Skip to content

Commit

Permalink
Minor improvements to bloch sphere, see #54
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Jan 2, 2025
1 parent e3d2853 commit bc6e5ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
44 changes: 22 additions & 22 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 Multilink from '../../../../axon/js/Multilink.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import Property from '../../../../axon/js/Property.js';
import TModel from '../../../../joist/js/TModel.js';
Expand All @@ -27,9 +28,9 @@ export default class BlochSphereModel implements TModel {

public readonly selectedSceneProperty: Property<BlochSphereScene>;

public readonly blochSphere: ComplexBlochSphere;
public readonly preparationBlochSphere: ComplexBlochSphere;

// Coefficients of the state equation
// Coefficients of the state equation. They are derived from the Bloch Sphere representation on the multilink below.
// |psi> = upCoefficient |up> + downCoefficient * exp( i * phase * PI ) |down>
public readonly upCoefficientProperty: NumberProperty;
public readonly downCoefficientProperty: NumberProperty;
Expand All @@ -46,8 +47,8 @@ export default class BlochSphereModel implements TModel {
phetioValueType: EnumerationIO( BlochSphereScene )
} );

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

this.upCoefficientProperty = new NumberProperty( 1, {
Expand Down Expand Up @@ -75,28 +76,27 @@ export default class BlochSphereModel implements TModel {
this.selectedStateDirectionProperty.link( stateDirection => {
if ( stateDirection !== StateDirection.CUSTOM ) {
selectingStateDirection = true;
this.blochSphere.polarAngleProperty.value = stateDirection.polarAngle;
this.blochSphere.azimuthalAngleProperty.value = stateDirection.azimuthalAngle;
this.preparationBlochSphere.polarAngleProperty.value = stateDirection.polarAngle;
this.preparationBlochSphere.azimuthalAngleProperty.value = stateDirection.azimuthalAngle;
selectingStateDirection = false;
}
} );

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

if ( !selectingStateDirection ) {
this.selectedStateDirectionProperty.value = StateDirection.CUSTOM;
}
} );

this.blochSphere.azimuthalAngleProperty.link( phi => {
this.phaseFactorProperty.value = phi / Math.PI;

if ( !selectingStateDirection ) {
this.selectedStateDirectionProperty.value = StateDirection.CUSTOM;
Multilink.multilink(
[
this.preparationBlochSphere.polarAngleProperty,
this.preparationBlochSphere.azimuthalAngleProperty
],
( polarAngle, azimuthalAngle ) => {
this.upCoefficientProperty.value = Math.cos( polarAngle / 2 );
this.downCoefficientProperty.value = Math.sin( polarAngle / 2 );
this.phaseFactorProperty.value = azimuthalAngle / Math.PI;

if ( !selectingStateDirection ) {
this.selectedStateDirectionProperty.value = StateDirection.CUSTOM;
}
}
} );
);
}

/**
Expand All @@ -111,7 +111,7 @@ export default class BlochSphereModel implements TModel {
* @param dt - time step, in seconds
*/
public step( dt: number ): void {
this.blochSphere.step( dt );
this.preparationBlochSphere.step( dt );
}
}

Expand Down
6 changes: 3 additions & 3 deletions js/bloch-sphere/view/BlochSpherePreparationArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export default class BlochSpherePreparationArea extends VBox {

public constructor( model: BlochSphereModel, parentNode: Node, providedOptions: BlochSpherePreparationAreaOptions ) {

const polarSlider = new Slider( model.blochSphere.polarAngleProperty, model.blochSphere.polarAngleProperty.range, {
const polarSlider = new Slider( model.preparationBlochSphere.polarAngleProperty, model.preparationBlochSphere.polarAngleProperty.range, {
center: new Vector2( 100, 200 ),
tandem: providedOptions.tandem.createTandem( 'polarSlider' ),
thumbFill: '#444',
trackSize: new Dimension2( 150, 0.5 ),
majorTickLength: 10
} );
const azimuthSlider = new Slider( model.blochSphere.azimuthalAngleProperty, model.blochSphere.azimuthalAngleProperty.range, {
const azimuthSlider = new Slider( model.preparationBlochSphere.azimuthalAngleProperty, model.preparationBlochSphere.azimuthalAngleProperty.range, {
center: new Vector2( 100, 100 ),
tandem: providedOptions.tandem.createTandem( 'azimuthSlider' ),
thumbFill: '#444',
Expand Down Expand Up @@ -80,7 +80,7 @@ export default class BlochSpherePreparationArea extends VBox {
} );

const blochSphereNode = new BlochSphereNode(
model.blochSphere, {
model.preparationBlochSphere, {
tandem: providedOptions.tandem.createTandem( 'blochSphereNode' ),
expandBounds: false,
drawTitle: false,
Expand Down

0 comments on commit bc6e5ea

Please sign in to comment.