Architecture overview¶
equilibria is a Python framework for Computable General Equilibrium (CGE)
modeling whose defining constraint is parity with reference GAMS models:
every template is validated cell-by-cell against the original GAMS
implementation before it is considered done.
The pipeline¶
Data I/O (
equilibria.babel,equilibria.sam_tools) reads and balances the input data: SAM matrices, GEMPACK HAR files (native pure-Python reader and writer), GAMS GDX containers, and raw MIP/IO tables (MIP → SAM, HAR I/O).Calibration (
equilibria.calibration,equilibria.core, plus per-template calibration modules) fits the model’s parameters so the benchmark equilibrium reproduces the SAM exactly.Templates (
equilibria.templates) are complete model implementations — sets, parameters, equations, closure — assembled on the core (equilibria.core,equilibria.backendsfor Pyomo) and the generic building blocks inequilibria.blocks(production, trade, demand, institutions, equilibrium).Solvers: the same model solves as an MCP (complementarity, PATH via the C API — Solving with PATH via the C API) or as an NLP (IPOPT), mirroring GAMS’s
ifMCPswitch. Solver support utilities live inequilibria.solver; the PATH/IPOPT drivers ship with each template.Validation compares every solved cell against a reference GAMS solution (Benchmarks, GTAP 7 Parity Coverage Matrix, PEP-1-1 Parity Coverage Matrix).
The parity philosophy¶
GAMS is the source of truth. A divergent cell is a bug (in the model, the calibration, or the reference itself) until proven otherwise — cells are never excluded to inflate a match number.
Same-engine comparisons. Parity is measured NLP-vs-NLP (IPOPT both sides) and MCP-vs-MCP (PATH both sides), so the solver’s equality tolerance cancels and the match% reflects model fidelity, not solver noise.
Gates, not snapshots. Coverage lives in one declarative matrix per model (
scripts/gtap/coverage_matrix.py,scripts/pep/pep_coverage_matrix.py). Pytest gates re-measure the match and assert conservative floors; CI keeps the rendered docs in sync with the matrix source.A solver-free structural canary. The
.nlcoefficient gate diffs Python-vs-GAMS Jacobian coefficients on every push — no solver needed, so it runs in CI and catches equation/parameter regressions in seconds.
Package map¶
Package |
Responsibility |
|---|---|
|
SAM audit, balancing, MIP → SAM transforms |
|
File formats: HAR reader/writer, GDX reader, SAM loaders |
|
Model assembly core: sets, parameters, variables, equations, calibration phases |
|
Public model API and bundled datasets ( |
|
Generic equation blocks: production, trade, demand, institutions, equilibrium |
|
Generic calibration utilities (CES, Leontief) |
|
Pyomo backend (model construction) |
|
Solver support: guards, Jacobian tooling, transforms |
|
GTAP Standard 7 (multi-period, MCP + NLP, 6 datasets) |
|
PEP-1-1 v2.1 ported to Pyomo (NLP + MCP) |
|
Didactic open-economy model |
|
Scenario runtime, adapters, multi-model wrappers |
|
Validation contracts and SAM/QA checks |
See the templates overview for per-template status and the API reference for the generated reference.