calliope.Model(model_definition, debug=False, scenario=None, override_dict=None, data_source_dfs=None, **kwargs)
¶
Bases: object
A Calliope Model.
Returns a new Model from either the path to a YAML model configuration file or a dict fully specifying the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_definition |
str | Path | dict | Dataset
|
If str or Path, must be the path to a model configuration file. If dict or AttrDict, must fully specify the model. If an xarray dataset, must be a valid calliope model. |
required |
debug |
bool
|
If True, additional debug data will be included in the built model. Defaults to False. |
False
|
scenario |
str
|
Comma delimited string of pre-defined |
None
|
override_dict |
dict
|
Additional overrides to apply to |
None
|
data_source_dfs |
dict[str, DataFrame]
|
Model definition |
None
|
Source code in src/calliope/model.py
backend: BackendModel
instance-attribute
¶
config: AttrDict
instance-attribute
¶
defaults: AttrDict
instance-attribute
¶
inputs
property
¶
is_built
property
¶
is_solved
property
¶
math: AttrDict
instance-attribute
¶
math_documentation = MathDocumentation()
instance-attribute
¶
name
property
¶
results
property
¶
build(force=False, **kwargs)
¶
Build description of the optimisation problem in the chosen backend interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force |
bool
|
If |
False
|
Source code in src/calliope/model.py
info()
¶
Generate basic description of the model, combining its name and a rough indication of the model size.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Basic description of the model. |
Source code in src/calliope/model.py
run(force_rerun=False, **kwargs)
¶
Run the model. If force_rerun
is True, any existing results
will be overwritten.
Additional kwargs are passed to the backend.
Source code in src/calliope/model.py
solve(force=False, warmstart=False, **kwargs)
¶
Run the built optimisation problem.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force |
bool
|
If |
False
|
warmstart |
bool
|
If True and the optimisation problem has already been run in this session
(i.e., |
False
|
Raises:
Type | Description |
---|---|
ModelError
|
Optimisation problem must already be built. |
ModelError
|
Cannot run the model if there are already results loaded, unless |
ModelError
|
Some preprocessing steps will stop a run mode of "operate" from being possible. |
Source code in src/calliope/model.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 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 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|
to_csv(path, dropna=True, allow_overwrite=False)
¶
Save complete model data (inputs and, if available, results)
as a set of CSV files to the given path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str | Path
|
|
required |
dropna |
bool
|
If True, NaN values are dropped when saving, resulting in significantly smaller CSV files. Defaults to True |
True
|
allow_overwrite |
bool
|
If True, allow the option to overwrite the directory contents if it already exists. This will overwrite CSV files one at a time, so if the dataset has different arrays to the previous saved models, you will get a mix of old and new files. Defaults to False. |
False
|
Source code in src/calliope/model.py
to_netcdf(path)
¶
Save complete model data (inputs and, if available, results)
to a NetCDF file at the given path
.
validate_math_strings(math_dict)
¶
Validate that expression
and where
strings of a dictionary containing string mathematical formulations can be successfully parsed.
This function can be used to test custom math before attempting to build the optimisation problem.
NOTE: strings are not checked for evaluation validity. Evaluation issues will be raised only on calling Model.build()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
math_dict |
dict
|
Math formulation dictionary to validate. Top level keys must be one or more of ["variables", "global_expressions", "constraints", "objectives"], e.g.: |
required |
Returns: If all components of the dictionary are parsed successfully, this function will log a success message to the INFO logging level and return None. Otherwise, a calliope.ModelError will be raised with parsing issues listed.