Skip to content

Commit

Permalink
Changing Basis for Axis, see #80
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Jan 16, 2025
1 parent 1da4fcf commit bad4cd4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
18 changes: 9 additions & 9 deletions js/bloch-sphere/model/BlochSphereModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import StringUnionIO from '../../../../tandem/js/types/StringUnionIO.js';
import QuantumMeasurementConstants from '../../common/QuantumMeasurementConstants.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import ComplexBlochSphere from './ComplexBlochSphere.js';
import { MeasurementBasis } from './MeasurementBasis.js';
import { MeasurementAxis } from './MeasurementAxis.js';
import { SpinMeasurementState, SpinMeasurementStateValues } from './SpinMeasurementState.js';
import { StateDirection } from './StateDirection.js';

Expand Down Expand Up @@ -54,7 +54,7 @@ class BlochSphereModel implements TModel {
public measurementTimeProperty: NumberProperty;

// Measurement basis
public measurementBasisProperty: Property<MeasurementBasis>;
public measurementAxisProperty: Property<MeasurementAxis>;

// If is single or multiple measurement mode
public isSingleMeasurementModeProperty: BooleanProperty;
Expand Down Expand Up @@ -109,9 +109,9 @@ class BlochSphereModel implements TModel {
tandem: providedOptions.tandem.createTandem( 'measurementTimeProperty' )
} );

this.measurementBasisProperty = new Property( MeasurementBasis.S_SUB_Z, {
tandem: providedOptions.tandem.createTandem( 'measurementBasisProperty' ),
phetioValueType: EnumerationIO( MeasurementBasis ),
this.measurementAxisProperty = new Property( MeasurementAxis.Z_PLUS, {
tandem: providedOptions.tandem.createTandem( 'measurementAxisProperty' ),
phetioValueType: EnumerationIO( MeasurementAxis ),
phetioFeatured: true
} );

Expand Down Expand Up @@ -203,7 +203,7 @@ class BlochSphereModel implements TModel {
} );
} );

this.measurementBasisProperty.link( () => {
this.measurementAxisProperty.link( () => {
this.resetCounts();
} );
}
Expand All @@ -220,15 +220,15 @@ class BlochSphereModel implements TModel {

if ( this.isSingleMeasurementModeProperty.value ) {
this.singleMeasurementBlochSphere.measure(
this.measurementBasisProperty.value,
this.measurementAxisProperty.value,
this.upMeasurementCountProperty,
this.downMeasurementCountProperty
);
}
else {
this.multiMeasurementBlochSpheres.forEach( blochSphere => {
blochSphere.measure(
this.measurementBasisProperty.value,
this.measurementAxisProperty.value,
this.upMeasurementCountProperty,
this.downMeasurementCountProperty
);
Expand Down Expand Up @@ -303,7 +303,7 @@ class BlochSphereModel implements TModel {
this.magneticFieldEnabledProperty.reset();
this.measurementStateProperty.reset();
this.magneticFieldStrengthProperty.reset();
this.measurementBasisProperty.reset();
this.measurementAxisProperty.reset();
this.isSingleMeasurementModeProperty.reset();
this.timeToMeasurementProperty.reset();
this.measurementTimeProperty.reset();
Expand Down
14 changes: 7 additions & 7 deletions js/bloch-sphere/model/ComplexBlochSphere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import AbstractBlochSphere, { AbstractBlochSphereOptions } from '../../common/model/AbstractBlochSphere.js';
import QuantumMeasurementConstants from '../../common/QuantumMeasurementConstants.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import { MeasurementBasis } from './MeasurementBasis.js';
import { MeasurementAxis } from './MeasurementAxis.js';
import { StateDirection } from './StateDirection.js';

type SelfOptions = {
Expand Down Expand Up @@ -63,12 +63,12 @@ export default class ComplexBlochSphere extends AbstractBlochSphere {

/**
* Given a measurement basis, measures along that axis and updates the counters accordingly.
* @param measurementBasis
* @param measurementAxis
* @param upCounterProperty
* @param downCounterProperty
*/
public measure( measurementBasis: MeasurementBasis, upCounterProperty: NumberProperty, downCounterProperty: NumberProperty ): void {
const measurementVector = StateDirection.directionToVector( measurementBasis );
public measure( measurementAxis: MeasurementAxis, upCounterProperty: NumberProperty, downCounterProperty: NumberProperty ): void {
const measurementVector = StateDirection.directionToVector( measurementAxis );
const stateVector = StateDirection.anglesToVector(
this.polarAngleProperty.value,
this.azimuthalAngleProperty.value
Expand All @@ -80,13 +80,13 @@ export default class ComplexBlochSphere extends AbstractBlochSphere {
if ( isUp ) {
upCounterProperty.value++;
this.setDirection(
measurementBasis.polarAngle,
measurementBasis.azimuthalAngle
measurementAxis.polarAngle,
measurementAxis.azimuthalAngle
);
}
else {
downCounterProperty.value++;
const oppositeDirection = measurementBasis.oppositeDirection;
const oppositeDirection = measurementAxis.oppositeDirection;
this.setDirection(
oppositeDirection.polarAngle,
oppositeDirection.azimuthalAngle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import quantumMeasurement from '../../quantumMeasurement.js';
import QuantumMeasurementStrings from '../../QuantumMeasurementStrings.js';
import { StateDirection } from './StateDirection.js';

export class MeasurementBasis extends EnumerationValue {
public static readonly S_SUB_X = new MeasurementBasis(
export class MeasurementAxis extends EnumerationValue {
public static readonly X_PLUS = new MeasurementAxis(
QuantumMeasurementStrings.SSubXStringProperty, Math.PI / 2, 0, StateDirection.X_MINUS, 'SSubX'
);
public static readonly S_SUB_Y = new MeasurementBasis(
public static readonly Y_PLUS = new MeasurementAxis(
QuantumMeasurementStrings.SSubYStringProperty, Math.PI / 2, Math.PI / 2, StateDirection.Y_MINUS, 'SSubY'
);
public static readonly S_SUB_Z = new MeasurementBasis(
public static readonly Z_PLUS = new MeasurementAxis(
QuantumMeasurementStrings.SSubZStringProperty, 0, 0, StateDirection.Z_MINUS, 'SSubZ'
);

public static readonly enumeration = new Enumeration( MeasurementBasis );
public static readonly enumeration = new Enumeration( MeasurementAxis );

public constructor( public readonly label: TReadOnlyProperty<string>,
public readonly polarAngle: number,
Expand All @@ -35,4 +35,4 @@ export class MeasurementBasis extends EnumerationValue {
}
}

quantumMeasurement.register( 'MeasurementBasis', MeasurementBasis );
quantumMeasurement.register( 'MeasurementAxis', MeasurementAxis );
4 changes: 2 additions & 2 deletions js/bloch-sphere/model/StateDirection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Vector3 from '../../../../dot/js/Vector3.js';
import Enumeration from '../../../../phet-core/js/Enumeration.js';
import EnumerationValue from '../../../../phet-core/js/EnumerationValue.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import { MeasurementBasis } from './MeasurementBasis.js';
import { MeasurementAxis } from './MeasurementAxis.js';

export class StateDirection extends EnumerationValue {
public static readonly Z_PLUS = new StateDirection( '+Z', 0, 0, 'ZPlus' );
Expand All @@ -30,7 +30,7 @@ export class StateDirection extends EnumerationValue {
super();
}

public static directionToVector( direction: StateDirection | MeasurementBasis ): Vector3 {
public static directionToVector( direction: StateDirection | MeasurementAxis ): Vector3 {
return new Vector3( Math.sin( direction.polarAngle ) * Math.cos( direction.azimuthalAngle ),
Math.sin( direction.polarAngle ) * Math.sin( direction.azimuthalAngle ),
Math.cos( direction.polarAngle ) );
Expand Down
16 changes: 8 additions & 8 deletions js/bloch-sphere/view/BlochSphereMeasurementArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import QuantumMeasurementHistogram from '../../common/view/QuantumMeasurementHis
import quantumMeasurement from '../../quantumMeasurement.js';
import QuantumMeasurementStrings from '../../QuantumMeasurementStrings.js';
import BlochSphereModel from '../model/BlochSphereModel.js';
import { MeasurementBasis } from '../model/MeasurementBasis.js';
import { MeasurementAxis } from '../model/MeasurementAxis.js';
import BlochSphereNumericalEquationNode from './BlochSphereNumericalEquationNode.js';
import MagneticFieldControl from './MagneticFieldControl.js';
import MeasurementTimerControl from './MeasurementTimerControl.js';
Expand Down Expand Up @@ -86,12 +86,12 @@ export default class BlochSphereMeasurementArea extends Node {
multipleMeasurementBlochSpheresNode.top = 70;

const spinUpLabelStringProperty = new DerivedStringProperty(
[ model.measurementBasisProperty ],
measurementBasis => measurementBasis.label.value + QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER
[ model.measurementAxisProperty ],
measurementAxis => measurementAxis.label.value + QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER
);
const spinDownLabelStringProperty = new DerivedStringProperty(
[ model.measurementBasisProperty ],
measurementBasis => measurementBasis.label.value + QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER
[ model.measurementAxisProperty ],
measurementAxis => measurementAxis.label.value + QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER
);

const measurementResultHistogram = new QuantumMeasurementHistogram(
Expand Down Expand Up @@ -126,7 +126,7 @@ export default class BlochSphereMeasurementArea extends Node {
// Create and add the radio buttons that select the chart type view in the nuclideChartAccordionBox.
const basisRadioButtonGroupTandem = providedOptions.tandem.createTandem( 'basisRadioButtonGroup' );

const basisRadioGroupItems = MeasurementBasis.enumeration.values.map( basis => {
const basisRadioGroupItems = MeasurementAxis.enumeration.values.map( basis => {
return {
value: basis,
createNode: () => new RichText(
Expand All @@ -136,8 +136,8 @@ export default class BlochSphereMeasurementArea extends Node {
};
} );

const basisRadioButtonGroup = new RectangularRadioButtonGroup<MeasurementBasis>(
model.measurementBasisProperty,
const basisRadioButtonGroup = new RectangularRadioButtonGroup<MeasurementAxis>(
model.measurementAxisProperty,
basisRadioGroupItems,
{
orientation: 'horizontal',
Expand Down

0 comments on commit bad4cd4

Please sign in to comment.