Skip to content

Commit

Permalink
improve behavior of timed measurements, see #54
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jan 9, 2025
1 parent add7787 commit 3ad845f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
57 changes: 39 additions & 18 deletions js/bloch-sphere/model/BlochSphereModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* measurements, equations and rotation under magnetic field.
*
* @author Agustín Vallejo (PhET Interactive Simulations)
* @author John Blanco (PhET Interactive Simulations)
*/

import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
Expand All @@ -31,7 +32,7 @@ type QuantumMeasurementModelOptions = SelfOptions & PickRequired<PhetioObjectOpt
// constants
const MAX_OBSERVATION_TIME = 2 * Math.PI / QuantumMeasurementConstants.MAX_PRECESSION_RATE;

export default class BlochSphereModel implements TModel {
class BlochSphereModel implements TModel {

public readonly showMagneticFieldProperty: BooleanProperty;

Expand All @@ -52,10 +53,10 @@ export default class BlochSphereModel implements TModel {
// Strength of the magnetic field
public magneticFieldStrengthProperty: NumberProperty;

// Time to measurement
// The amount of time to wait before making a measurement when the magnetic field is present.
public timeToMeasurementProperty: NumberProperty;

// Current time
// Current measurement time.
public measurementTimeProperty: NumberProperty;

// Measurement basis
Expand Down Expand Up @@ -222,20 +223,31 @@ export default class BlochSphereModel implements TModel {
* Make whatever observation ths mode is currently set up to make.
*/
private observe(): void {
if ( this.measurementStateProperty.value === 'prepared' ) {

if ( this.isSingleMeasurementModeProperty.value ) {
this.singleMeasurementBlochSphere.measure( this.measurementBasisProperty.value, this.upMeasurementCountProperty, this.downMeasurementCountProperty );
}
else {
this.multiMeasurementBlochSpheres.forEach( blochSphere => {
blochSphere.measure( this.measurementBasisProperty.value, this.upMeasurementCountProperty, this.downMeasurementCountProperty );
} );
}
assert && assert(
this.measurementStateProperty.value === 'prepared' || this.measurementStateProperty.value === 'timingObservation',
'The model is not in state where a new observation can be made.'
);

// Update the measurement state.
this.measurementStateProperty.value = 'observed';
if ( this.isSingleMeasurementModeProperty.value ) {
this.singleMeasurementBlochSphere.measure(
this.measurementBasisProperty.value,
this.upMeasurementCountProperty,
this.downMeasurementCountProperty
);
}
else {
this.multiMeasurementBlochSpheres.forEach( blochSphere => {
blochSphere.measure(
this.measurementBasisProperty.value,
this.upMeasurementCountProperty,
this.downMeasurementCountProperty
);
} );
}

// Update the measurement state.
this.measurementStateProperty.value = 'observed';
}

/**
Expand All @@ -245,7 +257,10 @@ export default class BlochSphereModel implements TModel {
*/
public initiateObservation(): void {

this.reprepare();
assert && assert(
this.measurementStateProperty.value === 'prepared',
'The model should be prepared for measurement prior to calling this method.'
);

if ( this.showMagneticFieldProperty.value ) {

Expand All @@ -264,7 +279,6 @@ export default class BlochSphereModel implements TModel {
* Reprepare the model for a new observation.
*/
public reprepare(): void {
this.measurementStateProperty.value = 'prepared';

// Copy the settings from the preparation bloch sphere
this.singleMeasurementBlochSphere.setDirection(
Expand All @@ -278,6 +292,9 @@ export default class BlochSphereModel implements TModel {
this.preparationBlochSphere.azimuthalAngleProperty.value
);
} );

this.measurementTimeProperty.value = 0;
this.measurementStateProperty.value = 'prepared';
}

/**
Expand All @@ -299,6 +316,7 @@ export default class BlochSphereModel implements TModel {
this.magneticFieldStrengthProperty.reset();
this.measurementBasisProperty.reset();
this.isSingleMeasurementModeProperty.reset();
this.timeToMeasurementProperty.reset();
this.measurementTimeProperty.reset();
}

Expand All @@ -315,11 +333,14 @@ export default class BlochSphereModel implements TModel {
if ( this.measurementStateProperty.value === 'timingObservation' ) {
this.measurementTimeProperty.value = this.measurementTimeProperty.value + dt;
if ( this.measurementTimeProperty.value > this.timeToMeasurementProperty.value ) {
this.reprepare();

// The time when the observation should be made has been reached. Make the observation.
this.observe();
}
}
}
}

quantumMeasurement.register( 'BlochSphereModel', BlochSphereModel );
quantumMeasurement.register( 'BlochSphereModel', BlochSphereModel );

export default BlochSphereModel;
2 changes: 2 additions & 0 deletions js/bloch-sphere/view/MeasurementTimerControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export default class MeasurementTimerControl extends Node {
lineWidth: 2
} );

// TODO: Can the measurement symbol be a common code item? See https://github.com/phetsims/quantum-measurement/issues/54.

const measurementSymbol = new Node( {
scale: 0.8,
children: [
Expand Down

0 comments on commit 3ad845f

Please sign in to comment.