Skip to content

Commit

Permalink
Renaming upProbability for alphaSquared, more consistent with what's …
Browse files Browse the repository at this point in the history
…happening, see #53
  • Loading branch information
AgustinVallejo committed Nov 29, 2024
1 parent 7291d9c commit 6771ebf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions js/photons/view/PhotonSprites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class PhotonSprites extends Sprites {

let numberOfPhotonsDisplayed = 0;

// TODO REVIEW: Wouldn't it be better to filter first the active photons and then iterate over them? https://github.com/phetsims/quantum-measurement/issues/52
for ( let i = 0; i < this.photons.length; i++ ) {

// Convenience constants.
Expand Down
23 changes: 12 additions & 11 deletions js/spin/model/SpinModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export default class SpinModel implements TModel {
// Bloch Sphere that represents the current spin state
public readonly blochSphere: SimpleBlochSphere;

// The probability of the 'up' state. The 'down' probability will be 1 - this.
public readonly upProbabilityProperty: NumberProperty;
public readonly downProbabilityProperty: NumberProperty;
// Alpha and Beta squared values of the prepared state.
// Alpha^2 translates to the P(up) in a SG_Z
public readonly alphaSquaredProperty: NumberProperty;
public readonly betaSquaredProperty: NumberProperty;

// Spin property that is controlled by the buttons or sliders
public readonly derivedSpinStateProperty: TReadOnlyProperty<Vector2>;
Expand Down Expand Up @@ -107,13 +108,13 @@ export default class SpinModel implements TModel {
this.derivedSpinStateProperty, { tandem: providedOptions.tandem.createTandem( 'blochSphere' ) }
);

this.upProbabilityProperty = new NumberProperty( 1, {
tandem: providedOptions.tandem.createTandem( 'upProbabilityProperty' )
this.alphaSquaredProperty = new NumberProperty( 1, {
tandem: providedOptions.tandem.createTandem( 'alphaSquaredProperty' )
} );

// Create a Property with the inverse probability as the provided one and hook the two Properties up to one another.
// This is needed for the number sliders to work properly.
this.downProbabilityProperty = new NumberProperty( 1 - this.upProbabilityProperty.value );
this.betaSquaredProperty = new NumberProperty( 1 - this.alphaSquaredProperty.value );

const sternGerlachsTandem = providedOptions.tandem.createTandem( 'sternGerlachs' );
this.sternGerlachs = [
Expand Down Expand Up @@ -177,25 +178,25 @@ export default class SpinModel implements TModel {

let changeHandlingInProgress = false;

this.upProbabilityProperty.link( upProbability => {
this.alphaSquaredProperty.link( alphaSquared => {
if ( !changeHandlingInProgress ) {
changeHandlingInProgress = true;
this.downProbabilityProperty.value = 1 - upProbability;
this.betaSquaredProperty.value = 1 - alphaSquared;
changeHandlingInProgress = false;
}

if ( this.isCustomExperimentProperty.value ) {
// Set the spin direction
const polarAngle = Math.PI * ( 1 - upProbability );
const polarAngle = Math.PI * ( 1 - alphaSquared );
this.particleSourceModel.customSpinStateProperty.value = new Vector2( Math.sin( polarAngle ), Math.cos( polarAngle ) );
}

this.prepare();
} );
this.downProbabilityProperty.link( downProbability => {
this.betaSquaredProperty.link( betaSquared => {
if ( !changeHandlingInProgress ) {
changeHandlingInProgress = true;
this.upProbabilityProperty.value = 1 - downProbability;
this.alphaSquaredProperty.value = 1 - betaSquared;
changeHandlingInProgress = false;
}
} );
Expand Down
8 changes: 4 additions & 4 deletions js/spin/view/SpinStatePreparationArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ export default class SpinStatePreparationArea extends VBox {
children: [
new ProbabilityValueControl(
`|${QuantumMeasurementConstants.ALPHA}|<sup>2`,
model.upProbabilityProperty,
tandem.createTandem( 'upProbabilityControl' )
model.alphaSquaredProperty,
tandem.createTandem( 'alphaSquaredControl' )
),
new ProbabilityValueControl(
`|${QuantumMeasurementConstants.BETA}|<sup>2`,
model.downProbabilityProperty,
tandem.createTandem( 'downProbabilityControl' )
model.betaSquaredProperty,
tandem.createTandem( 'betaSquaredControl' )
)
]
} );
Expand Down

0 comments on commit 6771ebf

Please sign in to comment.