Model

class iesopt.Model(filename: str | Path, **kwargs)[source]

An IESopt model, based on an IESopt.jl core model.

compute_iis(filename=None) None[source]

Compute and print the Irreducible Infeasible Set (IIS) of the model, or optionally write it to a file.

Note that this requires a solver that supports IIS computation.

Parameters:

filename (Optional[str | Path]) – The filename to write the IIS to. If None, the IIS is only printed to the console.

Examples

Computing the IIS of a model.
import iesopt

model = iesopt.run("infeasible_model.iesopt.yaml")
model.compute_iis()

# or (arbitrary filename/extension):
model.compute_iis(filename="my_problem.txt")
property core

Access the core JuMP model that is used internally.

property data

Access the IESopt data object of the model.

This is deprecated; use model.internal instead (similar to the Julia usage IESopt.internal(model)).

extract_result(component: str, field: str, mode: str = 'value')[source]

Manually extract a specific result from the model.

generate() None[source]

Generate a IESopt model from the attached top-level YAML config.

get_component(component: str)[source]

Get a core component based on its full name.

get_components(tagged=None)[source]

Get all components of the model, possibly filtered by (a) tag(s).

Parameters:

tagged (str or list of str) – The tag(s) to filter the components by, can be None (default) to get all components.

get_constraint(component: str, constraint: str)[source]

Get a specific constraint from a core component.

get_variable(component: str, variable: str)[source]

Get a specific variable from a core component.

property internal

Access the IESopt data object of the model.

nvar(var: str)[source]

Extract a named variable, from model.

If your variable is called :myvar, and you would access it in Julia using model[:myvar], you can call model.nvar(“myvar”).

property objective_value: float

Get the objective value of the model. Only available if the model was solved beforehand.

optimize() None[source]

Optimize the model.

property results: Results

Get the results of the model.

property status: ModelStatus

Get the current status of this model. See ModelStatus for possible values.

write_to_file(filename=None, *, format: str = 'automatic') str[source]

Write the model to a file.

Consult the Julia version of this function, [IESopt.write_to_file](https://ait-energy.github.io/iesopt/pages/manual/julia/index.html#write-to-file) for more information. This will automatically invoke generate if the model has not been generated yet.

Parameters:

filename (Optional[str]) – The filename to write to. If None, the path and name are automatically determined by IESopt.

Keyword Arguments:

format (str) – The format to write the file in. If automatic, the format is determined based on the extension of the filename. Otherwise, it used as input to [JuMP.write_to_file](https://jump.dev/JuMP.jl/stable/api/JuMP/#write_to_file), by converting to uppercase and prefixing it with MOI.FileFormats.FORMAT_. Writing to, e.g., an LP file can be done by setting format=”lp” or format=”LP”.

Returns:

The filename (including path) of the written file.

Return type:

str

Examples

Writing a model to a problem file.
import iesopt

cfg = iesopt.make_example("01_basic_single_node", dst_dir="opt")

# Model will be automatically generated when calling `write_to_file`:
model = iesopt.Model(cfg)
model.write_to_file()

# It also works with already optimized models:
model = iesopt.run(cfg)
model.write_to_file("opt/out/my_problem.LP")

# And supports different formats:
target = model.write_to_file("opt/out/my_problem.foo", format="mof")
print(target)
class iesopt.model.ModelStatus[source]

Status of an iesopt.Model.

EMPTY = 'empty'
FAILED_GENERATE = 'failed_generate'
FAILED_OPTIMIZE = 'failed_optimize'
GENERATED = 'generated'
INFEASIBLE = 'infeasible'
INFEASIBLE_OR_UNBOUNDED = 'infeasible_unbounded'
OPTIMAL = 'optimal'
OPTIMAL_LOCALLY = 'local_optimum'
OTHER = 'other'