Skip to content

Adding Multi-Objective Optimization (MOO) extension - #422

Draft
matteo-nicoli wants to merge 4 commits into
TemoaProject:unstablefrom
MAHTEP:feature/moo-extension
Draft

matteo-nicoli wants to merge 4 commits into
TemoaProject:unstablefrom
MAHTEP:feature/moo-extension

Conversation

@matteo-nicoli

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

Copy link
Copy Markdown

Summary

New scenario_mode = "MOO" (Multi-Objective Optimization): it traces the Pareto front between two objective functions, as the --moo option of Temoa v3 did, with the augmented epsilon-constraint method (Finke and Bertsch, 2023). f1 is minimized while f2 is capped at ncaps evenly spaced levels between its lowest value and its value at the lowest f1; a small slack term (c) keeps every point Pareto optimal and not just weakly optimal.

scenario_mode = "MOO"

[MOO]
f1 = "cost"                             # minimized: cost, emission, construction_input or custom
f2 = "emission"                         # capped
ncaps = 11                              # number of Pareto optimal solutions
c = 0.0001                              # slack variable weight
emission_commodities = ["co2"]          # empty = all
construction_input_commodities = []     # empty = all
num_workers = 4                         # parallel solves of the Pareto optimal solutions
solver_options = { threads = 4 }

Objective functions

  • Built-in: cost (total discounted system cost), emission (activity, embodied and end-of-life emissions, and unit commitment start-up emissions, cumulative over the horizon), construction_input (cumulative material use for new capacity). Emission and construction-input commodities can be selected.
  • Custom: any weighted sum of activity, built capacity and net capacity, defined in three optional tables (moo_activity_weight, moo_built_capacity_weight, moo_net_capacity_weight, schema in multi_objective_optimization/tables.sql). The objective's name is the label used for f1 or f2. Weights can be negative (e.g. to maximize a quantity). The tables are only read when a custom name is used.

Changes

  • temoa/extensions/multi_objective_optimization/: sequencer, objectives, custom objectives, MOO_solver_options.toml (fallback worker settings: 4 workers, 4 threads each).
  • The model is built once. The three boundary solves run in the main process; the Pareto points are solved in parallel by the MGA workers, which send back only the results (polled exactly as TableWriter polls them, with its output thresholds) and the objective values, not the model. Mixed-integer models are supported.
  • Each point is written to the standard output tables as <scenario>-<n>, with n = 0 the point with the lowest f1; output_objective holds the values of all built-in objectives and of the custom objectives used, for every point.
  • Storage levels and duals: with save_storage_levels, every point writes output_storage_level; with save_duals, every point writes output_dual_variable (MOO used to disable save_duals). The dual of moo_f2_cap, the cap on f2, is the change of f1 per unit of f2 at that point (for cost × CO2, the marginal abatement cost), and with f1 = cost the duals of the commodity balances are the commodity prices under that cap. As for any run, duals need a solver that returns them (not appsi_highs); solvers return none for mixed-integer models, and MOO then logs a warning for each point. The option is off by default, but the sample config sets save_storage_levels = true, so runs configured from it will write storage levels.
  • Worker options are layered as Temoa defaults < MOO_solver_options.toml < [solver.options] < solver_options of [MOO], with num_workers of [MOO] over the one of the file.
  • Outside its folder the PR only registers the mode (modes.py, config.py, temoa_sequencer.py, pyproject.toml), documents it (moo.rst, README) and adds the [MOO] block to the sample config. Other modes are not changed: MGA gets its config options in the MGA PR, and Monte Carlo and Morris in a separate PR.

Shared base commits. This PR starts with two commits that the MGA PR starts with too (same commits): a320c25 adds helpers to read solver options and worker counts from the configuration file (solver_spec.py), and 3f4a20e lets workers send back the results of the models they solve instead of the models (result extractor in worker.py, ResultPoller in table_writer.py, write_uc_results accepting polled results). The workers of that commit always start as new processes (multiprocessing "spawn"), as on Windows and macOS: forked, as on Linux before Python 3.14, they inherited the solver state of the main process, and the HiGHS solves of MOO failed in every worker. Neither changes any run mode by itself. Whichever of the two PRs is merged first brings them, and the other then shows only its own commits.

  • New docs page moo.rst; MOO listed in the README; the sample config shows the worker options of every mode.

Tests

  • test_moo.py (14 tests): fronts on Utopia and on the materials test database must be monotone; a custom objective mixing activity, built and net capacity is checked against values recomputed from the output tables; 1 and 3 workers give the same front; a front with integer capacity units is solved by the workers; storage levels are written for every point only when asked for; with Gurobi, every point has its duals and the dual of the cap lies between the slopes of the front on either side of the point (skipped without a licensed Gurobi); error cases.
  • test_solver_spec.py (shared base): order of the option layers, num_workers and solver_options validation.
  • test_polled_results.py (shared base): results written from a ResultPoller, storage levels included, are identical to those written from the model; with a licensed Gurobi, so are the duals.

The full test suite passes locally (354 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).

Demonstration on Utopia

All the data added to Utopia (construction materials, custom objectives, life-cycle emissions, integer nuclear units) is synthetic: it exercises the code and shows what can be modeled.

1_moo_front

The cheapest system costs 35,070 M$ and emits 277 Mt of CO2; the cleanest emits 27 Mt for 71,854 M$. The slope of the front is the marginal cost of abatement:

2_moo_mac 3_moo_mix

Custom objectives put any weighted mix of activity and capacity against cost or emissions, without changing the model (fossil power, new capacity, nuclear capacity, maximized hydro output with a negative weight, a land-use mix of capacity and activity, two custom objectives against each other):

4_moo_fronts

With nuclear capacity built only in 1.5 GW units (discrete_capacity), the front becomes non-convex and has a flat stretch:

5_moo_discrete

Verification

  • Values: across 15 pairs of objectives (30 fronts, 350 points), every value in output_objective matches the value recomputed from the output tables written by Temoa (output_cost, output_emission, output_flow_out, capacity tables), to 2e-14 relative.
  • Pareto optimality: two independent solves per point, without the slack term (minimize f1 with f2 capped at the point's value, and the reverse), find gaps of at most 7e-7 of the front's range (solver tolerance); no point is weakly optimal.
  • Consistency: the lowest-cost point matches a perfect-foresight run (cost within 1e-6); every second point of a 21-cap front equals the 11-cap front; the same pair traced in both orders gives one curve.
  • A custom objective reproduces a built-in one: NOx comes only from diesel and gasoline cars at 1 Mt per PJ, so a custom objective on their activity gives exactly the built-in NOx front (and confirms that demand-technology activity is counted once).
6_moo_nox
  • Duals: on the 11-point cost × CO2 front, solved with Gurobi, the dual of the cap at each inner point lies between the slopes of the front to its two neighbours, as it must on a convex front, to within 4e-5 relative (at 177 Mt: −105.0 M$/Mt, between −88.2 and −107.3); both fronts write the storage levels of every point; the integer front writes no duals, and one warning per point.
  • Workers: extracting the results in the workers writes identical rows in every output table (10,213 rows for an 11-point front) and is slightly faster on the median (21.7 s against 22.6 s over five runs each on Utopia, within the run-to-run variation).
  • Errors: unbounded objectives, missing weight tables, unknown names or commodities and invalid options stop with clear messages; built-in MOO on a database without the weight tables runs with no warning.

@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

@matteo-nicoli matteo-nicoli changed the title Feature/moo extension Adding multi-objective optimization extension Nov 24, 2026
@matteo-nicoli matteo-nicoli changed the title Adding multi-objective optimization extension Adding Multi-Objective Optimization (MOO) extension Nov 24, 2026
…file

The solver options of the parallel run modes come from extension options files (MGA_solver_options.toml, MC_solver_options.toml, ...), which override the configuration file, and their number of workers can only be changed inside the installed package. These helpers let a run mode put the configuration file first: resolve_solver_options takes the options file as a fallback layer below the options of the solver entry of the configuration file, and the solver_options of a mode section on top; mode_solver_options and resolve_num_workers read solver_options and num_workers from a mode section, and read_options_file reads an options file, empty if it is missing.

No run mode uses them yet: each one is switched to them in its own commit.
The workers of the parallel run modes send every solved model back to the main process, which then polls its results, one model at a time. On large models each model is pickled twice, and the main process hands out no new work while it polls.

A Worker can now take a result extractor, a function that turns the solved model into what is sent back; without one it sends the model as before. The extractor reaches each worker through a queue after the process starts: inside the pickled process, which can exceed the pipe buffer, it made every start wait for the new process to import Temoa.

ResultPoller polls the results of a model exactly as the table writer does, with its output thresholds: capacities, emissions, costs, flows and unit commitment, and the storage levels and duals when save_storage_levels and save_duals are set. The table writer writes them with write_polled_capacity, write_polled_optional (storage levels and duals) and write_polled_results, and write_uc_results also accepts unit commitment results polled in a worker. The flow balance check is shared as a module function. No run mode uses the extractor yet.

The workers now always start as new processes (multiprocessing "spawn"), with their queues from the same context, as Monte Carlo workers already do. Forked, as on Linux before Python 3.14, they inherited the state of the solvers already run by the main process: HiGHS solves asking for a number of threads then failed in every worker.
New scenario_mode "MOO" explores the Pareto front between two objective functions with the augmented epsilon-constraint method (Finke and Bertsch, 2023, https://doi.org/10.1016/j.apenergy.2022.120521).

Built-in objectives: cost, emission (activity, embodied and end-of-life, optionally restricted to emission_commodities) and construction_input (optionally restricted to construction_input_commodities). Custom objectives are weighted sums of activity, built capacity and net capacity read from the optional moo_activity_weight, moo_built_capacity_weight and moo_net_capacity_weight tables, which are only read when used. Annual flow variables count towards activity only for annual technologies, so the activity of non-annual demand technologies is not counted twice.

The three solves bounding the front run in the main process. The Pareto optimal solutions are then solved in parallel by the MGA workers, with num_workers and solver_options from the [MOO] section of the config, which take precedence over the fallback values of the new MOO_solver_options.toml. The workers send back the results of each solution (ResultPoller, as the TableWriter polls them) and its objective values, not the model; the storage levels are among them when save_storage_levels is set. The sequencer can be reused by other run modes: its options can be passed to the constructor, and a run is split into build_model(), find_caps() and solve_points(). The objective values are held in an expression built without a local function, so that the model can be sent to worker processes.

Outside its folder, the mode is registered (TemoaMode, the [MOO] config section and its dispatch), documented (moo.rst, README) and shown in the sample config.
MOO disabled save_duals. With it set, the dual suffix is now kept on the model of each Pareto optimal solution, and the workers poll its duals with the other results, which are written to output_dual_variable. The dual of moo_f2_cap is the change of f1 per unit of f2 at that solution, and with f1 = cost the duals of the commodity balances are the commodity prices under the cap.

Duals need a solver that returns them, as for any run. Solvers return none for mixed-integer models: the solutions are then written without them, and the run logs a warning for each.

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