Closed pixelzoom closed 5 months ago
The state schema for HistogramModelIO
involves ReferenceArrayIO
, which (as I understand it) is relatively new and not widely used. To verify that it's not causing this problem, I switched to ArrayIO and (rather than relying on the default serialization functions) explicilty defined toStateObject
and applyState
-- see the patch below. This does not resolve the problem, but rules out ReferenceArrayIO and the default serialization functions.
The problem is specific to totalSpeedBinCountsProperty
. heavySpeedBinCountsProperty
and lightSpeedBinCountsProperty
are properly restored.
To demonstrate... If I check both checkboxes, like this:
... then the Standard Wrapper looks like this:
Adding this to EnergyModel.ts:
this.histogramsModel.totalSpeedBinCountsProperty.link( totalSpeedBinCounts => {
console.log( `heavySpeedBinCounts = ${this.histogramsModel.heavySpeedBinCountsProperty.value}` );
console.log( `lightSpeedBinCounts = ${this.histogramsModel.lightSpeedBinCountsProperty.value}` );
console.log( `totalSpeedBinCounts = ${totalSpeedBinCounts}` );
console.log( '------' );
} );
Running the Standard wrapper paused with 50 heavy particles, I see this in the console:
EnergyModel.ts:42 heavySpeedBinCounts = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
EnergyModel.ts:43 lightSpeedBinCounts = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
EnergyModel.ts:44 totalSpeedBinCounts = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
EnergyModel.ts:45 ------
EnergyModel.ts:42 heavySpeedBinCounts = 5.708333333333333,12.958333333333334,13.333333333333334,7.333333333333333,4.666666666666667,6,0,0,0,0,0,0,0,0,0,0,0,0,0
EnergyModel.ts:43 lightSpeedBinCounts = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
EnergyModel.ts:44 totalSpeedBinCounts = 5.708333333333333,12.958333333333334,13.333333333333334,7.333333333333333,4.666666666666667,6,0,0,0,0,0,0,0,0,0,0,0,0,0
EnergyModel.ts:45 ------
These values look correct. The first set of output is when the sim starts, the second set is when the initial state of the Standard Wrapper is restored.
Collaping and expanding the Speed accordion box in the Standard Wrapper will cause the histogram to update. So I suspect that there is a problem related to histogramNode.updateEnabledProperty
, which is a performance optimization that prevents the histogram from updating while the accordion box is collapsed.
Fixed in the above commits. There was a performance optimization (based on a pesky Emitter) that was resulting in failure to update the Speed "total" plot when restoring state. No idea how the KE "total" plot was getting updated properly, perhaps because it was collapsed by default. I replaced with a superior optimization based on Property. This fixes the problem observed in the Standard wrapper, and the similar "lag" problem in the State wrapper.
@arouinfar @Nancy-Salpepi please review. The last person to review may close. Note that this required major changes to the histograms, so 👀 for regressions.
Good news, the histograms appear to be stateful. Bad news, #262 was introduced. Seems like we should hold off on further testing until it's addressed.
Thanks @pixelzoom. The histograms are looking good on main in the state wrapper and Studio. I'll leave this open for @Nancy-Salpepi to review too.
Histograms look good to me too! Closing.
Reported by @arouinfar and @Nancy-Salpepi.
To reproduce:
Note that something similar happens in the State wrapper with Set-State Rate set to zero. Updating of the histograms lags in the Downstream sim.