phetsims / tandem

Simulation-side code for PhET-iO
MIT License
0 stars 5 forks source link

ReferenceIO.toStateObject should assert that the object is instrumented #312

Open zepumph opened 1 month ago

zepumph commented 1 month ago

Over in https://github.com/phetsims/density-buoyancy-common/issues/275, @samreid and I were surprised that there wasn't an assertion preventing sim.optionalTandem as the value of a ReferenceIO serialization. Let's add an assertion.

zepumph commented 1 month ago

Yay.

samreid commented 1 month ago

There is trouble in CCK in studio that requires investigation. A Vertex points to an uninstrumented something.

samreid commented 1 month ago

This error is being triggered for archetypes. The PhetioGroups are defined like so, in Circuit.ts

    this.wireGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => {
      return new Wire( startVertex, endVertex, this.wireResistivityProperty, tandem );
    }, () => createVertices( WIRE_LENGTH ), {
      groupElementStartingIndex: GROUP_STARTING_INDEX,
      phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ),
      tandem: tandem.createTandem( 'wireGroup' )
    } );

createVertices creates uninstrumented vertices. However, during startup, archetypes are broadcast and the first fail is for 'circuitConstructionKitDc.introScreen.model.circuit.wireGroup.archetype'. Should the Vertex instances for a CircuitElement archetype be instrumented?

zepumph commented 3 weeks ago

I think that makes sense generally. It is basically saying that all circuit elements can depend on an instrumented start/end vertex. What do you think?

zepumph commented 3 weeks ago

Perhaps this is our first instrumented dependency injection for archetypes. Happy to discuss more in person if that is best.

samreid commented 3 weeks ago

I made some progress in this patch:

```diff Subject: [PATCH] Use labels like radius, width & depth, etc., see https://github.com/phetsims/density-buoyancy-common/issues/348 --- Index: js/model/LightBulb.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/model/LightBulb.ts b/js/model/LightBulb.ts --- a/js/model/LightBulb.ts (revision 878aa776dd94df8318969b20e378776c976a88c1) +++ b/js/model/LightBulb.ts (date 1724119571706) @@ -86,8 +86,8 @@ const points = LightBulb.createSamplePoints( position ); // start vertex is at the bottom - const startVertex = icon ? new Vertex( points[ 0 ], circuit.selectionProperty ) : circuit.vertexGroup.createNextElement( points[ 0 ] ); - const endVertex = icon ? new Vertex( points[ 1 ], circuit.selectionProperty ) : circuit.vertexGroup.createNextElement( points[ 1 ] ); + const startVertex = icon ? new Vertex( points[ 0 ], circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ) : circuit.vertexGroup.createNextElement( points[ 0 ] ); + const endVertex = icon ? new Vertex( points[ 1 ], circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ) : circuit.vertexGroup.createNextElement( points[ 1 ] ); return { startVertex: startVertex, endVertex: endVertex }; } Index: js/view/ViewRadioButtonGroup.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/view/ViewRadioButtonGroup.ts b/js/view/ViewRadioButtonGroup.ts --- a/js/view/ViewRadioButtonGroup.ts (revision 878aa776dd94df8318969b20e378776c976a88c1) +++ b/js/view/ViewRadioButtonGroup.ts (date 1724119634683) @@ -60,8 +60,8 @@ }, providedOptions ); // Create a battery which can be used in the views - const startVertex = new Vertex( new Vector2( BATTERY_LENGTH / 2, 0 ), new Property( null ) ); - const endVertex = new Vertex( new Vector2( -BATTERY_LENGTH / 2, 0 ), new Property( null ) ); + const startVertex = new Vertex( new Vector2( BATTERY_LENGTH / 2, 0 ), new Property( null ), { tandem: Tandem.OPT_OUT } ); + const endVertex = new Vertex( new Vector2( -BATTERY_LENGTH / 2, 0 ), new Property( null ), { tandem: Tandem.OPT_OUT } ); const battery = new Battery( endVertex, startVertex, new NumberProperty( 0 ), 'normal', Tandem.OPT_OUT, { initialOrientation: 'left', numberOfDecimalPlaces: Battery.VOLTAGE_DECIMAL_PLACES Index: js/view/CircuitElementToolFactory.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/view/CircuitElementToolFactory.ts b/js/view/CircuitElementToolFactory.ts --- a/js/view/CircuitElementToolFactory.ts (revision 878aa776dd94df8318969b20e378776c976a88c1) +++ b/js/view/CircuitElementToolFactory.ts (date 1724119525572) @@ -218,7 +218,7 @@ */ public createRightBatteryToolNode( tandem: Tandem, count = 10 ): CircuitElementToolNode { const batteryModel = new Battery( - new Vertex( Vector2.ZERO, this.circuit.selectionProperty ), new Vertex( new Vector2( CCKCConstants.BATTERY_LENGTH, 0 ), this.circuit.selectionProperty ), + new Vertex( Vector2.ZERO, this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), new Vertex( new Vector2( CCKCConstants.BATTERY_LENGTH, 0 ), this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), new NumberProperty( 0 ), 'normal', Tandem.OPT_OUT ); return this.createCircuitElementToolNode( batteryStringProperty, count, @@ -237,8 +237,8 @@ */ public createACVoltageToolNode( tandem: Tandem, count = 10 ): CircuitElementToolNode { const acSource = new ACVoltage( - new Vertex( Vector2.ZERO, this.circuit.selectionProperty ), - new Vertex( new Vector2( AC_VOLTAGE_LENGTH, 0 ), this.circuit.selectionProperty ), + new Vertex( Vector2.ZERO, this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), + new Vertex( new Vector2( AC_VOLTAGE_LENGTH, 0 ), this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), new NumberProperty( 0 ), Tandem.OPT_OUT ); @@ -298,8 +298,8 @@ // Create the icon model without using the PhetioGroup, so it will not be PhET-iO instrumented. const resistorModel = new Resistor( - new Vertex( Vector2.ZERO, this.circuit.selectionProperty ), - new Vertex( new Vector2( resistorType.length, 0 ), this.circuit.selectionProperty ), + new Vertex( Vector2.ZERO, this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), + new Vertex( new Vector2( resistorType.length, 0 ), this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), resistorType, Tandem.OPT_OUT ); @@ -321,8 +321,8 @@ public createFuseToolNode( tandem: Tandem ): CircuitElementToolNode { const fuseModel = new Fuse( - new Vertex( Vector2.ZERO, this.circuit.selectionProperty ), - new Vertex( new Vector2( CCKCConstants.RESISTOR_LENGTH, 0 ), this.circuit.selectionProperty ), + new Vertex( Vector2.ZERO, this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), + new Vertex( new Vector2( CCKCConstants.RESISTOR_LENGTH, 0 ), this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), Tandem.OPT_OUT ); return this.createCircuitElementToolNode( fuseStringProperty, 10, @@ -343,8 +343,8 @@ */ public createCapacitorToolNode( tandem: Tandem, count = 10 ): CircuitElementToolNode { const capacitor = new Capacitor( - new Vertex( Vector2.ZERO, this.circuit.selectionProperty ), - new Vertex( new Vector2( CCKCConstants.CAPACITOR_LENGTH, 0 ), this.circuit.selectionProperty ), + new Vertex( Vector2.ZERO, this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), + new Vertex( new Vector2( CCKCConstants.CAPACITOR_LENGTH, 0 ), this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), Tandem.OPT_OUT ); return this.createCircuitElementToolNode( capacitorStringProperty, count, @@ -359,8 +359,8 @@ public createInductorToolNode( tandem: Tandem ): CircuitElementToolNode { const inductorModel = new Inductor( - new Vertex( Vector2.ZERO, this.circuit.selectionProperty ), - new Vertex( new Vector2( CCKCConstants.INDUCTOR_LENGTH, 0 ), this.circuit.selectionProperty ), + new Vertex( Vector2.ZERO, this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), + new Vertex( new Vector2( CCKCConstants.INDUCTOR_LENGTH, 0 ), this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), Tandem.OPT_OUT ); const count = CCKCQueryParameters.moreInductors ? 10 : 1; @@ -381,8 +381,8 @@ return this.createCircuitElementToolNode( switchStringProperty, 5, ( tandem, viewTypeProperty ) => new SwitchNode( null, null, new Switch( - new Vertex( Vector2.ZERO, this.circuit.selectionProperty ), - new Vertex( new Vector2( SWITCH_LENGTH, 0 ), this.circuit.selectionProperty ), + new Vertex( Vector2.ZERO, this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), + new Vertex( new Vector2( SWITCH_LENGTH, 0 ), this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), Tandem.OPT_OUT, null ), viewTypeProperty, tandem.createTandem( 'switchIcon' ), { @@ -485,8 +485,8 @@ return this.createCircuitElementToolNode( batteryStringProperty, 4, ( tandem, viewTypeProperty ) => new BatteryNode( null, null, new Battery( - new Vertex( Vector2.ZERO, this.circuit.selectionProperty ), - new Vertex( new Vector2( CCKCConstants.BATTERY_LENGTH, 0 ), this.circuit.selectionProperty ), + new Vertex( Vector2.ZERO, this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), + new Vertex( new Vector2( CCKCConstants.BATTERY_LENGTH, 0 ), this.circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), new NumberProperty( 0 ), 'high-voltage', Tandem.OPT_OUT, { Index: js/model/Circuit.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/model/Circuit.ts b/js/model/Circuit.ts --- a/js/model/Circuit.ts (revision 878aa776dd94df8318969b20e378776c976a88c1) +++ b/js/model/Circuit.ts (date 1724119270720) @@ -353,14 +353,16 @@ // Create vertices for the API validated/baseline circuit elements. These are not present in the vertexGroup and // hence not transmitted in the state. - const createVertices: ( l: number ) => [ Vertex, Vertex ] = ( length: number ) => { + const createVertices: ( l: number, tandem: Tandem ) => [ Vertex, Vertex ] = ( length: number, tandem: Tandem ) => { const startPosition = new Vector2( -1000, 0 ); - return [ new Vertex( startPosition, this.selectionProperty ), new Vertex( startPosition.plusXY( length, 0 ), this.selectionProperty ) ]; + return [ + new Vertex( startPosition, this.selectionProperty, { tandem: tandem.createTandem( 'startVertex' ) } ), + new Vertex( startPosition.plusXY( length, 0 ), this.selectionProperty, { tandem: tandem.createTandem( 'endVertex' ) } ) ]; }; this.wireGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => { return new Wire( startVertex, endVertex, this.wireResistivityProperty, tandem ); - }, () => createVertices( WIRE_LENGTH ), { + }, () => createVertices( WIRE_LENGTH, tandem.createTandem( 'wireGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'wireGroup' ) @@ -369,7 +371,7 @@ this.batteryGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => { return new Battery( startVertex, endVertex, this.sourceResistanceProperty, 'normal', tandem ); - }, () => createVertices( BATTERY_LENGTH ), { + }, () => createVertices( BATTERY_LENGTH, tandem.createTandem( 'batteryGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'batteryGroup' ) @@ -382,7 +384,7 @@ voltage: 1000, numberOfDecimalPlaces: Battery.HIGH_VOLTAGE_DECIMAL_PLACES } ); - }, () => createVertices( BATTERY_LENGTH ), { + }, () => createVertices( BATTERY_LENGTH, tandem.createTandem( 'extremeBatteryGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'extremeBatteryGroup' ), @@ -391,7 +393,7 @@ this.acVoltageGroup = this.includeACElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => { return new ACVoltage( startVertex, endVertex, this.sourceResistanceProperty, tandem ); - }, () => createVertices( CCKCConstants.AC_VOLTAGE_LENGTH ), { + }, () => createVertices( CCKCConstants.AC_VOLTAGE_LENGTH, tandem.createTandem( 'acVoltageGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'acVoltageGroup' ) @@ -400,7 +402,7 @@ this.resistorGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => new Resistor( startVertex, endVertex, ResistorType.RESISTOR, tandem ), - () => createVertices( ResistorType.RESISTOR.length ), { + () => createVertices( ResistorType.RESISTOR.length, tandem.createTandem( 'resistorGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( Resistor.ResistorIO ), tandem: tandem.createTandem( 'resistorGroup' ) @@ -409,7 +411,7 @@ this.extremeResistorGroup = includeExtremeElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => new Resistor( startVertex, endVertex, ResistorType.EXTREME_RESISTOR, tandem ), - () => createVertices( ResistorType.EXTREME_RESISTOR.length ), { + () => createVertices( ResistorType.EXTREME_RESISTOR.length, tandem.createTandem( 'extremeResistorGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( Resistor.ResistorIO ), tandem: tandem.createTandem( 'extremeResistorGroup' ) @@ -419,7 +421,7 @@ ( tandem, startVertex, endVertex, resistorType ) => new Resistor( startVertex, endVertex, resistorType, tandem ), () => { - return [ ...createVertices( ResistorType.RESISTOR.length ), ResistorType.COIN ]; + return [ ...createVertices( ResistorType.RESISTOR.length, tandem.createTandem( 'householdObjectGroup' ) ), ResistorType.COIN ]; }, { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( Resistor.ResistorIO ), @@ -428,7 +430,7 @@ this.fuseGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => new Fuse( startVertex, endVertex, tandem ), - () => createVertices( CCKCConstants.FUSE_LENGTH ), { + () => createVertices( CCKCConstants.FUSE_LENGTH, tandem.createTandem( 'fuseGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'fuseGroup' ) @@ -436,7 +438,7 @@ this.seriesAmmeterGroup = this.includeLabElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => new SeriesAmmeter( startVertex, endVertex, tandem ), - () => createVertices( CCKCConstants.SERIES_AMMETER_LENGTH ), { + () => createVertices( CCKCConstants.SERIES_AMMETER_LENGTH, tandem.createTandem( 'seriesAmmeterGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'seriesAmmeterGroup' ) @@ -448,7 +450,7 @@ this.viewTypeProperty, tandem, { isExtreme: true } ); - }, () => createVertices( 100 ), { + }, () => createVertices( 100, tandem.createTandem( 'extremeLightBulbGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'extremeLightBulbGroup' ) @@ -456,7 +458,7 @@ this.capacitorGroup = this.includeACElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => new Capacitor( startVertex, endVertex, tandem ), - () => createVertices( CCKCConstants.CAPACITOR_LENGTH ), { + () => createVertices( CCKCConstants.CAPACITOR_LENGTH, tandem.createTandem( 'capacitorGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'capacitorGroup' ) @@ -464,7 +466,7 @@ this.inductorGroup = this.includeACElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => new Inductor( startVertex, endVertex, tandem ), - () => createVertices( CCKCConstants.INDUCTOR_LENGTH ), { + () => createVertices( CCKCConstants.INDUCTOR_LENGTH, tandem.createTandem( 'inductorGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'inductorGroup' ) @@ -472,7 +474,7 @@ this.switchGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => new Switch( startVertex, endVertex, tandem, this ), - () => createVertices( CCKCConstants.SWITCH_LENGTH ), { + () => createVertices( CCKCConstants.SWITCH_LENGTH, tandem.createTandem( 'switchGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'switchGroup' ) @@ -480,7 +482,7 @@ this.lightBulbGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => { return new LightBulb( startVertex, endVertex, CCKCConstants.DEFAULT_RESISTANCE, this.viewTypeProperty, tandem ); - }, () => createVertices( 100 ), { + }, () => createVertices( 100, tandem.createTandem( 'lightBulbGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'lightBulbGroup' ) @@ -494,7 +496,7 @@ tandem: Tandem.OPT_OUT } } ); - }, () => createVertices( 100 ), { + }, () => createVertices( 100, tandem.createTandem( 'realLightBulbGroup' ) ), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'realLightBulbGroup' ) Index: js/model/Vertex.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/model/Vertex.ts b/js/model/Vertex.ts --- a/js/model/Vertex.ts (revision 878aa776dd94df8318969b20e378776c976a88c1) +++ b/js/model/Vertex.ts (date 1724119806345) @@ -15,12 +15,12 @@ import Vector2Property from '../../../dot/js/Vector2Property.js'; import optionize, { combineOptions } from '../../../phet-core/js/optionize.js'; import PhetioObject, { PhetioObjectOptions } from '../../../tandem/js/PhetioObject.js'; -import Tandem from '../../../tandem/js/Tandem.js'; import IOType from '../../../tandem/js/types/IOType.js'; import circuitConstructionKitCommon from '../circuitConstructionKitCommon.js'; import TProperty from '../../../axon/js/TProperty.js'; import CircuitElement from './CircuitElement.js'; import StringProperty from '../../../axon/js/StringProperty.js'; +import WithRequired from '../../../phet-core/js/types/WithRequired.js'; // Index counter for debugging let counter = 0; @@ -32,13 +32,13 @@ blackBoxInterface?: boolean; insideTrueBlackBox?: boolean; }; -type VertexOptions = SelfOptions & PhetioObjectOptions; +type VertexOptions = SelfOptions & WithRequired; export default class Vertex extends PhetioObject { // Index counter for hashing in CircuitNode. Also useful for debugging and can be shown with ?vertexDisplay=index public readonly index: number; - private readonly vertexTandem: Tandem; + // private readonly vertexTandem: Tandem; // position of the vertex public readonly positionProperty: Property; @@ -92,7 +92,7 @@ } ); public readonly selectionProperty: TProperty; - public constructor( position: Vector2, selectionProperty: TProperty, providedOptions?: VertexOptions ) { + public constructor( position: Vector2, selectionProperty: TProperty, providedOptions: VertexOptions ) { const options = optionize()( { draggable: true, // whether the vertex can be dragged, false for Black Box elements @@ -103,8 +103,9 @@ // Temporary vertices (for icons) should not be instrumented since they are more of an implementation detail // rather than a feature - tandem: Tandem.OPTIONAL, - phetioDynamicElement: true + // tandem: Tandem.OPTIONAL, + phetioDynamicElement: true, + phetioState: false }, providedOptions ); super( options ); @@ -113,7 +114,7 @@ this.selectionProperty = selectionProperty; - this.vertexTandem = options.tandem; + // this.vertexTandem = options.tandem; this.positionProperty = new Vector2Property( position, { tandem: options.tandem && options.tandem.createTandem( 'positionProperty' ), Index: js/view/SensorToolbox.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/view/SensorToolbox.ts b/js/view/SensorToolbox.ts --- a/js/view/SensorToolbox.ts (revision 878aa776dd94df8318969b20e378776c976a88c1) +++ b/js/view/SensorToolbox.ts (date 1724119597489) @@ -141,8 +141,8 @@ // Icon for the series ammeter const seriesAmmeterIcon = new SeriesAmmeter( - new Vertex( Vector2.ZERO, circuit.selectionProperty ), - new Vertex( new Vector2( CCKCConstants.SERIES_AMMETER_LENGTH, 0 ), circuit.selectionProperty ), + new Vertex( Vector2.ZERO, circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), + new Vertex( new Vector2( CCKCConstants.SERIES_AMMETER_LENGTH, 0 ), circuit.selectionProperty, { tandem: Tandem.OPT_OUT } ), Tandem.OPT_OUT ); const seriesAmmeterNodeIcon = new SeriesAmmeterNode( null, null, seriesAmmeterIcon, ```

Running in studio, I see this assertion error:

Assertion failed:  phetioElement not found: circuitConstructionKitDc.introScreen.model.circuit.wireGroup.startVertex

It's saying the archetype is not a dynamic element, since it is statically created, but then it is looking for the archetype for it, so I'm confused how to proceed (if I do understand the problem). Probably synchronous collaboration is the best way forward here.

samreid commented 2 weeks ago
```diff Subject: [PATCH] test --- Index: tandem/js/PhetioDynamicElementContainer.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tandem/js/PhetioDynamicElementContainer.ts b/tandem/js/PhetioDynamicElementContainer.ts --- a/tandem/js/PhetioDynamicElementContainer.ts (revision 05021a8bb062b2b926d5d95b9afcbfc23de120ba) +++ b/tandem/js/PhetioDynamicElementContainer.ts (date 1724358551881) @@ -69,7 +69,7 @@ return archetype; } -abstract class PhetioDynamicElementContainer extends PhetioObject { +abstract class PhetioDynamicElementContainer extends PhetioObject { private readonly _archetype: T | null; public readonly elementCreatedEmitter: TEmitter<[ T, string ]>; public readonly elementDisposedEmitter: TEmitter<[ T, string ]>; @@ -78,10 +78,10 @@ private readonly deferredDisposals: T[]; public readonly supportsDynamicState: boolean; // (phet-io internal) protected phetioDynamicElementName: string; - protected createElement: ( t: Tandem, ...args: P ) => T; + protected createElement: ( t: Tandem, ...args: DefaultArguments ) => T; // Arguments passed to the archetype when creating it. - protected defaultArguments: P | ( () => P ); + protected defaultArguments: DefaultArguments | ( () => DefaultArguments ); /** * @param createElement - function that creates a dynamic readonly element to be housed in @@ -90,7 +90,7 @@ * @param defaultArguments - arguments passed to createElement when creating the archetype * @param [providedOptions] - describe the Group itself */ - public constructor( createElement: ( t: Tandem, ...args: P ) => T, defaultArguments: P | ( () => P ), providedOptions?: PhetioDynamicElementContainerOptions ) { + public constructor( createElement: ( t: Tandem, ...args: DefaultArguments ) => T, defaultArguments: DefaultArguments | ( () => DefaultArguments ), providedOptions?: PhetioDynamicElementContainerOptions ) { const options = optionize()( { phetioState: false, // elements are included in state, but the container will exist in the downstream sim. @@ -246,8 +246,16 @@ * Archetypes are created to generate the baseline file, or to validate against an existing baseline file. They are * PhetioObjects and registered with the phetioEngine, but not send out via notifications from PhetioEngine.phetioElementAddedEmitter(), * because they are intended for internal usage only. Archetypes should not be created in production code. + * + * PhetioDynamicElementContainer calls this method internally to create and assign its own archetype, but this method + * can additionally be called with alternate archetypeTandem and/or createElementArgs to create alternate archetypes. + * This can be necessary in situations that require archetypes provided to other archetypes, or with other forms + * of dependency injection, such as in https://github.com/phetsims/tandem/issues/312 */ - private createArchetype(): T | null { + public createArchetype( + archetypeTandem = this.tandem.createTandem( DYNAMIC_ARCHETYPE_NAME ), + createElementArgs: ( DefaultArguments | ( () => DefaultArguments ) ) = this.defaultArguments + ): T | null { // Once the sim has started, any archetypes being created are likely done so because they are nested PhetioGroups. if ( _.hasIn( window, 'phet.joist.sim' ) && phet.joist.sim.isConstructionCompleteProperty.value ) { @@ -257,12 +265,12 @@ // When generating the baseline, output the schema for the archetype if ( Tandem.PHET_IO_ENABLED && phet.preloads.phetio.createArchetypes ) { - const defaultArgs = Array.isArray( this.defaultArguments ) ? this.defaultArguments : this.defaultArguments(); + const archetypeArgs = Array.isArray( createElementArgs ) ? createElementArgs : createElementArgs(); // The create function takes a tandem plus the default args - assert && assert( this.createElement.length === defaultArgs.length + 1, 'mismatched number of arguments' ); + assert && assert( this.createElement.length === archetypeArgs.length + 1, 'mismatched number of arguments' ); - const archetype = this.createElement( this.tandem.createTandem( DYNAMIC_ARCHETYPE_NAME ), ...defaultArgs ); + const archetype = this.createElement( archetypeTandem, ...archetypeArgs ); // Mark the archetype for inclusion in the baseline schema if ( this.isPhetioInstrumented() ) { @@ -281,7 +289,7 @@ * @param argsForCreateFunction * @param containerParameterType - null in PhET brand */ - public createDynamicElement( componentName: string, argsForCreateFunction: P, containerParameterType: IOType | null ): T { + public createDynamicElement( componentName: string, argsForCreateFunction: DefaultArguments, containerParameterType: IOType | null ): T { assert && assert( Array.isArray( argsForCreateFunction ), 'should be array' ); // create with default state and substructure, details will need to be set by setter methods. Index: tandem/js/types/ReferenceIO.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tandem/js/types/ReferenceIO.ts b/tandem/js/types/ReferenceIO.ts --- a/tandem/js/types/ReferenceIO.ts (revision 05021a8bb062b2b926d5d95b9afcbfc23de120ba) +++ b/tandem/js/types/ReferenceIO.ts (date 1724358256271) @@ -15,6 +15,7 @@ import StringIO from './StringIO.js'; import { PhetioID } from '../TandemConstants.js'; import IOTypeCache from '../IOTypeCache.js'; +import Tandem from '../Tandem.js'; // Cache each parameterized ReferenceIO so that it is only created once const cache = new IOTypeCache(); @@ -41,7 +42,7 @@ * directly to use this implementation. */ toStateObject( phetioObject ): ReferenceIOState { - + assert && Tandem.VALIDATION && assert( phetioObject.isPhetioInstrumented(), 'Cannot reference an uninstrumented object', phetioObject ); // NOTE: We cannot assert that phetioObject.phetioState === false here because sometimes ReferenceIO is used statically like // ReferenceIO( Vector2IO ).toStateObject( myVector ); return { Index: circuit-construction-kit-common/js/model/Circuit.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/circuit-construction-kit-common/js/model/Circuit.ts b/circuit-construction-kit-common/js/model/Circuit.ts --- a/circuit-construction-kit-common/js/model/Circuit.ts (revision b4a9c23c1be69e3f78604230e091a96f18ba73d0) +++ b/circuit-construction-kit-common/js/model/Circuit.ts (date 1724359105773) @@ -66,9 +66,6 @@ // of group elements from 0 -> 1, see https://github.com/phetsims/tandem/issues/226 const GROUP_STARTING_INDEX = 0; -const BATTERY_LENGTH = CCKCConstants.BATTERY_LENGTH; -const WIRE_LENGTH = CCKCConstants.WIRE_LENGTH; - // Determine what sense a circuit element should have to create an overall positive readout, given the specified current const getSenseForPositive = ( current: number ) => current < 0 ? CurrentSense.BACKWARD : current > 0 ? CurrentSense.FORWARD : @@ -298,6 +295,8 @@ phetioType: PhetioGroup.PhetioGroupIO( Vertex.VertexIO ), tandem: tandem.createTandem( 'vertexGroup' ) } ); + const archetypeStartVertex = this.vertexGroup.createArchetype( this.vertexGroup.tandem.createTandem( 'archetypeStartVertex' ), [ new Vector2( 0, 0 ) ] ); + const archetypeEndVertex = this.vertexGroup.createArchetype( this.vertexGroup.tandem.createTandem( 'archetypeEndVertex' ), [ new Vector2( 100, 0 ) ] ); this.vertexGroup.elementCreatedEmitter.addListener( vertex => { @@ -353,14 +352,13 @@ // Create vertices for the API validated/baseline circuit elements. These are not present in the vertexGroup and // hence not transmitted in the state. - const createVertices: ( l: number ) => [ Vertex, Vertex ] = ( length: number ) => { - const startPosition = new Vector2( -1000, 0 ); - return [ new Vertex( startPosition, this.selectionProperty ), new Vertex( startPosition.plusXY( length, 0 ), this.selectionProperty ) ]; + const createVertices = (): [ Vertex, Vertex ] => { + return [ archetypeStartVertex!, archetypeEndVertex! ]; }; this.wireGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => { return new Wire( startVertex, endVertex, this.wireResistivityProperty, tandem ); - }, () => createVertices( WIRE_LENGTH ), { + }, createVertices, { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'wireGroup' ) @@ -369,7 +367,7 @@ this.batteryGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => { return new Battery( startVertex, endVertex, this.sourceResistanceProperty, 'normal', tandem ); - }, () => createVertices( BATTERY_LENGTH ), { + }, () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'batteryGroup' ) @@ -382,7 +380,7 @@ voltage: 1000, numberOfDecimalPlaces: Battery.HIGH_VOLTAGE_DECIMAL_PLACES } ); - }, () => createVertices( BATTERY_LENGTH ), { + }, () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'extremeBatteryGroup' ), @@ -391,7 +389,7 @@ this.acVoltageGroup = this.includeACElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => { return new ACVoltage( startVertex, endVertex, this.sourceResistanceProperty, tandem ); - }, () => createVertices( CCKCConstants.AC_VOLTAGE_LENGTH ), { + }, () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'acVoltageGroup' ) @@ -400,7 +398,7 @@ this.resistorGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => new Resistor( startVertex, endVertex, ResistorType.RESISTOR, tandem ), - () => createVertices( ResistorType.RESISTOR.length ), { + () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( Resistor.ResistorIO ), tandem: tandem.createTandem( 'resistorGroup' ) @@ -409,7 +407,7 @@ this.extremeResistorGroup = includeExtremeElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => new Resistor( startVertex, endVertex, ResistorType.EXTREME_RESISTOR, tandem ), - () => createVertices( ResistorType.EXTREME_RESISTOR.length ), { + () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( Resistor.ResistorIO ), tandem: tandem.createTandem( 'extremeResistorGroup' ) @@ -419,7 +417,7 @@ ( tandem, startVertex, endVertex, resistorType ) => new Resistor( startVertex, endVertex, resistorType, tandem ), () => { - return [ ...createVertices( ResistorType.RESISTOR.length ), ResistorType.COIN ]; + return [ ...createVertices(), ResistorType.COIN ]; }, { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( Resistor.ResistorIO ), @@ -428,7 +426,7 @@ this.fuseGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => new Fuse( startVertex, endVertex, tandem ), - () => createVertices( CCKCConstants.FUSE_LENGTH ), { + () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'fuseGroup' ) @@ -436,7 +434,7 @@ this.seriesAmmeterGroup = this.includeLabElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => new SeriesAmmeter( startVertex, endVertex, tandem ), - () => createVertices( CCKCConstants.SERIES_AMMETER_LENGTH ), { + () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'seriesAmmeterGroup' ) @@ -448,7 +446,7 @@ this.viewTypeProperty, tandem, { isExtreme: true } ); - }, () => createVertices( 100 ), { + }, () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'extremeLightBulbGroup' ) @@ -456,7 +454,7 @@ this.capacitorGroup = this.includeACElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => new Capacitor( startVertex, endVertex, tandem ), - () => createVertices( CCKCConstants.CAPACITOR_LENGTH ), { + () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'capacitorGroup' ) @@ -464,7 +462,7 @@ this.inductorGroup = this.includeACElements ? new PhetioGroup( ( tandem, startVertex, endVertex ) => new Inductor( startVertex, endVertex, tandem ), - () => createVertices( CCKCConstants.INDUCTOR_LENGTH ), { + () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'inductorGroup' ) @@ -472,7 +470,7 @@ this.switchGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => new Switch( startVertex, endVertex, tandem, this ), - () => createVertices( CCKCConstants.SWITCH_LENGTH ), { + () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'switchGroup' ) @@ -480,7 +478,7 @@ this.lightBulbGroup = new PhetioGroup( ( tandem, startVertex, endVertex ) => { return new LightBulb( startVertex, endVertex, CCKCConstants.DEFAULT_RESISTANCE, this.viewTypeProperty, tandem ); - }, () => createVertices( 100 ), { + }, () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'lightBulbGroup' ) @@ -494,7 +492,7 @@ tandem: Tandem.OPT_OUT } } ); - }, () => createVertices( 100 ), { + }, () => createVertices(), { groupElementStartingIndex: GROUP_STARTING_INDEX, phetioType: PhetioGroup.PhetioGroupIO( CircuitElement.CircuitElementIO ), tandem: tandem.createTandem( 'realLightBulbGroup' )
zepumph commented 2 weeks ago

@samreid and I got to a commit point by reusing createArchetye() logic from PhetioDynamicElementContainer. This worked very well in all forms except what the phetioID of these "extra" archetypes should be. We settled on siblings of the vertextGroup.archetype and prefixed their names with "archetype". @samreid can you give a spot check to the above commits?

zepumph commented 2 weeks ago

Migration rules inbound

zepumph commented 2 weeks ago

Shoot dang. Migration for this one is actually pretty hard. We aren't good at support ignoring initialStateIncompatible with dynamic elements.

This is because we write a rule like "please ignore initialState for batteryGroup.archeteype", and that doesn't successfully bring back the state that was gracefully deleted for "barryerGroup.battery_0".

``` Subject: [PATCH] remove listeners redundant with MappedWrappedProperty, https://github.com/phetsims/density-buoyancy-common/issues/362 --- Index: phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts b/phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts --- a/phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts (revision d4b54c012b181c62cab9d44825d7177277d017ab) +++ b/phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts (date 1724448994875) @@ -7,6 +7,7 @@ import { MigrationProcessors } from '../../../../phet-io-wrappers/common/js/migration/MigrationEngine.js'; import { getCircuitConstructionKit1_4MigrationProcessors } from '../../circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.js'; import DeleteUninstrumentedPhetioElement from '../../../../phet-io-wrappers/common/js/migration/processors/DeleteUninstrumentedPhetioElement.js'; +import RemoveExpectedReportErrors from '../../../../phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.js'; window.phetio = window.phetio || {}; @@ -17,7 +18,26 @@ '1.4.0': [ ...getCircuitConstructionKit1_4MigrationProcessors( simName, [ 'labScreen' ] ), - new DeleteUninstrumentedPhetioElement( `${simName}.general.model.fallbackLocalesProperty` ) + new DeleteUninstrumentedPhetioElement( `${simName}.general.model.fallbackLocalesProperty` ), + new RemoveExpectedReportErrors( { + expectedReportErrors: { + initialStatesAreIncompatible: [ + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.batteryGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.wireGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.resistorGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.extremeBatteryGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.fuseGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.extremeResistorGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.householdObjectGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.realLightBulbGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.extremeLightBulbGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.lightBulbGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.seriesAmmeterGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.switchGroup.archetype' + ] + } + } ) + ] }; Index: phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts b/phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts --- a/phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts (revision f6c07c76bb697b985c82f9b02b7fa66588b158fe) +++ b/phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts (date 1724449941098) @@ -92,7 +92,7 @@ if ( expectedReportedPhetioIDs.includes( phetioID ) ) { // Removing from the report should be accompanied by restoring the state that was gracefully deleted when creating the report entry. If the deletion is intentional and important, then a delete processor should be used (not a report processor). - if ( report.gracefullyDeletedState.hasOwnProperty( phetioID ) ) { + if ( report.gracefullyDeletedState.hasOwnProperty( phetioID ) && !phetioID.includes( '.archetype' ) ) { migratingState[ phetioID ] = report.gracefullyDeletedState[ phetioID ]; } Index: phet-io-wrappers/common/js/migration/MigrationReport.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io-wrappers/common/js/migration/MigrationReport.ts b/phet-io-wrappers/common/js/migration/MigrationReport.ts --- a/phet-io-wrappers/common/js/migration/MigrationReport.ts (revision f6c07c76bb697b985c82f9b02b7fa66588b158fe) +++ b/phet-io-wrappers/common/js/migration/MigrationReport.ts (date 1724450078876) @@ -61,6 +61,7 @@ // see initialStateComparisonHandler. Please populate only with reportInitialStatesIncompatible(). public readonly initialStatesAreIncompatible: Array<{ phetioID: PhetioID; + archetypePhetioID: PhetioID; migratedInitialState?: PhetioElementState; newInitialState?: PhetioElementState; }> = []; Index: phet-io/js/PhetioStateEngine.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io/js/PhetioStateEngine.ts b/phet-io/js/PhetioStateEngine.ts --- a/phet-io/js/PhetioStateEngine.ts (revision f4b858bc2bf74815220c95505b52cf3d1855e92a) +++ b/phet-io/js/PhetioStateEngine.ts (date 1724449362582) @@ -306,6 +306,9 @@ const nextPass: string[] = []; currentPhetioIDs.forEach( phetioID => { + if ( phetioID.includes( '.archetype' ) ) { + debugger; + } try { let phetioObject = null; Index: phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts b/phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts --- a/phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts (revision d4b54c012b181c62cab9d44825d7177277d017ab) +++ b/phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts (date 1724450244185) @@ -12,6 +12,7 @@ import MigrationPhetioAPI from '../../../../phet-io-wrappers/common/js/migration/MigrationPhetioAPI.js'; import { PhetioState } from '../../../../tandem/js/TandemConstants.js'; import MigrationReport from '../../../../phet-io-wrappers/common/js/migration/MigrationReport.js'; +import RemoveExpectedReportErrors from '../../../../phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.js'; window.phetio = window.phetio || {}; @@ -111,7 +112,40 @@ ...reviseAmmeterStringPropertiesForScreen( simName, 'introScreen' ), ...reviseAmmeterStringPropertiesForScreen( simName, 'labScreen' ), - new DeleteUninstrumentedPhetioElement( `${simName}.general.model.fallbackLocalesProperty` ) + new DeleteUninstrumentedPhetioElement( `${simName}.general.model.fallbackLocalesProperty` ), + + new RemoveExpectedReportErrors( { + expectedReportErrors: { + initialStatesAreIncompatible: [ + // TODO: But this won't bring back the state for battery_0 + 'circuitConstructionKitDc.introScreen.model.circuit.batteryGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.wireGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.resistorGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.extremeBatteryGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.fuseGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.extremeResistorGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.householdObjectGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.realLightBulbGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.extremeLightBulbGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.lightBulbGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.seriesAmmeterGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.switchGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.batteryGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.wireGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.resistorGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.extremeBatteryGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.fuseGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.extremeResistorGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.householdObjectGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.realLightBulbGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.extremeLightBulbGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.lightBulbGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.seriesAmmeterGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.switchGroup.archetype' + ] + } + } ) + ] }; Index: phet-io-wrappers/common/js/migration/analyzeMigration.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io-wrappers/common/js/migration/analyzeMigration.ts b/phet-io-wrappers/common/js/migration/analyzeMigration.ts --- a/phet-io-wrappers/common/js/migration/analyzeMigration.ts (revision f6c07c76bb697b985c82f9b02b7fa66588b158fe) +++ b/phet-io-wrappers/common/js/migration/analyzeMigration.ts (date 1724450164086) @@ -35,7 +35,8 @@ phetio.PhetioIDUtils.MODEL_COMPONENT_NAME, phetio.PhetioIDUtils.STRINGS_COMPONENT_NAME ); -type InitialStateHandler = ( phetioID: PhetioID, migratedInitialState: PhetioElementState, +type InitialStateHandler = ( statePhetioID: PhetioID, + archetypePhetioID: PhetioID, migratedInitialState: PhetioElementState, newInitialState: PhetioElementState, report: MigrationReport, migratedState: PhetioState, migratedAPI: MigrationPhetioAPI ) => void; @@ -178,7 +179,7 @@ } else { // Compare initial states to see if they are compatible. - compareInitialStatesForCompatibility( archetypePhetioID, migratedAPI, newAPI, migratedState, report ); + compareInitialStatesForCompatibility( statePhetioID, archetypePhetioID, migratedAPI, newAPI, migratedState, report ); } } @@ -190,7 +191,7 @@ // - validValues is allowed to add values, as long as it doesn't change. // - PropertyIO that are just the rangeProperty to a NumberPropertyIO can "widen" their range, as long as it // keeps all previous values. - PropertyIO: ( phetioID, migratedInitialState, newInitialState, report, migratedState, migratedAPI ) => { + PropertyIO: ( statePhetioID, archetypePhetioID, migratedInitialState, newInitialState, report, migratedState, migratedAPI ) => { const migratedValidValues = migratedInitialState.validValues; const newValidValues = newInitialState.validValues; @@ -199,11 +200,11 @@ // Check if all elements of setA are in setB for ( const validValue of migratedValidValues ) { if ( !newValidValues.includes( validValue ) ) { - report.propertyValidValueNoLongerSupported.push( { phetioID: phetioID, missingValue: validValue } ); + report.propertyValidValueNoLongerSupported.push( { phetioID: archetypePhetioID, missingValue: validValue } ); // The new sim doesn't support the migrated value if ( !newValidValues.includes( migratedInitialState.value ) ) { - report.switchedFromInvalidValueToNewDefault.push( phetioID ); + report.switchedFromInvalidValueToNewDefault.push( archetypePhetioID ); migratedInitialState.value = newInitialState.value; } } @@ -217,8 +218,8 @@ if ( !_.isEqual( migratedInitialStateNoValidValues, newInitialStateNoValidValues ) ) { // The state is just a NumberProperty range, and it widens the range from old->new, then don't report incompatibility - if ( migratedAPI.phetioElements[ phetioID ]._metadata.phetioTypeName === 'PropertyIO' ) { - const numberPropertyAPI = migratedAPI.phetioElements[ phetio.PhetioIDUtils.getParentID( phetioID ) ]; + if ( migratedAPI.phetioElements[ archetypePhetioID ]._metadata.phetioTypeName === 'PropertyIO' ) { + const numberPropertyAPI = migratedAPI.phetioElements[ phetio.PhetioIDUtils.getParentID( archetypePhetioID ) ]; if ( numberPropertyAPI && numberPropertyAPI._metadata.phetioTypeName === 'NumberPropertyIO' && migratedInitialState.value.min >= newInitialState.value.min && migratedInitialState.value.max <= newInitialState.value.max @@ -227,10 +228,10 @@ } } - reportInitialStatesIncompatible( phetioID, migratedInitialState, newInitialState, migratedState, report ); + reportInitialStatesIncompatible( statePhetioID, migratedInitialState, newInitialState, migratedState, report ); } }, - NumberPropertyIO: ( phetioID, migratedInitialState, newInitialState ) => { + NumberPropertyIO: ( statePhetioID, archetypePhetioID, migratedInitialState, newInitialState ) => { delete newInitialState.range; delete migratedInitialState.range; } @@ -241,14 +242,15 @@ * Compare the initialStates of a PhET-iO Element between two versions. Remember this is a compatibility check and not * an equality check. */ -function compareInitialStatesForCompatibility( phetioID: PhetioID, +function compareInitialStatesForCompatibility( statePhetioID: PhetioID, + archetypePhetioID: PhetioID, migratedAPI: MigrationPhetioAPI, newAPI: MigrationPhetioAPI, migratedState: PhetioState, report: MigrationReport ): void { - const migratedData = migratedAPI.getData( phetioID ); - const newData = newAPI.getData( phetioID ); + const migratedData = migratedAPI.getData( archetypePhetioID ); + const newData = newAPI.getData( archetypePhetioID ); if ( migratedData && newData ) { const migratedInitialState = migratedData.initialState; @@ -256,7 +258,7 @@ if ( !_.isEqual( migratedInitialState, newInitialState ) ) { - const typeHierarchy = migratedAPI.getTypeHierarchy( migratedAPI.getPhetioTypeName( phetioID ) ); + const typeHierarchy = migratedAPI.getTypeHierarchy( migratedAPI.getPhetioTypeName( archetypePhetioID ) ); // If any level of the type hierarchy provided a custom definition of "compatible", we rely on that behavior let handled = false; @@ -269,7 +271,8 @@ Object.keys( InitialStateComparisonHandler ).forEach( handlerType => { if ( type.startsWith( handlerType ) ) { InitialStateComparisonHandler[ handlerType ]( - phetioID, + statePhetioID, + archetypePhetioID, migratedInitialState, newInitialState, report, @@ -283,7 +286,7 @@ // No custom handler provided specific knowledge about how to compare states, so report it as incompatible if ( !handled ) { - reportInitialStatesIncompatible( phetioID, migratedInitialState, newInitialState, migratedState, report ); + reportInitialStatesIncompatible( statePhetioID, migratedInitialState, newInitialState, migratedState, report ); } } } @@ -291,7 +294,7 @@ // This is fine, it means that the element was deleted in both the migrated and new API } else { - reportInitialStatesIncompatible( phetioID, migratedData?.initialState, newData?.initialState, migratedState, report ); + reportInitialStatesIncompatible( statePhetioID, migratedData?.initialState, newData?.initialState, migratedState, report ); } } @@ -477,12 +480,14 @@ /** * A factored out way to populate the initialStatesAreIncompatible report key. */ -function reportInitialStatesIncompatible( phetioID: PhetioID, migratedInitialState: PhetioElementState | undefined, +function reportInitialStatesIncompatible( statePhetioID: PhetioID, migratedInitialState: PhetioElementState | undefined, newInitialState: PhetioElementState | undefined, migratedState: PhetioState, report: MigrationReport ): void { - report.initialStatesAreIncompatible.push( { phetioID: phetioID, migratedInitialState: migratedInitialState, newInitialState: newInitialState } ); - gracefulStateDelete( phetioID, migratedState, report ); + let archetypePhetioID = ''; + report.initialStatesAreIncompatible.push( { phetioID: statePhetioID, archetypePhetioID: archetypePhetioID, migratedInitialState: migratedInitialState, newInitialState: newInitialState } ); + console.log( statePhetioID, archetypePhetioID ); + gracefulStateDelete( statePhetioID, migratedState, report ); } /**
samreid commented 2 weeks ago

I did not fully understand the patch above, but this subpatch propagates state correctly and has a Congratulations.

```diff Subject: [PATCH] Update keyboard order when mode changes, see https://github.com/phetsims/density-buoyancy-common/issues/355 --- Index: phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts b/phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts --- a/phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts (revision d4b54c012b181c62cab9d44825d7177277d017ab) +++ b/phet-io-sim-specific/repos/circuit-construction-kit-dc-virtual-lab/js/circuit-construction-kit-dc-virtual-lab-migration-processors.ts (date 1724636611884) @@ -7,6 +7,7 @@ import { MigrationProcessors } from '../../../../phet-io-wrappers/common/js/migration/MigrationEngine.js'; import { getCircuitConstructionKit1_4MigrationProcessors } from '../../circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.js'; import DeleteUninstrumentedPhetioElement from '../../../../phet-io-wrappers/common/js/migration/processors/DeleteUninstrumentedPhetioElement.js'; +import RemoveExpectedReportErrors from '../../../../phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.js'; window.phetio = window.phetio || {}; @@ -17,7 +18,26 @@ '1.4.0': [ ...getCircuitConstructionKit1_4MigrationProcessors( simName, [ 'labScreen' ] ), - new DeleteUninstrumentedPhetioElement( `${simName}.general.model.fallbackLocalesProperty` ) + new DeleteUninstrumentedPhetioElement( `${simName}.general.model.fallbackLocalesProperty` ), + new RemoveExpectedReportErrors( { + expectedReportErrors: { + initialStatesAreIncompatible: [ + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.batteryGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.wireGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.resistorGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.extremeBatteryGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.fuseGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.extremeResistorGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.householdObjectGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.realLightBulbGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.extremeLightBulbGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.lightBulbGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.seriesAmmeterGroup.archetype', + 'circuitConstructionKitDcVirtualLab.labScreen.model.circuit.switchGroup.archetype' + ] + } + } ) + ] }; Index: phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts b/phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts --- a/phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts (revision f6c07c76bb697b985c82f9b02b7fa66588b158fe) +++ b/phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.ts (date 1724637125936) @@ -92,7 +92,7 @@ if ( expectedReportedPhetioIDs.includes( phetioID ) ) { // Removing from the report should be accompanied by restoring the state that was gracefully deleted when creating the report entry. If the deletion is intentional and important, then a delete processor should be used (not a report processor). - if ( report.gracefullyDeletedState.hasOwnProperty( phetioID ) ) { + if ( report.gracefullyDeletedState.hasOwnProperty( phetioID ) && !phetioID.includes( '.archetype' ) ) { migratingState[ phetioID ] = report.gracefullyDeletedState[ phetioID ]; } Index: phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts b/phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts --- a/phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts (revision d4b54c012b181c62cab9d44825d7177277d017ab) +++ b/phet-io-sim-specific/repos/circuit-construction-kit-dc/js/circuit-construction-kit-dc-migration-processors.ts (date 1724636611878) @@ -12,6 +12,7 @@ import MigrationPhetioAPI from '../../../../phet-io-wrappers/common/js/migration/MigrationPhetioAPI.js'; import { PhetioState } from '../../../../tandem/js/TandemConstants.js'; import MigrationReport from '../../../../phet-io-wrappers/common/js/migration/MigrationReport.js'; +import RemoveExpectedReportErrors from '../../../../phet-io-wrappers/common/js/migration/processors/report-processors/RemoveExpectedReportErrors.js'; window.phetio = window.phetio || {}; @@ -111,7 +112,40 @@ ...reviseAmmeterStringPropertiesForScreen( simName, 'introScreen' ), ...reviseAmmeterStringPropertiesForScreen( simName, 'labScreen' ), - new DeleteUninstrumentedPhetioElement( `${simName}.general.model.fallbackLocalesProperty` ) + new DeleteUninstrumentedPhetioElement( `${simName}.general.model.fallbackLocalesProperty` ), + + new RemoveExpectedReportErrors( { + expectedReportErrors: { + initialStatesAreIncompatible: [ + // TODO: But this won't bring back the state for battery_0 + 'circuitConstructionKitDc.introScreen.model.circuit.batteryGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.wireGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.resistorGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.extremeBatteryGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.fuseGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.extremeResistorGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.householdObjectGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.realLightBulbGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.extremeLightBulbGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.lightBulbGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.seriesAmmeterGroup.archetype', + 'circuitConstructionKitDc.introScreen.model.circuit.switchGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.batteryGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.wireGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.resistorGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.extremeBatteryGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.fuseGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.extremeResistorGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.householdObjectGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.realLightBulbGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.extremeLightBulbGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.lightBulbGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.seriesAmmeterGroup.archetype', + 'circuitConstructionKitDc.labScreen.model.circuit.switchGroup.archetype' + ] + } + } ) + ] };
zepumph commented 2 weeks ago

That may work for this case, but let's discuss the lack of support for dynamic element analyzing + report processing.