Explore near-optimal designs with ORACLE¶
The cost-optimal solution of an energy system model is only one answer. Models simplify reality, costs are uncertain, and decision-makers care about things a model does not capture: public acceptance, land use, security of supply, and so on. Often, many very different energy systems cost only a few percent more than the optimum. Together they form the near-optimal space:
$$ \mathcal{Z}_\varepsilon = \left\{\, z \;\middle|\; \exists\, x \text{ feasible with design } z,\; \text{cost}(x) \le (1+\varepsilon)\, C^* \,\right\} $$
where $x$ is a complete energy system (all the variables of the model), $z$ the design decisions you care about (e.g. the installed capacities of wind, PV, nuclear and gas power plants), $C^*$ the optimal cost, and $\varepsilon$ the cost slack you accept (e.g. 5 %).
Modelling to Generate Alternatives (MGA) methods find alternatives in this space, but they cannot tell you how much of it they have missed. ORACLE (Optimization for the Rigorous Analysis of the Complete Landscape of alternatives in Energy systems), a method developed by Evren M. Turan, Stefano Moret and André Bardow at ETH Zurich [1], solves this problem. It sandwiches the near-optimal space between an inner and an outer approximation and measures the gap between the two. Once the gap is small, you have mapped all near-optimal designs, with a known accuracy.
ORACLE is a general method; this tutorial shows one possible application of it. ORACLE works with any energy system model that is a linear (more generally, convex) optimisation problem, whatever the modelling framework. The authors demonstrate it on an hourly EnergyScope model of Switzerland with typical days [1]. Here we apply it to a simpler, monthly EnergyScope model of Switzerland shipped with this library, with the implementation in
energyscope.oracle, which is adapted from the authors' reference code [2].The method, its metric and its guarantees are the work of Turan, Moret and Bardow. If you use ORACLE, please cite their paper [1] (see How to cite at the end of this tutorial).
[1] E. M. Turan, S. Moret, A. Bardow. ORACLE: A rigorous metric and method to explore all near-optimal designs for energy systems. Computers & Chemical Engineering 210 (2026) 109630. doi:10.1016/j.compchemeng.2026.109630 ⧉ (open access; preprint: arXiv:2509.26452 ⧉).
[2] Reference implementation of ORACLE, ETH Zurich (MIT license): gitlab.ethz.ch/epse/systems-design-public/oracle-metric-and-method ⧉.
In this tutorial
- How ORACLE works, step by step, on a toy model with two design variables, where everything can be drawn. It uses Pyomo and the open-source HiGHS solver: no license needed.
- One application, plug and play: the EnergyScope model of Switzerland in 2050, solved with AMPL and Gurobi. This needs an AMPL license that includes Gurobi (free for academics, see Getting started). Without one, a one-line change runs the same steps with Pyomo and the open-source HiGHS solver (see the note just before the first code cell of part 2).
- How to use the result: ranges, trade-offs, sampling alternatives, and rebuilding a full energy system from a chosen design.
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import plotly.io as pio
import pyomo.environ as pyo
from scipy.spatial import ConvexHull
from energyscope.oracle import Oracle, PyomoProblem, polytope_vertices
pio.renderers.default = 'notebook_connected' # figures load plotly.js from the web: keeps the notebook light
1. How ORACLE works, on a toy model¶
A small country splits its year into two halves, day and night:
| day | night | |
|---|---|---|
| Average electricity demand [GW] | 8 | 5 |
| PV capacity factor | 0.40 | 0 |
| Wind capacity factor | 0.25 | 0.35 |
It decides how much PV and wind capacity to build (0 to 30 GW each): these two capacities are the design variables we want to explore. A gas power plant covers whatever is missing. Annualised costs, in arbitrary money units: PV 1.0 and wind 1.5 per GW installed; the gas plant 1.0 per GW installed plus 6 per GW of average production (fuel).
This is a linear program (LP), hence convex, which is what ORACLE needs: convexity is what makes its approximations provably valid. To connect a model, ORACLE needs:
design: the variables that span the space to explore, here the capacitiesF['PV']andF['WIND'](their bounds are read from the model);cost: the total cost that defines what "near-optimal" means;cost_coefficients(optional): a cheap under-estimate of the cost as a function of the design. Here it is the investment in PV and wind: whatever else happens, the system costs at least $1.0\,F_{PV} + 1.5\,F_{WIND}$.
def toy_model():
m = pyo.ConcreteModel()
m.TECH = pyo.Set(initialize=['PV', 'WIND'])
m.HALF = pyo.Set(initialize=['day', 'night'])
demand = {'day': 8.0, 'night': 5.0} # GW
cf = {('PV', 'day'): 0.40, ('PV', 'night'): 0.0, ('WIND', 'day'): 0.25, ('WIND', 'night'): 0.35}
capex = {'PV': 1.0, 'WIND': 1.5} # per GW installed
m.F = pyo.Var(m.TECH, bounds=(0, 30)) # PV and wind capacity [GW]: the design
m.GAS = pyo.Var(bounds=(0, None)) # gas plant capacity [GW]
m.gas_use = pyo.Var(m.HALF, bounds=(0, None)) # gas plant production [GW]
m.balance = pyo.Constraint(m.HALF, rule=lambda m, h:
sum(cf[t, h] * m.F[t] for t in m.TECH) + m.gas_use[h] >= demand[h])
m.gas_capacity = pyo.Constraint(m.HALF, rule=lambda m, h: m.gas_use[h] <= m.GAS)
m.TotalCost = pyo.Expression(expr=sum(capex[t] * m.F[t] for t in m.TECH) + 1.0 * m.GAS
+ sum(0.5 * 6.0 * m.gas_use[h] for h in m.HALF)) # day and night: half a year each
return m
problem = PyomoProblem(toy_model(), design='F', cost='TotalCost', cost_coefficients=[1.0, 1.5])
To check ORACLE against the truth, we first compute the exact near-optimal space by brute force, which is only possible in two dimensions: solve the cost optimum $C^*$, impose the budget $\text{cost} \le (1+\varepsilon)\,C^*$ with $\varepsilon = 10\,\%$, and push the design as far as possible in 360 directions (one LP each). ORACLE avoids exactly this brute force, which is impossible with more dimensions.
The helper draw (you can skip reading it) draws the true near-optimal space (black outline), ORACLE's outer approximation (light blue) and inner approximation (dark blue), both explained below, and the cost optimum (red star).
EPS = 0.10 # accept designs that cost at most 10 % more than the optimum
optimal_cost, optimal_design = problem.solve_optimum()
problem.set_budget((1 + EPS) * optimal_cost)
print(f'Optimal cost: {optimal_cost:.2f} -> budget with eps = {EPS:.0%}: {(1 + EPS) * optimal_cost:.2f}')
print(f'Cost-optimal design: PV = {optimal_design[0]:.2f} GW, wind = {optimal_design[1]:.2f} GW')
true_points = np.array([problem.extreme(np.array([np.cos(a), np.sin(a)]))
for a in np.linspace(0, 2 * np.pi, 360, endpoint=False)])
def outline(points):
# Closed outline of a convex 2-D point set (its convex hull).
points = np.unique(np.round(np.atleast_2d(points), 9), axis=0)
if len(points) < 3:
return points
loop = points[ConvexHull(points).vertices]
return np.vstack([loop, loop[:1]])
def draw(oracle, title, trial=None, found=None):
fig = go.Figure()
areas = [(polytope_vertices(oracle.A, oracle.b), 'Outer approximation O',
dict(fill='toself', fillcolor='rgba(158,202,225,0.35)', line=dict(color='#6baed6', dash='dash'))),
(true_points, 'True near-optimal space', dict(mode='lines', line=dict(color='black', width=2))),
(oracle.inner_points, 'Inner approximation I',
dict(fill='toself', fillcolor='rgba(8,81,156,0.45)', line=dict(color='#08519c')))]
for points, name, style in areas:
loop = outline(points)
fig.add_trace(go.Scatter(x=loop[:, 0], y=loop[:, 1], name=name, **style))
points = [(oracle.optimum, 'Cost optimum', dict(symbol='star', size=14, color='#d62728')),
(trial, 'Trial point', dict(symbol='x', size=12, color='#ff7f0e')),
(found, 'Closest near-optimal design', dict(size=10, color='#2ca02c'))]
for point, name, marker in points:
if point is not None:
fig.add_trace(go.Scatter(x=[point[0]], y=[point[1]], mode='markers', marker=marker, name=name))
fig.update_layout(template='plotly_white', title=title, height=520, legend=dict(orientation='h', y=-0.15),
xaxis=dict(title='PV capacity [GW]', range=[-1, 31]),
yaxis=dict(title='Wind capacity [GW]', range=[-1, 31]))
return fig
Optimal cost: 32.50 -> budget with eps = 10%: 35.75 Cost-optimal design: PV = 11.07 GW, wind = 14.29 GW
The cost optimum is fully renewable (about 11 GW of PV and 14 GW of wind, no gas), but for only 10 % more, very different designs are possible: much less PV and more wind, or fewer renewables backed up by gas. You will see the true space in the figures below. Now let us pretend we do not know it, and let ORACLE find it.
The idea¶
Following Turan, Moret and Bardow [1], ORACLE maintains two approximations of the unknown near-optimal space $\mathcal{Z}_\varepsilon$:
- the inner approximation $I$: the convex hull of the near-optimal designs found so far. Because $\mathcal{Z}_\varepsilon$ is convex, every point of $I$ is a guaranteed near-optimal design;
- the outer approximation $O$: a polytope made of halfspaces ("cuts") that are guaranteed to contain all near-optimal designs.
The truth is always sandwiched, $I \subseteq \mathcal{Z}_\varepsilon \subseteq O$, and ORACLE measures the gap with its metric, the largest distance from a point of $O$ to $I$:
$$ d = \max_{z \in O}\; \min_{y \in I}\; \lVert z - y \rVert_\infty $$
$d$ is the largest error you can make by using $I$ (or $O$) instead of the true near-optimal space, in the units of the design variables (GW here; the $\infty$-norm is the largest deviation of any single technology). This metric is the key contribution of the paper [1]. As in the paper, ORACLE proceeds in steps:
- Step 1, initialise: $I$ is the cost optimum, and $O$ the box of the variable bounds cut by the investment budget, $1.0\,F_{PV} + 1.5\,F_{WIND} \le (1+\varepsilon)\,C^*$.
Then it repeats steps 2 to 4 until $d$ is below a tolerance:
- Step 2, measure the gap: compute $d$ and the point of $O$ that reaches it, the trial point, where the two approximations disagree most. (The paper [1] computes it by solving a bilevel problem, reformulated as a mixed-integer linear program. This implementation does the same above 6 dimensions; in up to 6 dimensions it simply checks the vertices of $O$, where the maximum lies.)
- Step 3, explore: solve one LP on the full model for the near-optimal design closest to the trial point. Its dual variables $\mu$ tell how this distance changes when the trial point moves.
- Step 4, refine: add the design found to $I$, and cut the trial point off $O$ with the hyperplane $\mu^\top z \le \mu^\top z_\text{found}$. This cut is valid, it never removes a near-optimal design: the distance to $\mathcal{Z}_\varepsilon$ is a convex function of the trial point, $\mu$ is its slope, and it is zero on $\mathcal{Z}_\varepsilon$. A second LP (the cheapest system with the design found) gives a second, cost cut.
Let us run the first iteration by hand, with a tolerance of 0.05 GW.
oracle = Oracle(problem, eps=EPS, tol=0.05)
oracle.initialise() # step 1: initialise
trial = oracle.furthest_point() # step 2: measure the gap
explored = oracle.nearest_point(trial.point) # step 3: explore
print(f'ORACLE metric d = {trial.distance:.2f} GW, reached at the trial point {trial.point.round(2)}')
print(f'Closest near-optimal design: {explored.point.round(2)}, at {explored.distance:.2f} GW from the trial point')
print(f'Dual variables mu: {explored.normal.round(3) + 0.0}')
draw(oracle, 'Steps 2-3: trial point and closest design', trial.point, explored.point).show()
ORACLE: 2 dimensions, optimal cost 32.5, budget 35.75 (eps = 10.00%), tolerance 0.05
ORACLE metric d = 18.93 GW, reached at the trial point [30. 3.83] Closest near-optimal design: [14.94 8.1 ], at 15.06 GW from the trial point Dual variables mu: [1. 0.]
oracle.refine(trial.point, explored) # step 4: refine (I grows, O gets two cuts)
draw(oracle, 'Step 4: refined approximations', trial.point).show()
oracle.result.outer.tail(2) # the two new cuts: sum(coefficient * z) <= rhs
| PV | WIND | rhs | kind | |
|---|---|---|---|---|
| 5 | 1.0 | -0.0 | 14.940476 | cut |
| 6 | -0.0 | -1.0 | -8.095238 | cost cut |
The trial point is now outside $O$, and $I$ has grown from a point to a segment. Here $\mu = (1, 0)$, so the cut is $F_{PV} \le 14.94$ GW: no near-optimal design has more PV than the design found. The cost cut adds $F_{WIND} \ge 8.10$ GW. Both are new edges of $O$ in the figure.
oracle.step() runs one such iteration, and oracle.run() iterates until the metric is below the tolerance (its counter does not include the iteration done by hand). Each line of its log is one iteration: the metric $d$ ("distance"), how far the trial point was from the near-optimal space (0 means that it is near-optimal, so no cut is needed), and which cuts were added. All distances are in GW:
toy_result = oracle.run(max_iter=50)
draw(oracle, f'Converged after {len(toy_result.history)} iterations: d = {toy_result.distance:.3f} GW').show()
iteration 1: distance 11.07 | trial point is 5.911 away from the near-optimal space | cut + cost_cut
iteration 2: distance 9.626 | trial point is 7.424 away from the near-optimal space | cut + cost_cut
iteration 3: distance 2.222 | trial point is 0.5253 away from the near-optimal space | cut + cost_cut
iteration 4: distance 1.591 | trial point is 0 away from the near-optimal space | no cut (trial point is near-optimal)
iteration 5: distance 1.429 | trial point is 0.8497 away from the near-optimal space | cut + cost_cut
iteration 6: distance 0.6272 | trial point is 0 away from the near-optimal space | no cut (trial point is near-optimal)
iteration 7: distance 0.4727 | trial point is 0 away from the near-optimal space | no cut (trial point is near-optimal)
iteration 8: distance 0.2652 | trial point is 0 away from the near-optimal space | no cut (trial point is near-optimal) iteration 9: distance 0 <= tolerance 0.05: converged
The inner and outer approximations now coincide with the true near-optimal space, and ORACLE knows it: the metric certifies that no near-optimal design is further than tol from the inner approximation.
Key ideas
- Inner approximation: convex hull of the designs found. Everything inside is guaranteed near-optimal.
- Outer approximation: intersection of valid cuts. Nothing outside is near-optimal.
- ORACLE metric: the largest distance between the two. It bounds the error, says when to stop, and points to where to explore next.
2. One application: EnergyScope Switzerland 2050, plug and play¶
ORACLE is not tied to a particular model. As one possible application, and as in the paper [1] but with a simpler monthly model, we now run it in a few lines on the EnergyScope model of Switzerland in 2050 shipped with the library (infrastructure_ch_2050: monthly resolution, net-zero CO$_2$ emissions, about 14 000 variables and 17 000 constraints), solved with AMPL and Gurobi.
AmplProblem.from_energyscope(es, technologies=[...]) connects an Energyscope object to ORACLE:
- the design variables are the installed capacities
F_Multof the technologies you list, between their boundsf_minandf_maxfrom the data; - the cost under-estimator is the annualised investment cost $\tau \cdot c_{inv}$ of each technology ($c_{inv}$: investment cost per GW; $\tau$: annuity factor that turns it into a yearly cost);
- the model's integer variables (e.g. the charging or discharging mode of storage) are relaxed to continuous variables, because ORACLE needs a convex model, and a warning tells you so. The near-optimal space explored is that of this linear relaxation.
We explore four electricity technologies, rooftop PV (PV_LV, connected to the low-voltage grid), wind, nuclear and gas combined-cycle plants (CCGT); we accept 5 % of extra cost and ask for an accuracy of 0.1 GW. The cell below is self-contained: you can copy it into your own script.
AMPL license. If AMPL and Gurobi are not installed and activated yet, pass your license to
Energyscope, as in Getting started:Energyscope(model=infrastructure_ch_2050, license_uuid='<your license UUID>', modules=['gurobi']).No AMPL or Gurobi license? Replace the
swiss = ...line withswiss = PyomoProblem.from_energyscope( technologies=['PV', 'WIND', 'NUCLEAR', 'CCGT'])It explores
pyomo_ch, a monthly Pyomo model of Switzerland solved with the open-source HiGHS solver (about 20 s). It is a different scenario, without CO$_2$ limit and with other data (e.g. a single PV technology,PV, and at most 5.3 GW of wind). Its cost optimum builds 3.7 GW of nuclear and none of the three others, so the comments below, which describe the AMPL model, do not apply to it.
import warnings
from energyscope.energyscope import Energyscope
from energyscope.models import infrastructure_ch_2050
from energyscope.oracle import AmplProblem, Oracle, PyomoProblem
es = Energyscope(model=infrastructure_ch_2050) # AMPL, with Gurobi (the default solver)
with warnings.catch_warnings(record=True) as caught: # print ORACLE's warnings as plain lines
warnings.simplefilter('always')
swiss = AmplProblem.from_energyscope(es, technologies=['PV_LV', 'WIND', 'NUCLEAR', 'CCGT'])
for warning in caught:
print('Warning:', warning.message)
swiss_oracle = Oracle(swiss, eps=0.05, tol=0.1)
swiss_result = swiss_oracle.run(max_iter=100)
Warning: ORACLE needs a convex model: 445 integer/binary variables are relaxed to continuous variables in ORACLE's solves. ORACLE: 4 dimensions, optimal cost 9229.74, budget 9691.23 (eps = 5.00%), tolerance 0.1
iteration 1: distance 51 | trial point is 42.69 away from the near-optimal space | cut + cost_cut
iteration 2: distance 20 | trial point is 12.63 away from the near-optimal space | cut + cost_cut
iteration 3: distance 7.576 | trial point is 1.006 away from the near-optimal space | cut + cost_cut
iteration 4: distance 6.386 | trial point is 4.034 away from the near-optimal space | cut + cost_cut
iteration 5: distance 2.508 | trial point is 1.935 away from the near-optimal space | cut + cost_cut
iteration 6: distance 2.132 | trial point is 2.018 away from the near-optimal space | cut + cost_cut
iteration 7: distance 1.421 | trial point is 1.117 away from the near-optimal space | cut + cost_cut
iteration 8: distance 1.309 | trial point is 1.028 away from the near-optimal space | cut + cost_cut
iteration 9: distance 1.131 | trial point is 0.3909 away from the near-optimal space | cut + cost_cut
iteration 10: distance 1.129 | trial point is 0.3493 away from the near-optimal space | cut + cost_cut
iteration 11: distance 0.9113 | trial point is 0.1259 away from the near-optimal space | cut + cost_cut
iteration 12: distance 0.8149 | trial point is 0.7485 away from the near-optimal space | cut + cost_cut
iteration 13: distance 0.5966 | trial point is 0.5898 away from the near-optimal space | cut + cost_cut
iteration 14: distance 0.5761 | trial point is 5.79e-05 away from the near-optimal space | cut + cost_cut
iteration 15: distance 0.499 | trial point is 0.2473 away from the near-optimal space | cut + cost_cut
iteration 16: distance 0.2731 | trial point is 0.2128 away from the near-optimal space | cut + cost_cut
iteration 17: distance 0.2699 | trial point is 0.1132 away from the near-optimal space | cut + cost_cut
iteration 18: distance 0.2552 | trial point is 0.07074 away from the near-optimal space | cut + cost_cut
iteration 19: distance 0.2297 | trial point is 0.1169 away from the near-optimal space | cut + cost_cut
iteration 20: distance 0.2144 | trial point is 0.1483 away from the near-optimal space | cut + cost_cut
iteration 21: distance 0.2035 | trial point is 0.196 away from the near-optimal space | cut + cost_cut
iteration 22: distance 0.1722 | trial point is 0.158 away from the near-optimal space | cut + cost_cut
iteration 23: distance 0.149 | trial point is 0.06854 away from the near-optimal space | cut + cost_cut
iteration 24: distance 0.1261 | trial point is 0.0617 away from the near-optimal space | cut + cost_cut
iteration 25: distance 0.1198 | trial point is 0.08968 away from the near-optimal space | cut + cost_cut
iteration 26: distance 0.1116 | trial point is 0.09558 away from the near-optimal space | cut + cost_cut
iteration 27: distance 0.1017 | trial point is 0.003171 away from the near-optimal space | cut + cost_cut iteration 28: distance 0.09889 <= tolerance 0.1: converged
ORACLE converged: the last line of the log shows that the metric fell below the tolerance.
Solver accuracy matters.
infrastructure_ch_2050is badly scaled (its coefficients range from $10^{-7}$ to $10^{7}$), so an LP solver can return a slightly non-optimal solution and still report it as optimal.AmplProblemtherefore asks Gurobi for its dual simplex method with a tight optimality tolerance; CPLEX and HiGHS through AMPL solve the model itself, but fail on ORACLE's problems for it (CPLEX stops with a numerical error, HiGHS does not finish). If ORACLE warns that a cut "would remove known near-optimal designs", the solver's answers are inaccurate.pyomo_chis much better scaled, and HiGHS solves it accurately.
How much can each technology vary?¶
ranges() gives, for each technology, the range covered by the inner approximation (guaranteed near-optimal) and by the outer approximation (possibly near-optimal). The true near-optimal range is in between.
swiss_result.ranges().round(2)
| optimum | inner_min | inner_max | outer_min | outer_max | |
|---|---|---|---|---|---|
| dimension | |||||
| PV_LV | 0.0 | 0.00 | 8.31 | 0.00 | 8.31 |
| WIND | 20.0 | 12.63 | 20.00 | 12.63 | 20.00 |
| NUCLEAR | 0.0 | 0.00 | 2.35 | 0.00 | 2.35 |
| CCGT | 0.0 | 0.00 | 6.57 | 0.00 | 6.57 |
swiss_result.plot_ranges().show()
Within 5 % of the optimal cost:
- The cost optimum builds wind up to its full potential (20 GW, its upper bound
f_max) and none of the three other technologies. - Wind can nevertheless drop to 12.6 GW.
- Rooftop PV, nuclear and CCGT, absent from the optimum, can reach 8.3 GW, 2.4 GW and 6.6 GW respectively.
The inner and outer ranges agree within the tolerance, as they must once ORACLE has converged. The converse is not true: matching ranges only show that the bounding box of the near-optimal space is found, which can happen long before the whole space is mapped. Only the ORACLE metric (the last line of the log, or swiss_result.converged) certifies that.
Trade-offs between technologies¶
Ranges hide the interactions between technologies: a value that is near-optimal on its own may only be near-optimal in combination with specific values of the others. Two-dimensional projections of the near-optimal space show these trade-offs:
swiss_result.plot_projection('WIND', 'CCGT').show()
The projection is almost a triangle. The full 6.6 GW of CCGT are near-optimal only when wind is fully built (20 GW), and no CCGT at all fits when wind is at its minimum (12.6 GW): giving up wind and building gas plants use up the same 5 % budget, so you can do one, the other, or a bit of both. This picture is the "shadow" of the 4-dimensional near-optimal space: a point inside it is near-optimal for some values of the two other technologies, not for all of them.
3. Use the near-optimal space¶
Once ORACLE has converged, the near-optimal space is known, and using it needs no further model solve:
swiss_result.contains(design, 'inner')tells whether a design is guaranteed near-optimal; outside the outer approximation ('outer'), it is certainly not near-optimal;swiss_result.sample(n)draws designs approximately uniformly from the inner approximation (with a hit-and-run random walk): thousands of guaranteed near-optimal alternatives, for free.
swiss_oracle.design(z) then solves the full model with the capacities $z$ pinned, at minimum cost, and returns a regular EnergyScope Result, so all the usual post-processing and plotting functions work on it.
Let us first check a design that the ranges alone would accept: the least wind together with the most CCGT. Then we draw 1000 alternatives, pick the one with the least wind, and rebuild its full energy system.
# Ranges hide interactions: the least wind and the most CCGT are each near-optimal, but not together
ranges = swiss_result.ranges()
both = swiss_result.optimum.copy()
both['WIND'], both['CCGT'] = ranges.loc['WIND', 'inner_min'], ranges.loc['CCGT', 'inner_max']
print('Least wind and most CCGT possibly near-optimal:', swiss_result.contains(both, 'outer'))
print(f'Distance to the inner approximation: {swiss_result.distance_to_inner(both):.2f} GW')
samples = swiss_result.sample(1000, seed=42)
low_wind = samples.loc[samples['WIND'].idxmin()]
print('Design with the least wind [GW]:', low_wind.round(2).to_dict())
alternative = swiss_oracle.design(low_wind)
optimum = swiss_oracle.design(swiss_result.optimum)
cost = alternative.variables['TotalCost']['TotalCost'].iloc[0]
print(f'Total cost: {cost:.0f} MCHF/year vs. {swiss_result.optimal_cost:.0f} MCHF/year at the optimum '
f'(+{cost / swiss_result.optimal_cost - 1:.1%}, budget +{swiss_result.eps:.0%})')
Least wind and most CCGT possibly near-optimal: False Distance to the inner approximation: 3.47 GW
Design with the least wind [GW]: {'PV_LV': 0.36, 'WIND': 13.46, 'NUCLEAR': 0.01, 'CCGT': 0.37}
Total cost: 9678 MCHF/year vs. 9230 MCHF/year at the optimum (+4.9%, budget +5%)
def electricity_production(result):
# Annual electricity produced (+) or consumed (-) by each technology [TWh/year], all voltage levels together
production = result.variables['Annual_Prod']['Annual_Prod'] # GWh/year of each technology's main output
layers = result.parameters['layers_in_out']['layers_in_out'].unstack()
to_electricity = layers.filter(like='ELECTRICITY').sum(axis=1)
return production.mul(to_electricity.reindex(production.index).fillna(0)) / 1000
electricity = pd.DataFrame({'Cost optimum': electricity_production(optimum),
'Least-wind alternative': electricity_production(alternative)})
producers = electricity[(electricity > 0.05).any(axis=1)].round(2)
fig = px.bar(producers, barmode='group', title='Annual electricity production [TWh/year]',
labels={'index': 'Technology', 'value': 'TWh/year', 'variable': ''})
fig.update_layout(template='plotly_white', legend=dict(orientation='h', yanchor='bottom', y=1.02))
fig.show()
change = (producers['Least-wind alternative'] - producers['Cost optimum']).round(1)
print('Change in production [TWh/year]:', change[change.abs() >= 0.1].sort_values().to_dict())
used = -electricity.clip(upper=0).sum() # electricity used by heat pumps, electric mobility, industry...
print(f"Electricity used by the rest of the system: {used['Cost optimum']:.1f} -> "
f"{used['Least-wind alternative']:.1f} TWh/year")
Change in production [TWh/year]: {'WIND': -13.2, 'NUCLEAR': 0.1, 'PV_LV': 0.4, 'CCGT_CC': 1.4, 'PV_EHV': 9.4}
Electricity used by the rest of the system: 41.1 -> 39.3 TWh/year
The whole energy system has been re-optimised around the chosen capacities, and its cost stays within the 5 % budget. With 6.5 GW less wind, about 13 TWh/year of wind power are missing. They are replaced mostly by alpine PV (PV_EHV: large PV parks in the Swiss Alps, connected to the extra-high-voltage grid), a technology we did not explore, and partly by gas plants with carbon capture (CCGT_CC). The rest of the system also uses less electricity, mainly in the heat pumps of district heating networks. Emissions are the same: this scenario is net zero by constraint.
Two lessons:
- This is what ORACLE is made for. Once the near-optimal space is mapped, you can screen thousands of alternatives for criteria the model does not optimise (land use, acceptance, ...) and pick the ones you prefer, knowing that they cost at most 5 % more than the optimum.
- The choice of design variables matters. Alpine PV turned out to be the main substitute for wind, so it deserves to be explored as a dimension of its own.
Going further¶
- More dimensions: just list more technologies. Above 6 dimensions, this implementation computes the metric by solving the bilevel problem of the paper [1] as a mixed-integer linear program (
metric='milp') instead of enumerating vertices. This MILP becomes the expensive part of ORACLE as the number of dimensions and of designs found grows;mip_rel_gapandmip_time_limittrade accuracy for speed (convergence is always judged on the certified bound). - Units: the metric measures the largest deviation of any single design variable, in its own units. If your dimensions have different units or magnitudes (e.g. GW of generation and GWh of storage), use
Oracle(..., scale='extent'). ORACLE warns you when the bound ranges differ by more than a factor 10. - Options:
tolsets the accuracy,max_iterthe iteration budget (run()can be called again to continue), andcost_cut=Falseuses only the separating cut. - Any other energy system model: ORACLE is not specific to EnergyScope. Any linear Pyomo model works as in part 1, with
PyomoProblem(model, design=..., cost=...); any linear AMPL model withAmplProblem(ampl, dimensions, design=..., cost=...). For other modelling frameworks, implement the four methods ofNearOptimalProblem(cost optimum, nearest near-optimal design, minimum cost of a design, extreme design), or start from the authors' reference code [2].
Limitations. ORACLE needs a convex model: integer decisions are relaxed, and the near-optimal space of a mixed-integer model is not convex. Each iteration solves the full model once or twice, plus the metric, whose cost grows with the number of dimensions. And the space is explored in the chosen design variables only: two systems with the same design can still differ in their operation.
References¶
[1] E. M. Turan, S. Moret, A. Bardow (2026). ORACLE: A rigorous metric and method to explore all near-optimal designs for energy systems. Computers & Chemical Engineering 210, 109630. doi:10.1016/j.compchemeng.2026.109630 ⧉. Open access (CC BY-NC-ND 4.0); preprint: arXiv:2509.26452 ⧉.
[2] Reference implementation of ORACLE, © 2026 ETH Zurich, MIT license: gitlab.ethz.ch/epse/systems-design-public/oracle-metric-and-method ⧉.
API reference of the implementation used in this tutorial: energyscope.oracle.
How to cite¶
ORACLE is the work of Evren M. Turan, Stefano Moret and André Bardow. If you use it, in EnergyScope or in any other model, please cite their paper [1]:
@article{turan2026oracle,
author = {Turan, Evren M. and Moret, Stefano
and Bardow, Andr{\'e}},
title = {{ORACLE}: A rigorous metric and method
to explore all near-optimal designs
for energy systems},
journal = {Computers \& Chemical Engineering},
volume = {210},
pages = {109630},
year = {2026},
doi = {10.1016/j.compchemeng.2026.109630}
}
The implementation in energyscope.oracle used in this tutorial is adapted from the authors' reference code [2].