Running a Model¶
The practical workflow is:
- create a project and generate templates;
- populate and validate the inputs;
- select the formulation and solver;
- run the optimization;
- inspect KPIs and detailed results.
From project to solved model¶
import microgridspy as mgp
mgp.validate_project("my_site") # step 2
model = mgp.solve("my_site", solver="highs") # steps 3–4
results = model.results() # step 5
solve() reads the formulation from formulation.json, builds the appropriate model
(TypicalYearModel or MultiYearModel), and solves it with the requested solver. It
returns the solved model, from which you obtain a structured results object with
model.results() or an xarray summary with model.results_summary().
Solver options¶
model = mgp.solve(
"my_site",
solver="highs", # "highs" (open source) or "gurobi" (licensed)
formulation=None, # None → auto-detect; or "typical_year" / "multi_year"
)
Extra keyword arguments are forwarded to the model's solve_single_objective(...) (e.g.
solver_params, problem_fn, log_file_path). At least one solver extra must be installed
— see Installation.
Driving the model class directly¶
from microgridspy import TypicalYearModel
model = TypicalYearModel("my_site")
model.solve_single_objective(solver="highs")
results = model.results()
Use MultiYearModel the same way for dynamic studies.
Command line¶
The package also installs a microgridspy console command and a microgridspy-gui
Streamlit workspace (with the [gui] extra). The CLI mirrors the create → validate → solve
workflow; run microgridspy --help for the available subcommands.
Once solved, see Results for what the outputs mean.