-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PhET-iO instrumentation #14
Comments
Raising priority to "high". Milestones section of the design document says "Features implemented by late September 2018". If the goal is to instrument this sim "as part of initial instrumentation" (as noted above), then we may have already missed that opportunity. |
Notes from 9/20/18 design meeting:
|
@amanda-phet @ariel-phet @kathy-phet FYI, notes about PhET-iO instrumentation are in the comment above. Let me know if I omitted anything. |
I'd like to review these requirements with @samreid before starting implementation. After stumbling across the "how to design PhET-iO features for a simulation document, I'm not confident that we have a solid plan for "amount of state that must be saved and restored". |
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
Instrumentation is partially completed. Compared to hookes-law, this is not going as smoothly, and talking a lot more time (6+ hours so far). Search for |
Worked on QuadraticIO a bit with @samreid, see above commits. |
Any estimate on when review will be completed? Graphing Quadratics needs to start dev testing on Friday 10/19 to stay on schedule. But it looks like there are a lot of checklist items that still need to be created. |
I've unexpectedly had yesterday and today off, please coordinate with @ariel-phet @chrisklus and @zepumph to decide how to proceed. |
Today @chrisklus and @zepumph worked on this for a few hours. We went through all the code for the first screen (including sim specific common types). It would be safe to say that we checked all the boxes down to (not including) the Data Stream heading. The next three screens will likely go much faster since we spent most of our time in the sim common files (there is a lot of shared hierarchy in this sim). |
I was unable to attend all meetings yesterday, is the conclusion that GQ is beginning dev testing for brand=phet today, then brand=phet-io will be for the future? |
@samreid that's correct, though @pixelzoom would like us to keep up our momentum getting though the phet-io side of things next week. |
Yes. PhET-iO review is taking longer than anticipated, and there are a significant number of blocking issues. After consultation with @ariel-phet, we decided that there was value in doing an initial dev test for brand=phet. So I initiated that yesterday, see phetsims/qa#211. The goal is still to have PhET-iO instrumentation completed before final dev testing, code review, and RC testing. |
Review complete, discovered questions and problems were described in new issues. There are these remaining steps, but they seem more relevant to the master checklist than part of the phet-io code review step:
@pixelzoom back to you. Please let me know if you have any questions or comments about this review, or feel free to close if everything here is done and we can continue in the linked issues. |
I think we can close this now. |
At 8/16/18 dev meeting, @ariel-phet said that we should attempt to do PhET-iO instrumentation as part of initial instrumentation for this sim. So we need to specify the PhET-iO API -- what needs to be instrumented, tandem name, etc.
Setting priority of this to "medium". It would be nice to have this specification completed soon, so that instrumentation occurs while the code is being written, rather than as a separate (later) task.
UPDATE from @samreid: I'm commandeering this comment for the PhET-iO Instrumentation checklist. For this issue, a checkmark indicates it has been reviewed. Discovered problems will be noted as new issues or comments in this issue.
How to Instrument a PhET Simulation for PhET-iO
Before instrumenting
/blob/<SHA>/
so that the specific guide you used is preserved. https://github.com/phetsims/phet-io/blob/a7436d70e1671c0a12e007356b9a4c8d42e6e5b3/doc/how-to-instrument-a-phet-simulation-for-phet-io.mdCode Review
A high-quality Code Review will make instrumentation easier, promote long term maintainability for the
simulation, and protect the simulation from a volatile API. If the simulation is already in good shape, the review
will not take too long. If the simulation is not in good shape, then it needs your help.
Instrumentation
Now that the simulation is in good shape and the PhET-iO design meeting is complete, we are ready to instrument the simulation.
Follow the checklist below, and if you have questions you can review Faraday's Law and its PhET-iO instrumentation or
reach out to teammates who may have come this way before.
Initial Setup
tandem
s to each screen usingtandem.createTandem(...)
Visit Objects that Should be Instrumented
Consult the PhET-iO design issue to see what features the sim should support. See
https://github.com/phetsims/tandem/tree/master/js/PhetioObject.js for the
supported PhetioObject options. Not every node in the hierarchy must be instrumented, but every leaf is instrumented.
For example the
view
is rarely instrumented. UsephetioValidateTandems=false
to test the links from the wrapperindex with a partially-instrumented simulation.
tandem
s and otherPhetioObject
options into objects that should be instrumented. Do not instrument objects that are "implementation details" and do not over-instrument.units
inNumberProperty
for example, and should be passed where appropriate.)Creating and Naming Tandems
Well-designed tandem names are important. Once the PhET-iO simulation is published, the API becomes public and therefore
difficult to change. Sometimes PhET-iO design meetings can also help come up tandem names. NOTE: "Tandem" is a PhET
internal name, publicly to clients the full strings are known as "phetioIDs."
Screen
instance tandems should end with aScreen
suffix.Property
suffix.model
andview
.Tandem.required
for constructors that already have an options parameter. This default can be helpful for identifying cases where you have neglected to pass a tandem in (becauseTandem.required
will error loudly if validating tandems).createGroupTandem
for arrays or otherwise numbered tandems. See usages for examples.See BeersLawSolution.js for an example.
Feature Support
Property
instances to make it possible to get/set a value, so value changes will appear on the data stream and so the item can be stored and restored in save/load.Property
orEmitter
elements by composition, or subclassPhetioObject
.tandem: Tandem.required
ortandem: Tandem.optional
to the options accordinglymutate
but not both.printMissingTandems
flag if you want to collect a list of all required, optional, and uninstrumented common code classes instead of erroring out on the first missing tandem. Each occurrence is numbered to give a better idea of how many the sim has to do.Create new IO types
If necessary, create new IO types to support desired feature set. Generally we don't want to be locked in to coupling
IO Types to sim types. Instead, we decided that we want the PhET-iO API to be able to vary independently from the sim
implementation instead of leaking sim implementation details. Still, for a well-designed simulation, IO Types will
often match closely with the sim types. To ensure good IO type inheritance hierarchies follow these principles:
See sloppy TTypes beers-law-lab#213 for more context on prior problems in this area and discussion
about it.
The Data Stream
Emitter
instances as appropriate to augment the data stream.Emitters
andProperty
instances naturally emit to a structured data stream and are probably what you need. If you need something more custom, you can callphetioStartEvent
andphetioEndEvent
directly.Emitter.addListener
instead ofEvents.onStatic
Emitter.emitN
argument, you may specifyVoidIO
for its type, see PressListener.jsphetioEventType: 'user'
for pointer events, keyboard events and UI events (like checkbox toggled, button pressed), andphetioEventType: 'model'
for model actions/responses. This is easiest to test in the console: colorized wrapper. Model events will be logged in black, and user events will be logged blue. You can also go to the data-stream wrapper to see events in JSON form.Post Instrumentation and Checks
dispose
d, which unregisters the tandem.dt
values are used instead of Date.now() or other Date functions. This is necessary for reproducible playback via input events. Perhaps tryphet.joist.elapsedTime
.phet.joist.random
, and all doing so after modules are declared (non-statically)? For example, the following methods (and perhaps others) should not be used:Math.random
,_.shuffle
,_.sample
,_.random
.undefined
values cannot be saved by phet-io, sims should be written to usenull
instead.grunt --brands=phet-io
and test the built version by launching build/wrappers/index and testing all the links.Support dynamic state
For simulations that have static content (such as a fixed number of objects and properties), instrumentation
is complete after you have completed the preceding steps. For simulations that have a dynamic number of objects,
such as Circuit Construction Kit circuits or Molecules and Light photons, the containers and elements must be instrumented.
This is currently tricky with PhET-iO. Some sims may wish to avoid this entire hassle by pre-allocating all of the
instrumented instances. Consider adding flags to indicate whether the objects are "alive" or "in the pool".
Details about how to support dynamic state.
Beer's Law Lab and Charges and Fields demonstrates how this may be done. A container class defines two methods:
clearChildInstances
which empties a container andaddChildInstance
which repopulates a container one element at atime. For example, see ShakerParticlesIO in the beers-law-lab instrumentation.
When state is set, first the container is cleared, then children are created. Child states can be obtained from
toStateObject
and set back with
fromStateObject
, with an additional call tosetValue
in case additional data is supplied, or customcode can be used.
Dispose must be implemented properly on all dynamic instances, or else it will result in stale values in the playback sim.
For example, if a simulation is sending the position of a particle as a property, if the particle position property
hasn't been disposed of, the simulation will try to create a new property with the same id and hence throw an assertion
error because that tandem is already registered.
On January 11, 2017 ControlPoints were not being disposed correctly in Energy-skate-park-basics, causing a mysterious bug
(impossible set state), make sure that children are being disposed correctly before creating them in the downstream sim!
Other tips and tricks for "impossible set state":
can be addressed the same way
Dispose functions must be added to types that are instrumented. But that's only half of the memory management issue. The
other half is revisiting memory management for all instances that don't exist for the lifetime of the sim, and verifying
that tandems are properly cleaned up.
Tips, Tricks, Notes, Misc
reason that testing without iframes, using the `Data: colorized" wrapper is sometimes preferable.
see https://github.com/phetsims/phet-io/issues/107
a while of testing it can be annoying to have the extra step:
phetmarks --> index --> desired wrapper
. Instead youcan use phetmarks to launch any individual wrapper, just don't forget
phetioValidateTandems=false
until youare ready for it. Note that the wrapper index in the build version is at the top level of the build dir (
build/phet-io/
).Two types of serialization
Data type serialization For example, numbers, strings, Vector2 instances fall into this category. These values
are instantiated by
fromStateObject
.Reference type serialization For example, Nodes and Properties. For example, if a simulation has one
heightProperty
that exists for the lifetime of the sim then when we save the state of the sim, we save the dynamic characteristics of
the
heightProperty
(rather than trying to serialize the entire list of listeners and phet-io metadata. Then thePhET-iO library calls
setValue()
to update the dynamic characteristics of theheightProperty
without dealing withall of Property's many attributes. The static
setValue
methods on IO Types are automatically called by PhET-iO torestore dynamic characteristics of reference-type serialized instances. Search for toStateObject in *IO.js files for examples.
Review and Publication
Happy instrumenting!
The text was updated successfully, but these errors were encountered: