Show simulation results for arrayed and unit-error'd variables#611
Conversation
Simulation results key each arrayed variable's per-element series by the engine's canonicalized element name (e.g. `temperature[high_2xco2_sensitivity]`), but a Dimension preserves the model's original-case subscript names (`High_2xCO2_sensitivity`). projectAttachData built its lookup keys from the original-case subscripts, so for any arrayed variable whose dimension elements are not already lowercase the keys never matched and the variable received an empty data array -- the diagram then rendered no sparkline for it.
This silently blanked every arrayed variable in C-LEARN (its scenario dimension is {Deterministic, Low_2xCO2_sensitivity, High_2xCO2_sensitivity}), which is why the model appeared to produce no results even though the engine simulates it correctly and isSimulatable() is true. Canonicalizing the element when building the key restores per-element data (verified end-to-end: variables with attached data went from 492 to 814 on C-LEARN). Multi-dimensional arrayed variables remain unhandled by the dimNames.length !== 1 guard -- a separate limitation.
Review —
|
Generalizes projectAttachData to group every result series by its base variable ident (the text before the first `[`) and attach all of them. A scalar gets its single bare-keyed series; an arrayed variable gets every per-element series the simulation emitted, for any dimensionality. This supersedes the previous 1-D-only path (which also had to canonicalize element names to match keys) and removes the `dimNames.length !== 1` guard that silently dropped all multi-dimensional arrayed variables. Because grouping matches whatever keys the run produced rather than reconstructing them from a Dimension's original-case subscripts, the element-name canonicalization mismatch can no longer recur. The display layer already plots every series (LineChart in VariableDetails draws one line per element; the canvas Sparkline draws one path per element), so attaching the full set is all that was needed. Verified end-to-end on C-LEARN: variables with attached data went 814 -> 873; a scalar attaches 1 series, a 1-D arrayed var 3, and the multi-dimensional co2eq_emissions_from_hfc all 63.
ReviewThe core change in [P3] Stale test comments describe the abandoned key-reconstruction approach
Overall correctness: correctThe patch is free of functional bugs; existing behavior and tests are preserved, and the generalization to multi-dimensional arrayed variables is correct. The only issue is the stale (non-blocking) test comments noted above. |
The variable details panel previously replaced the chart with an error list whenever the variable had ANY error, including a non-fatal unit error. A unit error does not stop the variable from simulating, so it has valid data worth charting; hiding the chart meant a model with many unit errors (e.g. C-LEARN, 481) showed almost no results in the details panel. Now only genuine equation/compile errors (which leave the variable with no data) replace the chart; unit errors are surfaced as warnings beneath the chart instead. The chart-vs-errors decision is a small pure helper (variableDetailsView) so it is unit-tested directly. Together with the projectAttachData fix, both scalar (one line) and arrayed (one line per element) variables now display their results in the details chart even when they carry unit warnings.
Code reviewI reviewed the rewrite of [P3] Misleading test comment about series ordering
The comment states the attached series are "ordered by the dimension's declared subscript order," but Overall correctness: correctThe patch is free of blocking issues. Existing behavior is preserved (unit errors still render alongside equation errors; scalars still attach their single series) and the new multi-dimensional path is exercised by tests. The single note above is a non-blocking documentation nit. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #611 +/- ##
=======================================
Coverage 82.85% 82.86%
=======================================
Files 261 261
Lines 69836 69836
=======================================
+ Hits 57866 57867 +1
+ Misses 11970 11969 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Arrayed variables — and any variable carrying a unit error — showed no simulation results in the editor, even though the engine simulates them correctly. This PR makes results display for scalar, 1-D arrayed, and multi-dimensional arrayed variables, on both the canvas sparklines and the variable-details chart, including when a variable has non-fatal unit errors.
Surfaced on C-LEARN, whose substantive variables are arrayed over a
scenariodimension and which carries 481 unit errors. The engine is fine throughout:isSimulatable()istrueand the run produces 3607 valid series; the results just weren't reaching the diagram.Root causes
projectAttachData(src/core/datamodel.ts) rebuilt per-element lookup keys from aDimension's subscripts, which preserve the model's original-case names (Deterministic,High_2xCO2_sensitivity), while the simulation keys series by canonicalized names (high_2xco2_sensitivity) → 0 matches → empty data. Multi-dimensional arrayed variables were skipped outright by adimNames.length !== 1guard.VariableDetails.tsx) replaced the chart with an error list whenever the variable had any error, including a non-fatal unit error.Changes
projectAttachDatato group every result series by its base variable ident (text before the first[) and attach all of them. Scalar (1 series), 1-D, and multi-D are handled uniformly; it matches whatever keys the run emitted, so the canonicalization mismatch cannot recur and multi-dimensional variables are included ("plot all the series").variableDetailsView), unit-tested directly.The display layer already plots every series —
LineChart(variable details) draws one line per element and the canvasSparklinedraws one path per element — so attaching the full set is all that was needed.Verification
projectAttachData(original-case 1-D, already-canonical 1-D, multi-D, no-data) andvariableDetailsView(no errors / unit-only / equation / both).100_percent→ 1 series, 1-Dadjusted_temperature_change_from_preindustrial→ 3, multi-Dco2eq_emissions_from_hfc→ all 63.Ruled out during investigation
LTM (the diagram runs with
analyzeLtm=false), unit errors gating simulation (they don't —isSimulatable()is true), and the protobuf round-trip (clean). The orange box the user saw is just the 481 unit-error warnings.