Add the OG-Core coupling engine (Linker-Reverse pass) - #539
Open
Adityakushwaha2006 wants to merge 4 commits into
Open
Adityakushwaha2006 wants to merge 4 commits into
Adityakushwaha2006 wants to merge 4 commits into
Conversation
Reads a solved CLEWS energy scenario and runs OG-Core on it in a separate environment, then reports the macro effect. Installable add-on; the app is unchanged unless it is installed and invoked.
Adityakushwaha2006
force-pushed
the
feat/oglink-reverse-pass
branch
2 times, most recently
from
September 1, 2026 12:02
71d8dd6 to
33f6233
Compare
Turn a solved coupled run into an absolute clews_patch.json and apply it via /oglink/applyPatch: a patch builder, a base-SAD reader, a urllib client, and a writeback CLI verb. Targets the final-demand carrier (not the zero-carrying price code), guards against zeroing a cell (a structure change), and picks the active scenario. Discount rate is region-level so it is recorded as deferred, not a change. Docs cover the reverse pass and the writeback command.
Adityakushwaha2006
force-pushed
the
feat/oglink-reverse-pass
branch
from
September 1, 2026 12:19
33f6233 to
e7c650e
Compare
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.
Parent Issue : #538 | Relates to Solution of Stage 1 - Reverse Pass
Dependency
Stack on top of PR #498, #520 & #537 .
Summary
reads OG-Core's demand feedback, turns it into an absolute change on the CLEWS case, applies it through the
existing
/oglink/applyPatchseam, and reports the re-solved CLEWS result. The forward pass sends an energyprice into the economy; this sends the economy's demand response back into the energy model.
This is the other half of one coupling pass. It builds on the forward pass (537) and the applyPatch seam,
and it stops at a single pass.
Where this sits
flowchart LR CLEWS["CLEWS<br/>energy, land, water model"] OGC["OG-Core<br/>macroeconomy model"] subgraph LINK["The linker add-on"] direction TB F["FORWARD PASS<br/>energy price and costs to macro results<br/>(done)"]:::done B["REVERSE PASS<br/>macro demand back to energy inputs<br/>(this PR)"]:::now L["CONVERGENCE LOOP<br/>repeat until both models agree<br/>(later)"]:::later end CLEWS -->|price, emissions, capex| F F -->|run in its own env| OGC OGC -->|activity demand ratio| B B -->|clews_patch.json to applyPatch| CLEWS F -.-> L B -.-> L classDef done fill:#e7eff7,stroke:#5a86b3,color:#1f3a56; classDef now fill:#d3f5df,stroke:#1f9d57,color:#0f3d22; classDef later fill:#eeeeee,stroke:#999999,color:#555555; style LINK fill:none,stroke:#555555,stroke-dasharray:6 5How it works, step by step
base ratio of the economy's activity). The reverse pass reads that ratio straight from the run folder.
the same rows the seam will overwrite, so the value it scales and the value that gets set are the same.
It targets the household final-demand commodity that actually carries load, only for years at or after the
model start year, and skips any year the change would leave unchanged.
clews_patch.jsonof absolute values and posts itto
/oglink/applyPatchover HTTP. Nothing is written into the case directly.regenerates the datafile, checks the structure did not change, solves, and returns the results folder.
warning from the seam as a failure, since that means the base demand it read had drifted.
Validation
year clipping, no-op suppression, the all-zero base guard, the guard against zeroing a live cell, the
discount-rate deferral, and the change shape. The HTTP client is covered for the success path, a blocked
patch (the seam's reasons are surfaced), and an unreachable server.
equal base demand times the ratio and that the change list is well formed, with no network call.
no app URL is set, so the default test run stays fast and server-free.
every module still imports with OG-Core absent.
Notes for review
applyPatch seam. It targets
mainonce both land.rather than the price-facing code; and the demand driver is the sector-output ratio. Both follow the
established behaviour and are one-line settings if preferred otherwise.
the seam's change model (single-entity year tables) cannot express. It is recorded as a deferred note to be
taken up at the coupling stage.
Checklist
EAPD-DRB/MUIOGO:mainNote on the True Diff :