Repository navigation
engine: rank LTM discovery competitive-first, expose cycle partitions (#671) - #686
Merged
Merged
Conversation
On C-LEARN, model.analyze() led with dozens of trivial two-variable gas-uptake loops while the coupled carbon-climate core was buried below them. The defect is information content: a loop alone in its cycle partition has relative loop score exactly +/-1 at every active step by construction (its own |score| is the whole normalization denominator), so ranking by mean |relative score| lets these zero-information loops win over loops that genuinely compete for dominance. Discovery now ranks competitive-first: loops sharing their partition with at least one other discovered loop come first (ordered by the unchanged, paper-aligned mean relative importance), and trivially isolated loops sort after all of them; the MAX_LOOPS cap drops the solo loops first. A partition-major ordering (giant component first by stock count) was considered and rejected: it would rank a dynamically inert giant partition's loops above a genuinely dominant small-partition loop, and any score-based partition ordering is unit-dependent and crosses the papers' partition-comparability boundary. The GH #543/#310 contracts are preserved for competing loops (their fixtures gain a second small- partition loop so the partition-dominant survivor is non-degenerate). Cycle partitions become first-class discovery output: each FoundLoop carries a result-scoped dense partition index (first-appearance order; not stable across edits, since the SCC numbering renumbers on stock adds/renames -- consumers needing durable identity key on the stock-name set) and DiscoveryResult/ModelAnalysis carry the partition list (stocks, returned-loop count), threaded through the C FFI (SimlinDiscoveredLoop. partition, SimlinDiscoveredPartition; neither discovery struct is ABI-size-tracked and only pysimlin reads them) and pysimlin (Analysis.partitions, Loop.partition). Exhaustive-mode parity is deliberately out of scope and tracked separately. The C-LEARN notebook's section 4 now opens with the model's feedback anatomy (3 giant 15-stock carbon-climate partitions of ~47 competing loops each, plus 12 isolated gas-decay singletons) and the ranking surfaces the core directly; verified end-to-end by rebuilding the notebook and running the ignored C-LEARN suites (discovery compile, LTM identity vs Ref.vdf, pinned climate loop, wasm twins).
Review summaryNo blocking findings. The competitive-first ranking (
Overall correctness verdictCorrect. No correctness bugs identified; tests cover the solo-demotion ordering, cap-pressure truncation order, partition metadata indexing (including the no-score-data path), and determinism under input permutation. The notebook + design doc + MCP instructions are aligned with the new ranking contract. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improves loop discovery so it prioritizes the most important loops: partition the feedback structure, then surface the loops competing within the giant component instead of the trivially-isolated singletons.
Problem
On C-LEARN,
model.analyze()led with dozens of two-variable gas-uptake loops while the coupled carbon-climate core was buried below them. The defect is information content: a loop alone in its cycle partition has relative loop score exactly +/-1 at every active step by construction (its own |score| is the entire normalization denominator), so ranking by mean |relative score| lets these zero-information loops win over loops that genuinely compete for dominance.Ranking change
Discovery now ranks competitive-first: loops sharing their cycle partition with at least one other discovered loop come first, ordered by the unchanged paper-aligned mean relative importance (ref 13.3); trivially-isolated loops sort after all of them, and the
MAX_LOOPScap drops the solo loops first. Never-active (NaN) loops still sort last.A partition-major ordering (giant component first by stock count) was considered and rejected after an adversarial design review: it would rank a dynamically inert giant partition's loops above a genuinely dominant small-partition loop, and any score-based partition ordering is unit-dependent and crosses the papers' cross-partition-comparability boundary (ref section 8). The GH #543/#310 contracts are preserved for competing loops -- their test fixtures gain a second small-partition loop so the partition-dominant survivor is non-degenerate rather than a solo +/-1 loop.
Cycle partitions become first-class API
Each
FoundLoopcarries a result-scoped densepartitionindex (first-appearance order over the ranked list; deliberately documented as NOT stable across edits, since the SCC numbering renumbers on unrelated stock adds/renames -- durable identity keys on the partition's stock-name set), andDiscoveryResult/ModelAnalysiscarry the partition list (element-level stock names, returned-loop count). Threaded through:SimlinDiscoveredLoop.partition, newSimlinDiscoveredPartition,SimlinDiscoveryResult.partitions(neither discovery struct is ABI-size-tracked; only pysimlin reads them, via the regenerated header)Analysis.partitions,Loop.partition, newPartitiondataclassExhaustive/pinned-surface parity (
SimlinLoop,Model.loops/Run.loops, MCP) is deliberately out of scope and tracked as #685.C-LEARN, end to end
analyze()now reports 153 loops across 15 partitions: three 15-stock, 47-loop carbon-climate giant components (one perscenarioelement) on top -- ocean carbon buffering, the CO2-forcing-temperature loops, the biomass revolving door -- and the 12 isolated gas-decay singletons at the bottom. The notebook's section 4 was rebuilt to open with this feedback anatomy (partition table first, then the ranking with a partition column); the expert-pin cross-validation and the decade-median dominance story are unchanged.Testing
Full pre-commit gauntlet (Rust fmt/cbindgen/clippy/tests, TS lint/build/tsc/tests, pysimlin tests/ruff/mypy), plus the ignored C-LEARN suites run explicitly:
clearn_ltm_discovery_compiles,clearn_with_ltm_simulates_model_vars_identically,clearn_pinned_climate_loop_is_scored,simulates_clearn,clearn_residual_exactness, and the wasm twins (simulates_clearn_wasm,simulates_wrld3_03_wasm). New/rewritten unit tests pin the solo-demotion ordering, truncation order under cap pressure, dense partition-metadata indexing (including the no-score-data path), and determinism under input permutation.Closes #671.