Skip to content

Commit

Permalink
Moving coefficients to the model #54
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Dec 25, 2024
1 parent b08fb5b commit 71d9757
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
30 changes: 30 additions & 0 deletions js/bloch-sphere/model/BlochSphereModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Agustín Vallejo (PhET Interactive Simulations)
*/

import NumberProperty from '../../../../axon/js/NumberProperty.js';
import TModel from '../../../../joist/js/TModel.js';
import { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
Expand All @@ -22,11 +23,40 @@ export default class BlochSphereModel implements TModel {

public readonly blochSphere: ComplexBlochSphere;

// Coefficients of the state equation |psi> = upCoefficient |up> + downCoefficient * exp( i * |down>
public readonly upCoefficientProperty: NumberProperty;
public readonly downCoefficientProperty: NumberProperty;
public readonly phaseFactorProperty: NumberProperty;

public constructor( providedOptions: QuantumMeasurementModelOptions ) {

this.blochSphere = new ComplexBlochSphere( {
tandem: providedOptions.tandem.createTandem( 'blochSphere' )
} );

this.upCoefficientProperty = new NumberProperty( 1, {
tandem: providedOptions.tandem.createTandem( 'upCoefficientProperty' ),
phetioReadOnly: true
} );

this.downCoefficientProperty = new NumberProperty( 0, {
tandem: providedOptions.tandem.createTandem( 'downCoefficientProperty' ),
phetioReadOnly: true
} );

this.phaseFactorProperty = new NumberProperty( 0, {
tandem: providedOptions.tandem.createTandem( 'phaseFactorProperty' ),
phetioReadOnly: true
} );

this.blochSphere.polarAngleProperty.link( theta => {
this.upCoefficientProperty.value = Math.cos( theta / 2 );
this.downCoefficientProperty.value = Math.sin( theta / 2 );
} );

this.blochSphere.azimutalAngleProperty.link( phi => {
this.phaseFactorProperty.value = phi / Math.PI;
} );
}

/**
Expand Down
16 changes: 8 additions & 8 deletions js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ export default class BlochSphereNumericalEquationNode extends HBox {

const equationNode = new RichText( new DerivedStringProperty(
[
model.blochSphere.polarAngleProperty,
model.blochSphere.azimutalAngleProperty
model.upCoefficientProperty,
model.downCoefficientProperty,
model.phaseFactorProperty
],
( polarAngle: number, azimutalAngle: number ) => {
const upCoefficient = Utils.toFixed( Math.cos( polarAngle / 2 ), 2 );
const downCoefficient = Utils.toFixed( Math.abs( Math.sin( polarAngle / 2 ) ), 2 );
const downCoefficientSign = Math.sin( polarAngle / 2 ) < 0 ? '\u2212' : '+';
const azimutalCoefficient = Utils.toFixed( azimutalAngle / Math.PI, 2 );
( upCoefficient: number, downCoefficient: number, phaseFactor: number ) => {
const upCoefficientString = Utils.toFixed( upCoefficient, 2 );
const downCoefficientString = Utils.toFixed( downCoefficient, 2 );
const azimutalCoefficientString = Utils.toFixed( phaseFactor, 2 );

return `|${PSI}⟩ = ${upCoefficient}|${UP}${KET} ${downCoefficientSign} ${downCoefficient}e<sup>i${azimutalCoefficient}${PI}</sup>|${DOWN}${KET}`;
return `|${PSI}⟩ = ${upCoefficientString}|${UP}${KET} + ${downCoefficientString}e<sup>i${azimutalCoefficientString}${PI}</sup>|${DOWN}${KET}`;
}
), { font: EQUATION_FONT } );

Expand Down

0 comments on commit 71d9757

Please sign in to comment.