Closed matthew-blackman closed 1 year ago
In further testing, I saw this error occurred some times and not other times, even depending on the wire length. So it seems to be a roundoff error for certain configurations. I tried rounding off the current values in the model like so and that seemed to prevent the problem.
I'm not sure if rounding off the model could cause other problems though. Let's discuss.
@matthew-blackman and I want to track the inputs to the analysis and see if we are getting different outputs (even if at 1E-9) for the same inputs.
Patch from 12/14/22 with @samreid :
@arouinfar we have found the source of this issue, which is that the currentProperty is being set twice per frame, once before conserveCurrent is called and then again afterwards. @samreid and I found that this could be solved by adding a tempCurrent value to components and setting tempCurrent before conserveCurrent, and finally using tempCurrent to set currentProperty after conserveCurrent has run.
@samreid and I are 90% confident that this solution would take about 1-4 hours to implement. This issue could also be addressed via communication/documentation with users, informing them where the current values are coming from. Thoughts on how to proceed @arouinfar?
Note that this would slightly increase the complexity of the code, rather than simplify the model logic. It would look simpler from the user perspective, however.
@samreid @matthew-blackman thanks for investigating. I think we can defer this for now. The data stream is underutilized and we have a deferred epic to design it, https://github.com/phetsims/phet-io/issues/1734. In the meantime, we can designate these properties phetioHighFrequency: true
.
This issue could also be addressed via communication/documentation with users, informing them where the current values are coming from.
Documentation sounds great. Any ideas where we should document this? Is there sim-specific documentation for developers? Currently, examples.md focuses on the phetioIDs
relevant to specific customization, but maybe we can add a notes section to the bottom.
I feel it should be a section in examples.md since that is the "sim specific" documentation. But I'm not sure how it is an "example". Maybe there would be a section like:
Due to an implementation detail in the simulation, the current and power are computed in a 2-phase algorithm, and have their values set twice during one step. So if you are observing values like circuitConstructionKitDc.introScreen.model.circuit.lightBulbGroup.lightBulb_0.currentProperty
or circuitConstructionKitDc.introScreen.model.circuit.batteryGroup.battery_0.powerGeneratedProperty
in the data stream or by adding listeners to them, please be aware there will be the intermediate value and the final value. The intermediate value is computed by the numerical algorithm, then the final value is computed via a post-processing "current conservation" step, which often just changes the values slightly.
Thanks for writing that up @samreid! I think it makes sense to keep all sim-specific documentation in a single file, so I've added your comment to #865. The primary purpose of examples.md will remain the same (list of example customizations) but I think there will be situations where we want to provide additional documentation.
We can continue to refer to the doc as "Examples" but we should probably revisit the description on the wrapper index page and the references to it in the PhET-iO Guide. How does that sound @samreid? If you agree, we can open up issues in the appropriate repos.
I think the last TODO for this issue is to set currentProperty
, powerDissipatedProperty
and powerGeneratedProperty
to phetioHighFrequency: true
.
@matthew-blackman and I set those to phetioHighFrequency: true and also saw that Vertex positionProperty was spamming the console, so we marked it as high frequency too. We both reviewed and saw it is working properly, so this issue seems good to close. Thanks!
We can continue to refer to the doc as "Examples" but we should probably revisit the description on the wrapper index page and the references to it in the PhET-iO Guide. How does that sound @samreid? If you agree, we can open up issues in the appropriate repos.
The text currently says "Provides instructions and the specific phetioIDs for customizing the simulation." which I don't think is too bad. In this case, it is kind of about customizing how you use the data stream. Anyways, please open a side issue or let me know if that should be changed for this release.
Thanks @samreid @matthew-blackman! The changes look good in master.
I'll leave this self-assigned to open up issues related to the Examples doc, and then we're good to close.
I agree with @samreid, I think the wrapper index page is sufficiently general. I made a minor wording change to the PhET-iO Guide in https://github.com/phetsims/phet-io-sim-specific/issues/19. There is no need to publish any MR or cherry-pick into existing RC's.
Connecting a circuit with the data stream running shows rapid logs like the following:
circuitConstructionKitDc.introScreen.model.circuit.batteryGroup.battery_0.powerGeneratedProperty changed {"oldValue":8.09991906553702,"newValue":8.099920065564913}
circuitConstructionKitDc.introScreen.model.circuit.lightBulbGroup.lightBulb_0.currentProperty changed {"oldValue":0.8999910072818911,"newValue":0.8999909974817832}
circuitConstructionKitDc.introScreen.model.circuit.lightBulbGroup.lightBulb_0.powerDissipatedProperty changed {"oldValue":8.099838131882729,"newValue":8.099837955482553}
It appears the current and power properties are being set to slightly new values every frame.