Skip to content

Commit

Permalink
Adding a Bloch Sphere Scene selector, see #54
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Jan 2, 2025
1 parent c807646 commit 2efc269
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
9 changes: 9 additions & 0 deletions js/bloch-sphere/model/BlochSphereModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import EnumerationIO from '../../../../tandem/js/types/EnumerationIO.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import { BlochSphereScene } from './BlochSphereScene.js';
import ComplexBlochSphere from './ComplexBlochSphere.js';
import { StateDirection } from './StateDirection.js';

Expand All @@ -24,6 +25,8 @@ type QuantumMeasurementModelOptions = SelfOptions & PickRequired<PhetioObjectOpt

export default class BlochSphereModel implements TModel {

public readonly selectedSceneProperty: Property<BlochSphereScene>;

public readonly blochSphere: ComplexBlochSphere;

// Coefficients of the state equation
Expand All @@ -37,6 +40,12 @@ export default class BlochSphereModel implements TModel {

public constructor( providedOptions: QuantumMeasurementModelOptions ) {

this.selectedSceneProperty = new Property( BlochSphereScene.MEASUREMENT, {
tandem: providedOptions.tandem.createTandem( 'selectedSceneProperty' ),
phetioReadOnly: true,
phetioValueType: EnumerationIO( BlochSphereScene )
} );

this.blochSphere = new ComplexBlochSphere( {
tandem: providedOptions.tandem.createTandem( 'blochSphere' )
} );
Expand Down
25 changes: 25 additions & 0 deletions js/bloch-sphere/model/BlochSphereScene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024, University of Colorado Boulder

/**
* Contains the two possible selectable scenes on the Bloch Screen
*
* @author Agustín Vallejo
*/

import Enumeration from '../../../../phet-core/js/Enumeration.js';
import EnumerationValue from '../../../../phet-core/js/EnumerationValue.js';
import quantumMeasurement from '../../quantumMeasurement.js';

export class BlochSphereScene extends EnumerationValue {
public static readonly MEASUREMENT = new BlochSphereScene( 'Measurement', 'measurementScene' );
public static readonly PRECESSION = new BlochSphereScene( 'Precession', 'precessionScene' );

public static readonly enumeration = new Enumeration( BlochSphereScene );

public constructor( public readonly description: string,
public readonly tandemName: string ) {
super();
}
}

quantumMeasurement.register( 'BlochSphereScene', BlochSphereScene );
3 changes: 2 additions & 1 deletion js/bloch-sphere/view/BlochSpherePreparationArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export default class BlochSpherePreparationArea extends VBox {
model.blochSphere, {
tandem: providedOptions.tandem.createTandem( 'blochSphereNode' ),
expandBounds: false,
drawTitle: false
drawTitle: false,
scale: 0.9
} );

const options = optionize<BlochSpherePreparationAreaOptions, SelfOptions, VBoxOptions>()( {
Expand Down
32 changes: 30 additions & 2 deletions js/bloch-sphere/view/BlochSphereScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

import BlochSphereModel from 'model/BlochSphereModel.js';
import ScreenView from '../../../../joist/js/ScreenView.js';
import { Color, Image, Line } from '../../../../scenery/js/imports.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { Color, Image, Line, Text, VBox } from '../../../../scenery/js/imports.js';
import ComboBox, { ComboBoxItem } from '../../../../sun/js/ComboBox.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import blochSphereScreenMockup_png from '../../../images/blochSphereScreenMockup_png.js';
import QuantumMeasurementScreenView from '../../common/view/QuantumMeasurementScreenView.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import { BlochSphereScene } from '../model/BlochSphereScene.js';
import BlochSpherePreparationArea from './BlochSpherePreparationArea.js';

export default class BlochSphereScreenView extends QuantumMeasurementScreenView {
Expand All @@ -29,8 +32,10 @@ export default class BlochSphereScreenView extends QuantumMeasurementScreenView

const preparationArea = new BlochSpherePreparationArea( model, this, {
left: this.layoutBounds.left + 20,
top: this.layoutBounds.top + 20,
tandem: tandem.createTandem( 'preparationArea' )
} );
this.addChild( preparationArea );

// Add the vertical line that will sit between the preparation and measurement areas.
const dividingLineX = 350; // empirically determined
Expand All @@ -41,7 +46,30 @@ export default class BlochSphereScreenView extends QuantumMeasurementScreenView
} );
this.addChild( dividingLine );

this.addChild( preparationArea );
const comboBoxItems: ComboBoxItem<BlochSphereScene>[] = BlochSphereScene.enumeration.values.map( scene => {
return {
value: scene,
createNode: () => new Text( scene.description, { font: new PhetFont( 16 ) } )
};
} );

const sceneSelectionComboBox = new ComboBox( model.selectedSceneProperty, comboBoxItems, this, {
tandem: tandem.createTandem( 'sceneSelectionComboBox' )
} );

const measurementAreaTitleAndComboBox = new VBox( {
children: [
new Text( 'Spin Measurement', { font: new PhetFont( { size: 20, weight: 'bolder' } ) } ),
sceneSelectionComboBox
],
spacing: 10,
centerX: this.layoutBounds.centerX + 150,
top: this.layoutBounds.top + 20
} );


this.addChild( measurementAreaTitleAndComboBox );

}

public override reset(): void {
Expand Down

0 comments on commit 2efc269

Please sign in to comment.