oracle
¤
Oracle
explore all near-optimal designs of an energy system model.
ORACLE (Optimization for the Rigorous Analysis of the Complete Landscape of alternatives in Energy systems), a method
by E. M. Turan, S. Moret and A. Bardow, maps the near-optimal space of a linear model - every design whose cost is at
most (1 + eps) times the optimal cost - and measures how well it has been mapped, so you know when to stop.
ORACLE is general: it applies to any energy system model that is a linear (more generally, convex) optimisation problem. This subpackage implements it for the EnergyScope models and for any linear Pyomo or AMPL model; it is adapted from the authors' reference implementation. If you use ORACLE, please cite their paper:
Reference
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 ⧉
Example
from energyscope.oracle import Oracle, PyomoProblem
problem = PyomoProblem.from_energyscope(technologies=['PV', 'WIND', 'NUCLEAR', 'CCGT'])
result = Oracle(problem, eps=0.03).run()
result.ranges()
See the tutorial Explore near-optimal designs with ORACLE for a step-by-step introduction.
Modules:
-
algorithm–The ORACLE algorithm (Turan, Moret & Bardow, 2026).
-
geometry–Polytope geometry used by ORACLE.
-
plots–Plots of ORACLE results (plotly).
-
problem–Models that ORACLE can explore.
Classes:
-
AmplProblem–A linear AMPL model, e.g. the EnergyScope
coreorinfrastructure_ch_2050model. -
CostAtPoint–Answer to "what does it cost, at least, to build exactly
point?". -
FurthestPoint–Solution of the ORACLE metric: the point of the outer approximation that is furthest from the inner one.
-
NearOptimalProblem–Interface between ORACLE and an optimisation model.
-
NearestPoint–Answer to "which near-optimal design is closest to
target?". -
Oracle–Explore the whole near-optimal space of a model with ORACLE.
-
OracleResult–Snapshot of ORACLE's approximations of the near-optimal space.
-
PyomoProblem–A linear Pyomo model, solved with HiGHS (no license needed).
Functions:
-
distance_to_hull–L-infinity distance from
zto the convex hull ofpoints(one LP). -
furthest_point–The ORACLE metric:
max_{z in O} min_{y in I} ||z - y||_inf. -
polytope_vertices–All vertices of the bounded polytope
{z : A z <= b}.
AmplProblem
¤
AmplProblem(
ampl: AMPL,
dimensions: Sequence[str],
design: str = "F",
cost: str = "TotalCost",
lower: Optional[Sequence[float]] = None,
upper: Optional[Sequence[float]] = None,
cost_coefficients: Optional[Sequence[float]] = None,
parser: Optional[Callable] = None,
relax_integers: bool = True,
)
Bases: NearOptimalProblem
A linear AMPL model, e.g. the EnergyScope core or infrastructure_ch_2050 model.
ORACLE declares a few extra AMPL entities, all prefixed with oracle_, and re-solves the model in the same
AMPL session with the solver selected in it (option solver). After each of its solves it drops its
constraints and objectives again and re-selects the session's objective, so the session (e.g. the one of an
Energyscope object) still solves the original model afterwards; its variables hold the last ORACLE solution.
Badly scaled models such as infrastructure_ch_2050 (coefficients from 1e-7 to 1e7) can make an LP solver stop
at a design that is not optimal and still report it as optimal, because the error is below its default tolerance.
ORACLE would then get wrong distances and invalid cuts. To prevent this, ORACLE's solves:
- put the options in
solver_defaults(for Gurobi: deterministic dual simplex with the tightest optimality tolerance) before the session's<solver>_options, which therefore take precedence; the session's options are restored afterwards; - minimise
distance_weighttimes the distance in the nearest-design problem, so that its dual values (which give ORACLE's cuts) are not tolerance-sized; - re-solve once when the solver fails (
solve_result_num500 to 599), e.g. on "unrecoverable numerical issues".
For infrastructure_ch_2050, use Gurobi: CPLEX and HiGHS (through AMPL) do not solve its ORACLE problems
reliably (CPLEX reports numerical issues, HiGHS may not finish). A warning of ORACLE that a cut "would remove
known near-optimal designs" means that the solver's answers are inaccurate.
Parameters:
-
(ampl¤AMPL) –An
amplpy.AMPLobject with the model and data already loaded. -
(dimensions¤Sequence[str]) –Indices of
designto explore, e.g. technology names. -
(design¤str, default:'F') –Name of the indexed design variable (default
'F', the installed capacities). -
(cost¤str, default:'TotalCost') –Name of the total cost variable (default
'TotalCost'). -
(lower¤Optional[Sequence[float]], default:None) –Lower bounds of the explored variables (default: unbounded). They are imposed in ORACLE's solves, so bounds tighter than the model's restrict the explored space to this box.
-
(upper¤Optional[Sequence[float]], default:None) –Upper bounds of the explored variables (default: unbounded), see
lower. -
(cost_coefficients¤Optional[Sequence[float]], default:None) –Under-estimator of the cost, see
cost_coefficients. -
(parser¤Optional[Callable], default:None) –Function turning the solved AMPL object into a result object, used by
design_at. -
(relax_integers¤bool, default:True) –ORACLE needs a convex model. If the model has integer or binary variables, relax them to continuous ones in ORACLE's solves (default, AMPL option
relax_integrality) or raise an error (False).
Methods:
-
bounds– -
cost_at– -
cost_coefficients– -
design_at–Cheapest full system with the design
point: aResultfor EnergyScope -
extreme– -
from_energyscope–Explore the installed capacities of some technologies of an EnergyScope AMPL model.
-
nearest– -
set_budget– -
solve_optimum–
Attributes:
-
ampl– -
dimensions– -
distance_weight(float) –The nearest-design problem minimises
distance_weight * distance; distances and duals are scaled back. -
n_dims(int) – -
parser– -
solver_defaults(dict[str, dict[str, str]]) –Solver options used in ORACLE's solves, per solver (matched in the
solveroption).
Source code in src/energyscope/oracle/problem.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
distance_weight
class-attribute
instance-attribute
¤
distance_weight: float = 1000.0
The nearest-design problem minimises distance_weight * distance; distances and duals are scaled back.
solver_defaults
class-attribute
instance-attribute
¤
solver_defaults: dict[str, dict[str, str]] = {
solver: dict(options)
for solver, options in type(
self
).solver_defaults.items()
}
Solver options used in ORACLE's solves, per solver (matched in the solver option).
Default: {'gurobi': {'method': '1', 'opttol': '1e-9'}} (Gurobi's dual simplex with the tightest optimality
tolerance). They are put before the session's <solver>_options, so the session's own options take precedence.
Each instance has its own copy: set it to {} on an instance to use the session's options only.
bounds
¤
bounds() -> tuple[ndarray, ndarray]
Source code in src/energyscope/oracle/problem.py
609 610 | |
cost_at
¤
cost_at(point: ndarray) -> CostAtPoint
Source code in src/energyscope/oracle/problem.py
631 632 633 634 635 | |
cost_coefficients
¤
cost_coefficients() -> Optional[ndarray]
Source code in src/energyscope/oracle/problem.py
612 613 | |
design_at
¤
design_at(point: ndarray) -> Any
Cheapest full system with the design point: a Result for EnergyScope
models (via parser), otherwise the AMPL object holding the solution.
Source code in src/energyscope/oracle/problem.py
642 643 644 645 646 647 648 | |
extreme
¤
extreme(direction: ndarray) -> ndarray
Source code in src/energyscope/oracle/problem.py
637 638 639 640 | |
from_energyscope
classmethod
¤
from_energyscope(
es: Energyscope,
technologies: Sequence[str],
ds: Optional[Dataset] = None,
design: Optional[str] = None,
) -> AmplProblem
Explore the installed capacities of some technologies of an EnergyScope AMPL model.
Parameters:
-
(es¤Energyscope) –An
Energyscopeobject, e.g.Energyscope(model=infrastructure_ch_2050). Its model files are loaded if they are not yet. -
(technologies¤Sequence[str]) –Technologies whose capacity spans the explored space. Prefer technologies with a finite
f_max; infinite bounds are replaced by the extent of the near-optimal space (one extra solve each). -
(ds¤Optional[Dataset], default:None) –Optional
Datasetpassed to the model when it is loaded. -
(design¤Optional[str], default:None) –Name of the capacity variable (default:
Fin the typical-day models such ascore,F_Multin the monthly models).
Returns:
-
AmplProblem–The problem, with the technology bounds
f_min/f_maxand the annualised investment coststau * c_invas cost under-estimator. Integer variables of the model are relaxed.
Source code in src/energyscope/oracle/problem.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
nearest
¤
nearest(target: ndarray, scale: ndarray) -> NearestPoint
Source code in src/energyscope/oracle/problem.py
622 623 624 625 626 627 628 629 | |
set_budget
¤
set_budget(budget: Optional[float]) -> None
Source code in src/energyscope/oracle/problem.py
604 605 606 607 | |
solve_optimum
¤
solve_optimum() -> tuple[float, ndarray]
Source code in src/energyscope/oracle/problem.py
618 619 620 | |
CostAtPoint
dataclass
¤
CostAtPoint(cost: float, gradient: ndarray)
Answer to "what does it cost, at least, to build exactly point?".
Attributes:
FurthestPoint
dataclass
¤
FurthestPoint(
point: ndarray,
distance: float,
upper_bound: float,
method: str,
)
Solution of the ORACLE metric: the point of the outer approximation that is furthest from the inner one.
Attributes:
-
point(ndarray) –The furthest point of the outer approximation (the next "trial point" to explore).
-
distance(float) –Its L-infinity distance to the inner approximation (the ORACLE metric).
-
upper_bound(float) –A certified upper bound on the metric. Equals
distancefor the exact vertex method; for the MILP it is the solver's dual bound, which is larger when the MILP stops at its optimality gap or time limit (distanceis then only a lower bound on the metric). -
method(str) –'vertex'or'milp'.
NearOptimalProblem
¤
NearOptimalProblem(dimensions: Sequence[Any])
Bases: ABC
Interface between ORACLE and an optimisation model.
The model must be linear (more generally, convex): ORACLE's approximations are only valid if the near-optimal space is convex. Implement the abstract methods to plug in another modelling framework.
Parameters:
-
(dimensions¤Sequence[Any]) –Names of the design variables that span the explored space (e.g. technology names).
Methods:
-
bounds–Lower and upper bounds of the design variables (
-inf/infwhen unknown). -
cost_at–Minimise the total cost with the design fixed to
point(ignoring the budget). -
cost_coefficients–Coefficients
csuch thatc @ znever exceeds the total cost (e.g. annualised investment costs). -
design_at–Full model solution of the cheapest system that has the design
point. -
extreme–Near-optimal design minimising
direction @ z. -
nearest–Find the near-optimal design closest to
targetin the normmax_i |z_i - target_i| / scale_i. -
set_budget–Set the cost budget
(1 + eps) * optimal costthat defines the near-optimal space. -
solve_optimum–Minimise the total cost (ignoring the budget). Returns the optimal cost and design.
Attributes:
-
dimensions– -
n_dims(int) –
Source code in src/energyscope/oracle/problem.py
76 77 78 79 80 | |
bounds
¤
bounds() -> tuple[ndarray, ndarray]
Lower and upper bounds of the design variables (-inf/inf when unknown).
Source code in src/energyscope/oracle/problem.py
106 107 108 | |
cost_at
abstractmethod
¤
cost_at(point: ndarray) -> CostAtPoint
Minimise the total cost with the design fixed to point (ignoring the budget).
Source code in src/energyscope/oracle/problem.py
98 99 100 | |
cost_coefficients
¤
cost_coefficients() -> Optional[ndarray]
Coefficients c such that c @ z never exceeds the total cost (e.g. annualised investment costs).
They give ORACLE's initial "cost cut" c @ z <= budget. Return None if no such under-estimator is known.
Source code in src/energyscope/oracle/problem.py
110 111 112 113 114 115 | |
design_at
¤
design_at(point: ndarray) -> Any
Full model solution of the cheapest system that has the design point.
Source code in src/energyscope/oracle/problem.py
117 118 119 | |
extreme
abstractmethod
¤
extreme(direction: ndarray) -> ndarray
Near-optimal design minimising direction @ z.
Source code in src/energyscope/oracle/problem.py
102 103 104 | |
nearest
abstractmethod
¤
nearest(target: ndarray, scale: ndarray) -> NearestPoint
Find the near-optimal design closest to target in the norm max_i |z_i - target_i| / scale_i.
Source code in src/energyscope/oracle/problem.py
94 95 96 | |
set_budget
¤
set_budget(budget: Optional[float]) -> None
Set the cost budget (1 + eps) * optimal cost that defines the near-optimal space.
Source code in src/energyscope/oracle/problem.py
86 87 88 | |
solve_optimum
abstractmethod
¤
solve_optimum() -> tuple[float, ndarray]
Minimise the total cost (ignoring the budget). Returns the optimal cost and design.
Source code in src/energyscope/oracle/problem.py
90 91 92 | |
NearestPoint
dataclass
¤
NearestPoint(
point: ndarray,
distance: float,
normal: ndarray,
cost: float,
)
Answer to "which near-optimal design is closest to target?".
Attributes:
-
point(ndarray) –The closest near-optimal design
z_f(in the units of the design variables). -
distance(float) –Its (scaled) L-infinity distance to the target. Zero means the target itself is near-optimal.
-
normal(ndarray) –Sensitivity of
distanceto the target (the dual variables of the problem). It is the normal of a hyperplane that separates the target from the whole near-optimal space. -
cost(float) –Total cost of the design found.
Oracle
¤
Oracle(
problem: NearOptimalProblem,
eps: float = 0.05,
tol: Optional[float] = None,
scale: Union[None, str, Sequence[float]] = None,
metric: str = "auto",
cost_cut: bool = True,
verbose: bool = True,
mip_rel_gap: float = 0.01,
mip_time_limit: Optional[float] = None,
)
Explore the whole near-optimal space of a model with ORACLE.
Example
from energyscope.oracle import Oracle, PyomoProblem
problem = PyomoProblem.from_energyscope(technologies=['PV', 'WIND', 'NUCLEAR', 'CCGT'])
oracle = Oracle(problem, eps=0.03)
result = oracle.run(max_iter=50)
result.ranges()
Use run for the full algorithm, or
initialise followed by
step (or by furthest_point, nearest_point and refine) to
follow it step by step.
Parameters:
-
(problem¤NearOptimalProblem) –The model to explore, e.g. a
PyomoProblem. -
(eps¤float, default:0.05) –Allowed relative cost increase over the optimum: designs costing at most
(1 + eps)times the optimal cost are near-optimal (more preciselyoptimal cost + eps * |optimal cost|, also valid for negative costs). -
(tol¤Optional[float], default:None) –Stop when the ORACLE metric (the largest distance between the two approximations) is below
tol. Default: 1 % of the largest (scaled) bound range. -
(scale¤Union[None, str, Sequence[float]], default:None) –How distances are measured.
None(default, as in the paper) uses the units of the design variables. When units or magnitudes differ (e.g. GW and GWh), use'extent', which divides each dimension by its extent in the near-optimal space (two extra solves per dimension, which also tighten the initial bounds), or'range', which divides it by its bound range. Or give one positive number per dimension. -
(metric¤str, default:'auto') –How the ORACLE metric is computed:
'vertex'(exact, up to about 6 dimensions),'milp'(the bilevel problem of the paper, solved as a MILP) or'auto'(default), seefurthest_point. -
(cost_cut¤bool, default:True) –Also add the cost cut of the paper (one extra solve per iteration, usually fewer iterations).
-
(verbose¤bool, default:True) –Print one line per iteration.
-
(mip_rel_gap¤float, default:0.01) –Relative optimality gap of the metric MILP (the paper uses 10 %). Convergence is always judged on the MILP's proven upper bound, so a gap only makes some trial points less than the furthest.
-
(mip_time_limit¤Optional[float], default:None) –Time limit in seconds for each metric MILP.
Methods:
-
design–Cheapest full system with the design
point, e.g. an EnergyScope -
furthest_point–Step 2: the ORACLE metric - the point of the outer approximation furthest from the inner one.
-
initialise–Step 1: solve the cost optimum and build the first inner and outer approximations.
-
nearest_point–Step 3: the near-optimal design closest to
target(one solve of the full model). -
refine–Step 4: add the design found to the inner approximation and cut
targetoff the outer one. -
run–Run ORACLE until the metric is below the tolerance or
max_iteriterations are done. -
step–One ORACLE iteration (steps 2 to 4). Returns the iteration record (also appended to the history).
Attributes:
-
A(ndarray) –Normals of the outer approximation
{z : A z <= b}. -
b(ndarray) –Right-hand sides of the outer approximation
{z : A z <= b}. -
budget(Optional[float]) – -
cost_cut– -
dimensions– -
eps– -
inner_points(ndarray) –Near-optimal designs found so far, one per row (they span the inner approximation).
-
lower(Optional[ndarray]) – -
metric– -
mip_rel_gap– -
mip_time_limit– -
n_dims(int) – -
optimal_cost(Optional[float]) – -
optimum(Optional[ndarray]) – -
problem– -
result(OracleResult) –The current approximations, as an
OracleResult. -
scale(Optional[ndarray]) – -
tol(Optional[float]) – -
upper(Optional[ndarray]) – -
verbose–
Source code in src/energyscope/oracle/algorithm.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
inner_points
property
¤
inner_points: ndarray
Near-optimal designs found so far, one per row (they span the inner approximation).
design
¤
design(point: Union[Sequence[float], dict, Series])
Cheapest full system with the design point, e.g. an EnergyScope
Result.
Its cost is within the budget if point is in the near-optimal space (always true inside the inner
approximation).
Source code in src/energyscope/oracle/algorithm.py
511 512 513 514 515 516 517 518 | |
furthest_point
¤
furthest_point() -> FurthestPoint
Step 2: the ORACLE metric - the point of the outer approximation furthest from the inner one.
Returns:
-
FurthestPoint–The point (in the units of the design variables), its scaled distance to the inner approximation, and a
-
FurthestPoint–certified upper bound on the metric (equal to the distance, unless the MILP stopped at its gap or time
-
FurthestPoint–limit).
Source code in src/energyscope/oracle/algorithm.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
initialise
¤
initialise() -> Oracle
Step 1: solve the cost optimum and build the first inner and outer approximations.
- inner approximation: the cost-optimal design;
- outer approximation: the bounds of the design variables, plus the cost cut
c @ z <= budgetwhen the problem knows an under-estimatorcof the cost. Infinite bounds (and all bounds withscale='extent') are replaced by the extent of the near-optimal space in that dimension (one extra solve each); the designs reaching these extents are added to the inner approximation.
Source code in src/energyscope/oracle/algorithm.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
nearest_point
¤
nearest_point(target: ndarray) -> NearestPoint
Step 3: the near-optimal design closest to target (one solve of the full model).
The dual variables give the normal of a hyperplane that separates target from the near-optimal space;
they are checked against the distance found and re-oriented if the solver uses the opposite sign convention.
Source code in src/energyscope/oracle/algorithm.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
refine
¤
refine(target: ndarray, nearest: NearestPoint) -> dict
Step 4: add the design found to the inner approximation and cut target off the outer one.
Two cuts can be added, both valid for the whole near-optimal space:
- the separating cut
mu @ z <= mu @ z_f(always, whentargetis not near-optimal), wheremuare the dual variables of step 3: since the distance to the near-optimal space is a convex function of the target andmuits slope, no near-optimal design can be on the far side of this hyperplane; - the cost cut
cost(z_f) + lam @ (z - z_f) <= budget(ifcost_cut), wherelamis the slope of the minimum cost as a function of the design: it linearises the cost from below, so it is also valid.
Returns:
-
dict–Which cuts were added and whether
targetwas cut off.
Source code in src/energyscope/oracle/algorithm.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
run
¤
run(max_iter: int = 100) -> OracleResult
Run ORACLE until the metric is below the tolerance or max_iter iterations are done.
Can be called again to continue a previous run.
Source code in src/energyscope/oracle/algorithm.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
step
¤
step() -> dict
One ORACLE iteration (steps 2 to 4). Returns the iteration record (also appended to the history).
Source code in src/energyscope/oracle/algorithm.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
OracleResult
dataclass
¤
OracleResult(
dimensions: list,
eps: float,
optimal_cost: float,
budget: float,
optimum: Series,
inner_points: DataFrame,
outer: DataFrame,
history: DataFrame,
scale: Series,
tol: float,
distance: float,
converged: bool,
)
Snapshot of ORACLE's approximations of the near-optimal space.
Attributes:
-
dimensions(list) –Names of the explored design variables.
-
eps(float) –Allowed relative cost increase over the optimum (e.g.
0.05for 5 %). -
optimal_cost(float) –Cost of the optimal design.
-
budget(float) –Cost budget
optimal_cost + eps * |optimal_cost|defining the near-optimal space. -
optimum(Series) –The cost-optimal design.
-
inner_points(DataFrame) –Near-optimal designs found (one row each); their convex hull is the inner approximation.
-
outer(DataFrame) –Halfspaces
sum(row[d] * z[d]) <= rhsof the outer approximation, with their origin inkind. -
history(DataFrame) –One row per iteration: ORACLE metric, trial point, nearest near-optimal design, cuts added, timings.
-
scale(Series) –Scale of each dimension used to measure distances (distances are in units of
z / scale). -
tol(float) –Convergence tolerance on the ORACLE metric.
-
distance(float) –Certified upper bound on the ORACLE metric, i.e. on the largest distance between the two approximations (and so on the error made by using either of them).
-
converged(bool) –Whether the metric reached the tolerance.
Methods:
-
contains–Whether
pointlies in the inner (guaranteed near-optimal) or outer (possibly near-optimal) region. -
distance_to_inner–Scaled L-infinity distance from
pointto the inner approximation (0 if it is inside). -
flat_dimensions–Dimensions that do not vary in the outer approximation (and so in the near-optimal space).
-
plot_convergence–Plot the ORACLE metric against the iterations, see
-
plot_projection–Plot both approximations projected on two dimensions, see
-
plot_ranges–Plot the near-optimal range of each dimension, see
plot_ranges. -
ranges–Smallest and largest value of each dimension over both approximations.
-
sample–Random designs from the inner (guaranteed near-optimal) or outer approximation.
-
vertices–Vertices of the inner or outer approximation (exact, practical up to about 6 dimensions).
outer_A
property
¤
outer_A: ndarray
Normals of the outer approximation's halfspaces, one row per halfspace.
contains
¤
contains(
point: Union[Sequence[float], dict, Series],
region: str = "inner",
tol: float = 1e-06,
) -> bool
Whether point lies in the inner (guaranteed near-optimal) or outer (possibly near-optimal) region.
Source code in src/energyscope/oracle/algorithm.py
87 88 89 90 91 92 93 94 95 | |
distance_to_inner
¤
distance_to_inner(
point: Union[Sequence[float], dict, Series],
) -> float
Scaled L-infinity distance from point to the inner approximation (0 if it is inside).
Source code in src/energyscope/oracle/algorithm.py
97 98 99 100 101 | |
flat_dimensions
¤
flat_dimensions() -> list
Dimensions that do not vary in the outer approximation (and so in the near-optimal space).
Such a dimension is fixed by the model, e.g. by an equality constraint. It makes the approximations flat, so
vertices and
sample cannot be used on the outer approximation:
explore without it.
Source code in src/energyscope/oracle/algorithm.py
103 104 105 106 107 108 109 110 111 112 113 | |
plot_convergence
¤
plot_convergence(**kwargs)
Plot the ORACLE metric against the iterations, see
plot_convergence.
Source code in src/energyscope/oracle/algorithm.py
148 149 150 151 152 | |
plot_projection
¤
plot_projection(x: str, y: str, **kwargs)
Plot both approximations projected on two dimensions, see
plot_projection.
Source code in src/energyscope/oracle/algorithm.py
154 155 156 157 158 | |
plot_ranges
¤
plot_ranges(**kwargs)
Plot the near-optimal range of each dimension, see plot_ranges.
Source code in src/energyscope/oracle/algorithm.py
160 161 162 163 | |
ranges
¤
ranges() -> DataFrame
Smallest and largest value of each dimension over both approximations.
The true near-optimal range of each dimension lies between the inner and the outer one.
Source code in src/energyscope/oracle/algorithm.py
74 75 76 77 78 79 80 81 82 83 84 85 | |
sample
¤
sample(
n: int = 100,
region: str = "inner",
seed: Optional[int] = None,
) -> DataFrame
Random designs from the inner (guaranteed near-optimal) or outer approximation.
Samples are approximately uniform (hit-and-run random walk). If the inner approximation is flat (fewer
than n_dims + 1 independent points), random convex combinations of its points are returned instead.
Source code in src/energyscope/oracle/algorithm.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
vertices
¤
vertices(region: str = 'outer') -> DataFrame
Vertices of the inner or outer approximation (exact, practical up to about 6 dimensions).
Source code in src/energyscope/oracle/algorithm.py
115 116 117 118 119 120 121 122 123 124 125 | |
PyomoProblem
¤
PyomoProblem(
model: ConcreteModel,
design: Union[str, Any],
cost: Union[str, Any],
dimensions: Optional[Sequence[Any]] = None,
lower: Optional[Sequence[float]] = None,
upper: Optional[Sequence[float]] = None,
cost_coefficients: Optional[Sequence[float]] = None,
parser: Optional[Callable] = None,
relax_integers: bool = True,
solver_options: Optional[dict] = None,
)
Bases: NearOptimalProblem
A linear Pyomo model, solved with HiGHS (no license needed).
ORACLE adds a block model.oracle to the model with the extra variables, constraints and objectives it needs,
deactivates the model's own objectives, and re-solves the model with a persistent HiGHS instance, so each query
only takes a fraction of a full solve. The model is therefore dedicated to ORACLE (from_energyscope builds a
fresh one).
Parameters:
-
(model¤ConcreteModel) –The Pyomo
ConcreteModel. Its objectives are deactivated; the cost to minimise is given bycost. -
(design¤Union[str, Any]) –The indexed design variable (or its name), e.g.
'F_Mult'. -
(cost¤Union[str, Any]) –The total cost variable or expression (or its name), e.g.
'TotalCost'. -
(dimensions¤Optional[Sequence[Any]], default:None) –Indices of
designto explore (default: all of them). -
(lower¤Optional[Sequence[float]], default:None) –Lower bounds of the explored variables (default: the variable bounds). Given bounds are added to the model as constraints, so bounds tighter than the model's restrict the explored space to this box.
-
(upper¤Optional[Sequence[float]], default:None) –Upper bounds of the explored variables (default: the variable bounds), see
lower. -
(cost_coefficients¤Optional[Sequence[float]], default:None) –Under-estimator of the cost, see
cost_coefficients. -
(parser¤Optional[Callable], default:None) –Function turning the solved model into a result object, used by
design_at. -
(relax_integers¤bool, default:True) –ORACLE needs a convex model. If the model has integer or binary variables, relax them to continuous ones (default) or raise an error (
False). -
(solver_options¤Optional[dict], default:None) –Extra HiGHS options.
Methods:
-
bounds– -
cost_at– -
cost_coefficients– -
design_at–Cheapest full system with the design
point: aResultfor EnergyScope -
extreme– -
from_energyscope–Explore the installed capacities of some technologies of an EnergyScope Pyomo model.
-
nearest– -
set_budget– -
solve_optimum–
Attributes:
-
dimensions– -
model– -
n_dims(int) – -
parser–
Source code in src/energyscope/oracle/problem.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
bounds
¤
bounds() -> tuple[ndarray, ndarray]
Source code in src/energyscope/oracle/problem.py
311 312 | |
cost_at
¤
cost_at(point: ndarray) -> CostAtPoint
Source code in src/energyscope/oracle/problem.py
334 335 336 337 338 339 340 341 | |
cost_coefficients
¤
cost_coefficients() -> Optional[ndarray]
Source code in src/energyscope/oracle/problem.py
314 315 | |
design_at
¤
design_at(point: ndarray) -> Any
Cheapest full system with the design point: a Result for EnergyScope
models (via parser), otherwise the solved Pyomo model.
Source code in src/energyscope/oracle/problem.py
351 352 353 354 355 | |
extreme
¤
extreme(direction: ndarray) -> ndarray
Source code in src/energyscope/oracle/problem.py
343 344 345 346 347 348 349 | |
from_energyscope
classmethod
¤
from_energyscope(
technologies: Sequence[str],
model: Optional[PyomoModel] = None,
solver_options: Optional[dict] = None,
) -> PyomoProblem
Explore the installed capacities of some technologies of an EnergyScope Pyomo model.
Parameters:
-
(technologies¤Sequence[str]) –Technologies whose capacity (
F_Mult) spans the explored space, e.g.['PV', 'WIND', 'NUCLEAR', 'CCGT']. -
(model¤Optional[PyomoModel], default:None) –An EnergyScope
PyomoModel(default:energyscope.models.pyomo_ch). -
(solver_options¤Optional[dict], default:None) –Extra HiGHS options.
Returns:
-
PyomoProblem–The problem, with the technology bounds
f_min/f_maxand the annualised investment coststau * c_invas cost under-estimator.
Source code in src/energyscope/oracle/problem.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
nearest
¤
nearest(target: ndarray, scale: ndarray) -> NearestPoint
Source code in src/energyscope/oracle/problem.py
323 324 325 326 327 328 329 330 331 332 | |
set_budget
¤
set_budget(budget: Optional[float]) -> None
Source code in src/energyscope/oracle/problem.py
306 307 308 309 | |
solve_optimum
¤
solve_optimum() -> tuple[float, ndarray]
Source code in src/energyscope/oracle/problem.py
317 318 319 320 321 | |
distance_to_hull
¤
L-infinity distance from z to the convex hull of points (one LP).
Parameters:
-
(z¤ndarray) –The point, shape
(n_dims,). -
(points¤ndarray) –The points spanning the hull, shape
(n_points, n_dims).
Returns:
-
tuple[float, ndarray]–The distance and the weights of the closest convex combination of
points.
Source code in src/energyscope/oracle/geometry.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
furthest_point
¤
furthest_point(
A: ndarray,
b: ndarray,
points: ndarray,
method: str = "auto",
upper_bound: Optional[float] = None,
time_limit: Optional[float] = None,
mip_rel_gap: float = 1e-06,
mip_abs_gap: float = 0.0,
) -> FurthestPoint
The ORACLE metric: max_{z in O} min_{y in I} ||z - y||_inf.
O = {z : A z <= b} is the outer approximation and I = conv(points) the inner approximation. The value is
the largest error made by using either approximation in place of the (unknown) near-optimal space, and the point
reaching it is where the approximations disagree the most - which is where ORACLE explores next.
Parameters:
-
(A¤ndarray) –Halfspace normals of the outer approximation, shape
(n_halfspaces, n_dims). Must describe a bounded set. -
(b¤ndarray) –Right-hand sides, shape
(n_halfspaces,). -
(points¤ndarray) –Points spanning the inner approximation, shape
(n_points, n_dims). -
(method¤str, default:'auto') –'vertex'enumerates the vertices ofOand evaluates the distance at each of them. This is exact because the distance to a convex set is a convex function, so its maximum over a polytope is reached at a vertex.'milp'solves the bilevel problem of the paper as a single-level MILP (KKT conditions with big-M constraints), which scales better with the number of dimensions.'auto'(default) picks'vertex'up toVERTEX_METHOD_MAX_DIMENSIONS(6) dimensions. -
(upper_bound¤Optional[float], default:None) –Known upper bound on the metric (e.g. its previous value), used to speed up the MILP.
-
(time_limit¤Optional[float], default:None) –Time limit in seconds for the MILP. When it is reached, the best point found is returned with the solver's upper bound on the metric.
-
(mip_rel_gap¤float, default:1e-06) –Relative optimality gap for the MILP.
-
(mip_abs_gap¤float, default:0.0) –Absolute optimality gap for the MILP.
Returns:
-
FurthestPoint–The furthest point and its distance.
Source code in src/energyscope/oracle/geometry.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
polytope_vertices
¤
polytope_vertices(A: ndarray, b: ndarray) -> ndarray
All vertices of the bounded polytope {z : A z <= b}.
Uses Qhull's halfspace intersection, so it is exact but its cost grows quickly with the number of dimensions.
Raises:
-
ValueError–If the polytope has no interior (it is flat or empty), or if Qhull can only enumerate its vertices approximately (nearly degenerate input).
Source code in src/energyscope/oracle/geometry.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |