Skip to content

Commit

Permalink
Update the equation above the Bloch sphere in the measurement area to…
Browse files Browse the repository at this point in the history
… match the measured state when the measurement occurs, #80
  • Loading branch information
AgustinVallejo committed Jan 16, 2025
1 parent a9d2b8b commit 1da4fcf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 41 deletions.
32 changes: 2 additions & 30 deletions js/bloch-sphere/model/BlochSphereModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ class BlochSphereModel implements TModel {
public readonly singleMeasurementBlochSphere: ComplexBlochSphere;
public readonly multiMeasurementBlochSpheres: ComplexBlochSphere[] = [];

// 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;
public readonly phaseFactorProperty: NumberProperty;

// Selected State Direction
public selectedStateDirectionProperty: Property<StateDirection>;

Expand Down Expand Up @@ -95,21 +89,6 @@ class BlochSphereModel implements TModel {
} ) );
} );

this.upCoefficientProperty = new NumberProperty( 0, {
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.selectedStateDirectionProperty = new Property( StateDirection.Z_PLUS, {
tandem: providedOptions.tandem.createTandem( 'selectedStateDirectionProperty' ),
phetioValueType: EnumerationIO( StateDirection ),
Expand Down Expand Up @@ -173,25 +152,18 @@ class BlochSphereModel implements TModel {
// measurement that is being made.
this.timeToMeasurementProperty.link( () => this.resetCounts() );

// Update the coefficients, clear accumulated counts, and potentially change the selected preset state direction to
// Clear accumulated counts, and potentially change the selected preset state direction to
// CUSTOM when the user changes the angles of the Bloch Sphere.
Multilink.multilink(
[
this.preparationBlochSphere.polarAngleProperty,
this.preparationBlochSphere.azimuthalAngleProperty
],
( polarAngle, azimuthalAngle ) => {

// Update the coefficients of the state equation.
this.upCoefficientProperty.value = Math.cos( polarAngle / 2 );
this.downCoefficientProperty.value = Math.sin( polarAngle / 2 );
this.phaseFactorProperty.value = azimuthalAngle / Math.PI;

() => {
// Clear the accumulated counts.
this.resetCounts();

if ( !selectingStateDirection ) {

// Change the selected state to indicate that the user has moved away from the preset states.
this.selectedStateDirectionProperty.value = StateDirection.CUSTOM;
}
Expand Down
2 changes: 1 addition & 1 deletion js/bloch-sphere/view/BlochSphereMeasurementArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class BlochSphereMeasurementArea extends Node {

public constructor( model: BlochSphereModel, providedOptions: BlochSphereMeasurementAreaOptions ) {

const equationNode = new BlochSphereNumericalEquationNode( model, {
const equationNode = new BlochSphereNumericalEquationNode( model.singleMeasurementBlochSphere, {
visibleProperty: model.isSingleMeasurementModeProperty,
tandem: providedOptions.tandem.createTandem( 'equationNode' )
} );
Expand Down
19 changes: 10 additions & 9 deletions js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.
import WithRequired from '../../../../phet-core/js/types/WithRequired.js';
import MathSymbolFont from '../../../../scenery-phet/js/MathSymbolFont.js';
import { HBox, HBoxOptions, RichText } from '../../../../scenery/js/imports.js';
import AbstractBlochSphere from '../../common/model/AbstractBlochSphere.js';
import QuantumMeasurementConstants from '../../common/QuantumMeasurementConstants.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import BlochSphereModel from '../model/BlochSphereModel.js';

type SelfOptions = EmptySelfOptions;
type BlochSphereNumericalEquationNodeOptions = SelfOptions & WithRequired<HBoxOptions, 'tandem'>;
Expand All @@ -29,18 +29,19 @@ const KET = QuantumMeasurementConstants.KET;

export default class BlochSphereNumericalEquationNode extends HBox {

public constructor( model: BlochSphereModel, providedOptions?: BlochSphereNumericalEquationNodeOptions ) {
public constructor( blochSphere: AbstractBlochSphere, providedOptions?: BlochSphereNumericalEquationNodeOptions ) {

const equationNode = new RichText( new DerivedStringProperty(
[
model.upCoefficientProperty,
model.downCoefficientProperty,
model.phaseFactorProperty
blochSphere.polarAngleProperty,
blochSphere.azimuthalAngleProperty
],
( upCoefficient: number, downCoefficient: number, phaseFactor: number ) => {
const upCoefficientString = Utils.toFixed( upCoefficient, 2 );
const downCoefficientString = Utils.toFixed( downCoefficient, 2 );
const azimuthalCoefficientString = Utils.toFixed( phaseFactor, 2 );
( polarAngle, azimuthalAngle ) => {

// Update the coefficients of the state equation.
const upCoefficientString = Utils.toFixed( Math.cos( polarAngle / 2 ), 2 );
const downCoefficientString = Utils.toFixed( Math.sin( polarAngle / 2 ), 2 );
const azimuthalCoefficientString = Utils.toFixed( azimuthalAngle / Math.PI, 2 );

return `|${PSI}⟩ = ${upCoefficientString}|${UP}${KET} + ${downCoefficientString}e<sup>i${azimuthalCoefficientString}${PI}</sup>|${DOWN}${KET}`;
}
Expand Down
2 changes: 1 addition & 1 deletion js/bloch-sphere/view/BlochSpherePreparationArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class BlochSpherePreparationArea extends VBox {
new Text( 'State to Prepare', { font: new PhetFont( { size: 20, weight: 'bolder' } ) } ),
new BlochSphereSymbolicEquationNode(),
new Panel(
new BlochSphereNumericalEquationNode( model ), {
new BlochSphereNumericalEquationNode( model.preparationBlochSphere ), {
fill: '#aff',
cornerRadius: 5,
stroke: null,
Expand Down

0 comments on commit 1da4fcf

Please sign in to comment.