Skip to content

Move the OG-CLEWS linker into MUIOGO - #550

Open
marcelolafleur wants to merge 10 commits into
EAPD-DRB:mainfrom
marcelolafleur:feature/538-linker-in-muiogo
Open

marcelolafleur wants to merge 10 commits into
EAPD-DRB:mainfrom
marcelolafleur:feature/538-linker-in-muiogo

Conversation

@marcelolafleur

Copy link
Copy Markdown
Collaborator

Depends on #549 (Python 3.11 and 3.12). Please merge that first. Until then this PR also shows #549's two commits.

MUIOGO becomes the home of the OG-CLEWS linker, the code that takes a solved CLEWS case into an OG-Core country model. It was developed in the ogclews-link research repository, and MUIOGO's post-run hook called it from there. This brings the current version in as the oglink folder, and new work on the linker happens here from now on.

How it runs

  • It's part of MUIOGO and needs no separate install. It runs with MUIOGO's own Python, as a separate process. The web app never imports it.
  • Each OG country model still runs in its own environment. The linker lends it this folder's code for the length of the run and installs nothing there.
  • GET /oglink/status now says plainly when the linker can't run, for example when an older MUIOGO environment hasn't picked up scipy yet.

What changed on the way in

  • The matplotlib figure deck is removed. The linker writes its results as data, and MUIOGO will chart them with its own libraries in a later PR.
  • The linker still works out the feedback for CLEWS (demand, carbon price, discount rate). Sending it back into a CLEWS case goes through MUIOGO's applyPatch endpoint, which Add the OG-Core coupling engine (Linker-Reverse pass) #539 connects. So the older ogclews-link code that wrote into case storage directly stays there, along with an unused environment-accounts module.
  • From Add the OG-Core coupling engine (Linker-Forward pass) #537: reading CLEWS tables by exact name, a visible record when the cost-push leg can't be computed, and 16 tests. Thanks @Adityakushwaha2006, credited as co-author on that commit. The exact-name reader also needed a fix in the marginal-price reader.

MUIOGO side

  • scipy 1.17.1 is added. The health channel needs it. It's the newest scipy that works with MUIOGO's numpy 1.26.4, and it also works with numpy 2, so Fix the Python version ceiling so MUIOGO can support 3.13+ #473 won't need to change it.
  • The post-run hook runs the in-repo linker. The linker's tests run in the CI test job.

Checked

  • The linker's tests pass in MUIOGO's environment: 205, plus 3 skipped that need an OG model package. MUIOGO's 358 tests pass.
  • On a running server, /oglink/status?deep=1 finds the linker and all installed OG models.
  • The full coupled run on the Philippines GOLD case reproduces the Aug 14 results exactly: every cell of the macro table, the health effect, and the feedback files for CLEWS.

This replaces #537. #539, the reverse pass, can be rebased on top of this. Part of #538.

@autibet could you review this one?

marcelolafleur and others added 10 commits September 24, 2026 11:44
MUIOGO now requires Python 3.11 or 3.12. Python 3.10 reaches end of life in
October 2026, and nothing in MUIOGO needs it.

The installers no longer take whatever Python happens to be on the machine:
a .python-version file makes uv build every environment on 3.12. The startup
check, the setup scripts, the docs and CI all follow the new range, and CI
now tests on 3.12. The lockfile drops only the 3.10 downloads; no package
version changes.
With 3.11 as the minimum, the linter targets 3.11 and asks for the shorter
datetime.UTC in place of datetime.timezone.utc. They are the same value, so
behaviour does not change.
MUIOGO becomes the home of the linker that couples CLEWS results into OG-Core
country models. This copies the current linker from the ogclews-link research
repository (branch experiment/v18-gold-coupled, commit ee92c9b), renamed from
ogclews_link to oglink, with its tests, the IHME burden data it needs for the
health channel, and its data notes.

Two modules stay behind in ogclews-link: the old reverse-pass driver, which
wrote into MUIOGO's case storage directly and is replaced by MUIOGO's
applyPatch endpoint, and the environment-accounts module, which nothing uses.

The package keeps its own environment. Nothing is wired into MUIOGO yet.
The steady state now always uses the country calibration's own root method,
which is OG-Core's standard method. Anderson stays where the calibration puts
it: the transition path. This removes the switch that could force Anderson
onto the steady state, which crashed the 8-industry Philippines baseline, and
adds a test so the override cannot come back unnoticed.
Two improvements from EAPD-DRB#537. The linker now reads each CLEWS result table by
its exact name, so a similar table (for example the discounted version of a
cost) can never be read by mistake when the intended one is missing. And if
the industry weights behind the cost-push leg cannot be computed, the run's
record now says so instead of quietly giving a smaller result.

The exact-name reader broke the marginal-price reader, which looked up the
dual file by its short code. It now uses the file's full name, as MUIOGO
writes it; the price series read from the Philippines GOLD runs is unchanged.

Adds EAPD-DRB#537's 16 tests for the price, industry-weight, reader and wedge logic.

Co-authored-by: Aditya Kushwaha <72969747+Adityakushwaha2006@users.noreply.github.com>
The post-run hook and the /oglink/status check now use the linker in this
repository, from its own environment at oglink/.venv, instead of looking for a
separate ogclews-link install. The overrides are now OGLINK_PYTHON and
OGLINK_HOME, matching the linker's own settings.

The linker, in turn, now finds the MUIOGO checkout it lives in, so it sees
MUIOGO's cases and installed OG models without any configuration.
Adds a CI job that installs the linker in its own Python 3.12 environment and
runs its tests. The README explains how to build that environment, how MUIOGO
uses it, and how to run it by hand. uv.lock pins the linker's environment.
MUIOGO shows results with its own chart and table libraries, so the linker no
longer draws figures. It writes the results as data (the macro table, the
results file and the run record) for MUIOGO to display.

This removes the figure deck and what existed only for it: the step that built
it after each run, the --no-figures option, the copy of CLEWS files into each
run folder, and matplotlib. The deck stays in the ogclews-link research
repository. Charting coupled results in MUIOGO comes in a later change.
The linker no longer needs its own environment. Its only extra need, scipy
(for the health channel's age profile), is now a MUIOGO dependency, so every
MUIOGO install can run it with nothing more to set up. scipy 1.17.1 is the
newest release that works with MUIOGO's numpy 1.26.4, and it also works with
numpy 2, so the planned numpy upgrade will not need to change it.

The post-run hook starts the linker as a separate process with MUIOGO's own
Python, from the oglink folder; the web app still never imports it. The
status check now says plainly when the linker cannot run, for example when an
older MUIOGO environment has not been updated with scipy yet. The linker's
separate build file, lockfile and environment settings are removed.
The linker's tests now run in the same job and environment as MUIOGO's own
tests, right after them, instead of in a separate job with its own Python.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant