Skip to content

Model API

The public model classes representing the two optimization formulations. Both are constructed from a project name and expose solve_single_objective(...), results(), and results_summary().

The detailed mathematical description of each formulation belongs in the Methodology section rather than in the generated API.

TypicalYearModel

The typical-year formulation.

microgridspy.TypicalYearModel

Typical-year optimization model for a project.

Builds and solves the single-representative-year formulation in Linopy: it assembles the sets and input data from the project folder, constructs the variables, constraints, and objective, and solves for least-cost sizing and hourly dispatch.

Construct it with a project name (resolved in the active workspace), then call solve_single_objective(); afterwards use results() for the structured TypicalYearResults tables or results_summary() for the raw solved dataset. The convenience wrapper microgridspy.solve() covers the common path.

from microgridspy import TypicalYearModel

model = TypicalYearModel("demo_typical_year")
model.solve_single_objective(solver="highs")
results = model.results()
results.kpis            # pandas DataFrame

Parameters:

Name Type Description Default
project_name str

the project folder in the active workspace.

required

results()

Assemble the full typical-year results object from the solved model.

Call this after solve_single_objective(). Returns a TypicalYearResults holding the analysis-ready pandas tables (dispatch, energy balance, design summary, KPIs, cash flows, ...) - the same content the GUI Results page renders, with no manual plumbing.

Returns:

Name Type Description
TypicalYearResults TypicalYearResults

the structured results container.

Raises:

Type Description
RuntimeError

if the model has not been solved yet.

results_summary()

Small, UI-oriented summary extracted from self.model.solution. Safe to call after solve.

solve_single_objective(solver='highs', solver_params=None, problem_fn=None, log_file_path=None)

Build and solve the model. Returns an xarray Dataset with: - attrs: status, objective_value (if available), solver, solver_params - (optional) decision var snapshots (res_units, battery_units, generator_units) The full numeric solution is also available as self.model.solution after solve.

MultiYearModel

The multi-year (dynamic) capacity-expansion formulation.

microgridspy.MultiYearModel

Multi-year (dynamic) capacity-expansion optimization model for a project.

Builds and solves the dynamic formulation in Linopy over an explicit planning horizon: it assembles year- and scenario-indexed inputs, represents phased investment through capacity cohorts, and solves for least-cost staged sizing and hourly dispatch with intertemporal (social-discount-rate) valuation.

Construct it with a project name (resolved in the active workspace), then call solve_single_objective(); afterwards use results() for the structured MultiYearResults tables or results_summary() for the raw solved dataset. The convenience wrapper microgridspy.solve() covers the common path.

from microgridspy import MultiYearModel

model = MultiYearModel("demo_multi_year")
model.solve_single_objective(solver="highs")
results = model.results()

Parameters:

Name Type Description Default
project_name str

the project folder in the active workspace.

required

results()

Assemble the full multi-year results object from the solved model.

Call this after solve_single_objective(). Returns a MultiYearResults holding the analysis-ready pandas tables (dispatch, energy balance, design by step, KPIs, discounted cash flows, ...) - the same content the GUI Results page renders.

Returns:

Name Type Description
MultiYearResults MultiYearResults

the structured results container.

Raises:

Type Description
RuntimeError

if the model has not been solved yet.

results_summary()

Small, UI-oriented summary extracted from self.model.solution. Safe to call after solve.

solve_single_objective(solver='highs', solver_params=None, problem_fn=None, log_file_path=None)

Build and solve the model. Returns an xarray Dataset with: - attrs: status, objective_value (if available), solver, solver_params - (optional) decision var snapshots (res_units, battery_units, generator_units) The full numeric solution is also available as self.model.solution after solve.

InputValidationError

Raised when a project's inputs are missing or inconsistent.

microgridspy.InputValidationError

Bases: RuntimeError

Raised when a project's inputs are missing, malformed or inconsistent.