Repository navigation
Adding Multi-Objective Optimization (MOO) extension - #422
Draft
matteo-nicoli wants to merge 4 commits into
Draft
matteo-nicoli wants to merge 4 commits into
matteo-nicoli wants to merge 4 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…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.
matteo-nicoli
force-pushed
the
feature/moo-extension
branch
from
November 24, 2026 21:09
a1bbe1e to
cfb5520
Compare
This branch has not been deployed
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.
Summary
New
scenario_mode = "MOO"(Multi-Objective Optimization): it traces the Pareto front between two objective functions, as the--moooption of Temoa v3 did, with the augmented epsilon-constraint method (Finke and Bertsch, 2023).f1is minimized whilef2is capped atncapsevenly spaced levels between its lowest value and its value at the lowestf1; a small slack term (c) keeps every point Pareto optimal and not just weakly optimal.Objective functions
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.moo_activity_weight,moo_built_capacity_weight,moo_net_capacity_weight, schema inmulti_objective_optimization/tables.sql). The objective's name is the label used forf1orf2. 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).TableWriterpolls them, with its output thresholds) and the objective values, not the model. Mixed-integer models are supported.<scenario>-<n>, withn = 0the point with the lowestf1;output_objectiveholds the values of all built-in objectives and of the custom objectives used, for every point.save_storage_levels, every point writesoutput_storage_level; withsave_duals, every point writesoutput_dual_variable(MOO used to disablesave_duals). The dual ofmoo_f2_cap, the cap onf2, is the change off1per unit off2at that point (for cost × CO2, the marginal abatement cost), and withf1 = costthe duals of the commodity balances are the commodity prices under that cap. As for any run, duals need a solver that returns them (notappsi_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 setssave_storage_levels = true, so runs configured from it will write storage levels.MOO_solver_options.toml<[solver.options]<solver_optionsof[MOO], withnum_workersof[MOO]over the one of the file.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):
a320c25adds helpers to read solver options and worker counts from the configuration file (solver_spec.py), and3f4a20elets workers send back the results of the models they solve instead of the models (result extractor inworker.py,ResultPollerintable_writer.py,write_uc_resultsaccepting 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.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_workersandsolver_optionsvalidation.test_polled_results.py(shared base): results written from aResultPoller, 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
temoatakes about 10 s to start, onunstabletoo). On Linux, with Python 3.12 and 3.14, it fails only the tests that fail onunstablethere too (those that need a Gurobi licence, and with Python 3.12 fivetemoa tutorialCLI 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.
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:
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):
With nuclear capacity built only in 1.5 GW units (
discrete_capacity), the front becomes non-convex and has a flat stretch:Verification
output_objectivematches the value recomputed from the output tables written by Temoa (output_cost,output_emission,output_flow_out, capacity tables), to 2e-14 relative.f1withf2capped 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.