Skip to content

Adding capacity and emission axes options for MGA solution space - #423

Draft
matteo-nicoli wants to merge 2 commits into
TemoaProject:unstablefrom
MAHTEP:feature/mga-category-axes
Draft

matteo-nicoli wants to merge 2 commits into
TemoaProject:unstablefrom
MAHTEP:feature/mga-category-axes

Conversation

@matteo-nicoli

@matteo-nicoli matteo-nicoli commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

MGA hull expansion could only diversify the activity of technology categories: the other documented axes were placeholders. This PR fixes the activity axis and adds capacity and emission axes, so the modeler can choose what to diversify. Two commits:

  1. Double counting on the activity axis. Non-annual demand technologies have both time-sliced and annual flow variables for the same activity, and the activity manager collected both, so their activity was counted twice in the hull and in the objectives. Annual flow variables are now collected only for annual technologies, and category activity matches output_flow_out.
  2. Capacity and emission axes. One vector manager per axis, selected by the manager factory, following the MGA development guide:
axis Value of a category (summed over regions and periods)
tech_category_activity (default) output flows of its technologies
tech_category_capacity (new) net available capacity of its technologies
tech_category_emission (new) activity-related emissions of the commodities in axis_emission_commodities
[MGA]
axis = "tech_category_emission"
axis_emission_commodities = ["co2"]   # required for tech_category_emission

Changes

  • New TechCapacityVectorManager and TechEmissionVectorManager, thin subclasses of the activity manager that only change which variables make up a category's value and, for emissions, their weights (the emission rates). The placeholder axes TECH_CAPACITY and EMISSION_ACTIVITY are removed.
  • Only named categories are explored. Technologies without a category no longer form a catch-all DEFAULT dimension: it summed dummy imports, transfers and pass-throughs, which pushes the exploration towards differences nobody asked for, and on the capacity axis any direction pushing their free capacity up is unbounded. They are still mapped and written for every solution, and the run logs how many are left out.
  • Categories without variables for the chosen axis are left out with a warning; at least two must remain, otherwise the run stops with a clear error. Unknown emission commodities stop the run.
  • mga.rst gains a section on categories and axes (which technologies need a category, and which are best left without one); the MGA README, design notes and sample config are updated.

This PR changes some of the same lines of tech_activity_vector_manager.py as the MGA PR: whichever of the two is merged later needs a small conflict resolution.

On a fully categorized model, the activity axis behaves as after commit 1. Without the search-direction fix of the MGA PR, the new axes work, but the emission axis does not reliably cover its own space (see below): the two PRs are best used together.

Tests

test_mga_axes.py: category activity against output_flow_out (fails without commit 1); capacity and emission values against the model results and output_emission; error cases (missing or unknown emission commodity, too few categories); uncategorized technologies left out of the activity and capacity axes; full MGA runs on the capacity and emission axes.

The full test suite passes locally (338 tests, with gurobipy 13 to match the local licence; the 3 CLI smoke tests time out on this machine, where temoa takes about 10 s to start, on unstable too). On Linux, with Python 3.12 and 3.14, it fails only the tests that fail on unstable there too (those that need a Gurobi licence, and with Python 3.12 five temoa tutorial CLI tests).

Sanity checks on Utopia

These checks were run on main (a96d46e), before the branch was moved onto unstable; the MGA code they exercise is the same on both.

The new axes are correct

MGA's initial solves minimize and maximize each category. Each result was compared with an independent optimization, written directly from the model's variables rather than through the vector manager:

1_axes_minmax
Axis Categories Max relative gap to independent min/max Hull-expansion solves (failed) Max cost / base
Activity 5 1.9e-15 25 (0) 1.03
Capacity 5 1.6e-15 25 (0) 1.03
Emission, ["co2"] 2 (petroleum, coal) 1.5e-15 25 (0) 1.03
Emission, ["co2", "nox"] 2 (petroleum, coal) 8.0e-16 25 (0) 1.03

What each axis explores

Three case studies built from Utopia by recategorizing its technologies (transport: diesel, gasoline and electric vehicles; power chains: each plant with its fuel import; transport with synthetic vintage-dependent NOx factors). Each axis was run 3 times at 3% and 10% cost slack, 100 hull-expansion solves each, and every solution was measured in the capacity, activity and emission spaces. The share is the volume of the hull of an axis's solutions over the hull of all solutions found by all axes.

2_explore_heatmap_transport 3_explore_grid_transport 4_explore_heatmap_power
  • The capacity axis covers the capacity space far better than the others: they reach at most 42% of the volume it finds in the transport case. It finds over-built vehicle fleets that the activity and emission axes never visit.
  • Activity and emission axes are interchangeable when emissions follow activity (in the transport case NOx is exactly proportional to vehicle output). With vintage-dependent emission factors, the emission axis gains a clear lead in its own space.
  • With the search-direction fix of the MGA PR, each axis covers 96–100% of the joint hull in its own space, the best of the three or within 1% of it. Without that fix, the emission axis reaches only 80–84% of its own space in the power-chain case (the heatmaps above are without it): in a two-dimensional space, the solves that go the wrong way never push some edges out.
  • Leaving uncategorized technologies out helps, with the fix: in the power-chain case the activity axis covers 11 points more of its own space, and the capacity axis 4–6 points more, than with the former DEFAULT dimension.

No solve failed in any run, every solution stayed within its cost relaxation, and emission values matched output_emission to 7e-15.

Non-annual demand technologies have both time-sliced and annual output flow variables for the same activity. The activity vector manager mapped both, so their activity was counted twice in the category values (the hull points) and in the objective of every MGA solve.

Map annual flow variables only for annual technologies. Add a test that checks the activity of each category against the output flows written for the solved model.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

MGA hull expansion could only diversify the activity of technology categories; the other documented axes were placeholders. Following the MGA development guide, add one vector manager per axis, each selected by the manager factory:

- TECH_CATEGORY_ACTIVITY (default): TechActivityVectorManager, output flows
- TECH_CATEGORY_CAPACITY: TechCapacityVectorManager, net available capacity
- TECH_CATEGORY_EMISSION: TechEmissionVectorManager, activity-related emissions of the commodities listed in the new `axis_emission_commodities` option

The capacity and emission managers subclass the activity manager and only change which variables make up a category's value. The placeholder TECH_CAPACITY and EMISSION_ACTIVITY axes are removed. Categories with no variables for the axis are excluded, and at least two categories are required to build the hull.

Technologies without a category are left out of every axis. Grouping them into an extra DEFAULT dimension mixed unrelated quantities, typically dummy, transfer and pass-through technologies whose capacity carries no cost, so on the capacity axis any direction that increased their capacity was unbounded. They still take whatever values the solver finds, but MGA does not push them. The number left out is logged, and the documentation says which technologies need a category.

The sample config lists the three axes and the axis_emission_commodities option, with aligned comments in the [MGA] section.
@matteo-nicoli
matteo-nicoli force-pushed the feature/mga-category-axes branch from 0651bf4 to 3f86a44 Compare November 24, 2026 21:09

This branch has not been deployed

No deployments
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