-
Notifications
You must be signed in to change notification settings - Fork 6
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
Speed histogram displays no data in the Standard wrapper. #261
Comments
The state schema for patchSubject: [PATCH] initialize rightPanels position before creating dragBoundsProperty for compassNode, https://github.com/phetsims/faradays-electromagnetic-lab/issues/183
---
Index: js/energy/model/HistogramsModel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/energy/model/HistogramsModel.ts b/js/energy/model/HistogramsModel.ts
--- a/js/energy/model/HistogramsModel.ts (revision d7277601a6bc5ad6e30705329897bf243878c74b)
+++ b/js/energy/model/HistogramsModel.ts (date 1718211876094)
@@ -21,7 +21,6 @@
import gasProperties from '../../gasProperties.js';
import IOType from '../../../../tandem/js/types/IOType.js';
import isSettingPhetioStateProperty from '../../../../tandem/js/isSettingPhetioStateProperty.js';
-import ReferenceArrayIO from '../../../../tandem/js/types/ReferenceArrayIO.js';
// Describes the properties of the histograms at a specific zoom level.
type ZoomLevel = {
@@ -48,10 +47,10 @@
const STATE_SCHEMA = {
dtAccumulator: NumberIO,
numberOfSamples: NumberIO,
- heavySpeedCumulativeBinCounts: ReferenceArrayIO( NumberIO ),
- lightSpeedCumulativeBinCounts: ReferenceArrayIO( NumberIO ),
- heavyKineticEnergyCumulativeBinCounts: ReferenceArrayIO( NumberIO ),
- lightKineticEnergyCumulativeBinCounts: ReferenceArrayIO( NumberIO )
+ heavySpeedCumulativeBinCounts: ArrayIO( NumberIO ),
+ lightSpeedCumulativeBinCounts: ArrayIO( NumberIO ),
+ heavyKineticEnergyCumulativeBinCounts: ArrayIO( NumberIO ),
+ lightKineticEnergyCumulativeBinCounts: ArrayIO( NumberIO )
};
export default class HistogramsModel extends PhetioObject {
@@ -325,6 +324,41 @@
this.clearSamples();
}
+ /**
+ * Serializes this instance of HistogramsModel.
+ */
+ private toStateObject(): HistogramsModelStateObject {
+ return {
+ dtAccumulator: this.dtAccumulator,
+ numberOfSamples: this.numberOfSamples,
+ heavySpeedCumulativeBinCounts: ArrayIO( NumberIO ).toStateObject( this.heavySpeedCumulativeBinCounts ),
+ lightSpeedCumulativeBinCounts: ArrayIO( NumberIO ).toStateObject( this.lightSpeedCumulativeBinCounts ),
+ heavyKineticEnergyCumulativeBinCounts: ArrayIO( NumberIO ).toStateObject( this.heavyKineticEnergyCumulativeBinCounts ),
+ lightKineticEnergyCumulativeBinCounts: ArrayIO( NumberIO ).toStateObject( this.lightKineticEnergyCumulativeBinCounts )
+ };
+ }
+
+ /**
+ * Deserializes an instance of HistogramsModel.
+ */
+ private static applyState( histogramsModel: HistogramsModel, stateObject: HistogramsModelStateObject ): void {
+
+ histogramsModel.dtAccumulator = stateObject.dtAccumulator;
+ histogramsModel.numberOfSamples = stateObject.numberOfSamples;
+
+ histogramsModel.heavySpeedCumulativeBinCounts.length = 0;
+ histogramsModel.heavySpeedCumulativeBinCounts.push( ...stateObject.heavySpeedCumulativeBinCounts );
+
+ histogramsModel.lightSpeedCumulativeBinCounts.length = 0;
+ histogramsModel.lightSpeedCumulativeBinCounts.push( ...stateObject.lightSpeedCumulativeBinCounts );
+
+ histogramsModel.heavyKineticEnergyCumulativeBinCounts.length = 0;
+ histogramsModel.heavyKineticEnergyCumulativeBinCounts.push( ...stateObject.heavyKineticEnergyCumulativeBinCounts );
+
+ histogramsModel.lightKineticEnergyCumulativeBinCounts.length = 0;
+ histogramsModel.lightKineticEnergyCumulativeBinCounts.push( ...stateObject.lightKineticEnergyCumulativeBinCounts );
+ }
+
/**
* HistogramModelIO handles serialization of data that supports derivation of speed and kinetic energy histograms.
* It implements reference-type serialization, as described in
@@ -334,9 +368,11 @@
valueType: HistogramsModel,
stateSchema: STATE_SCHEMA,
documentation: 'PhET-iO Type that supports sampling of the Speed and Kinetic Energy of the particle system. ' +
- 'All fields in this type are for internal use only.'
+ 'All fields in this type are for internal use only.',
// toStateObject: Use the default, which is derived from stateSchema.
+ toStateObject: histogramsModel => histogramsModel.toStateObject(),
// applyState: Use the default, which is derived from stateSchema.
+ applyState: HistogramsModel.applyState
} );
}
|
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:
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 |
…nsible for observing Property and handling updates, #261
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. |
#262 has been addressed, so you may resume review. |
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.
The text was updated successfully, but these errors were encountered: