Interfacing with the built optimisation problemΒΆ
On loading a model, there is no solver backend, only the input dataset.
The backend is generated when a user calls build()
on their model.
Currently this will call back to Pyomo to build the model and send it off to the solver, given by the user in the run configuration config.solve.solver
.
Once built, solved, and returned, the user has access to the results dataset model.results
and interface functions with the backend model.backend
.
You can use this interface to:
-
Get the optimisation problem component data. The optimisation problem has input parameters, decision variables, global expressions, constraints, and an objective. The data of all these components are stored as xarray.DataArrays and you can query the backend to inspect them. For instance,
model
.backend.parameters will provide you with an xarray.Dataset of input parameters transformed into mutable objects that are used in the optimisation. In addition to the input data you provided, these arrays fill in missing data with default values if the parameter is one of those predefined in Calliope. -
Update a parameter value. If you are interested in updating a few values in the model, you can run
model
.backend.update_parameter. For example, to update the energy efficiency of yourccgt
technology in locationregion1
from 0.5 to 0.1, you can run:
This will not affect results at this stage, you'll need to rerun the backend (point 4) to optimise with these new values.
-
Update decision variable bounds. Most of the time, decision variable bounds are actually input parameters (e.g.,
flow_cap_max
for the upper bound of theflow_cap
decision variable). Therefore, to update the bounds you will update the parameter withmodel
.backend.update_parameter. If a fixed numeric value is instead used, e.g. in your own custom math, you can update bounds usingmodel
.backend.update_variable_bounds. For instance, to updateflow_out
lower bound to 70 forbattery
atregion2
: -
Fix a decision variable. If you have already run your optimisation once and you want to re-run it with some decisions fixed to their previous optimal values, you can use
model
.backend.fix_variable. This can be useful if you change an input parameter and wish to see its effect on a limited set of decisions. As withmodel
.backend.update_parameter, you pass an xarray.DataArray to the method, this time with binary values. Where the value isTrue
in the array, that variable will be fixed. E.g., to fix allpv
area use:new_data = xr.DataArray(True, coords={"techs": "pv"}) model.backend.fix_variable("area_use", new_data)
Info
You can also _un_fix a variable using
unfix_variable
. -
Rerunning the optimisation problem. If you have edited parameters or variables, you will need to solve the optimisation problem again to propagate the effects. Any time you call
model.solve(force=true)
, it will use the current state of the backend.force=true
is required to tell Calliope that you are happy to replace the existing results with the new solution. Once solved,model.results
will contain new result data.