Mathematical models (ixmp.model
)¶
By default, the ix modeling platform is installed with ixmp.model.gams.GAMSModel
, which performs calculations by executing code stored in GAMS files.
However, ix modeling platform is extensible to support other methods of performing calculations or optimization.
Developers wishing to add such capabilities may subclass ixmp.model.base.Model
and implement its methods.
Provided models¶
-
ixmp.model.
get_model
(name, **model_options)¶ Return a model for name (or the default) with model_options.
-
ixmp.model.
MODELS
= {'default': <class 'ixmp.model.gams.GAMSModel'>, 'gams': <class 'ixmp.model.gams.GAMSModel'>}¶ Mapping from names to available models. To register additional models, add elements to this variable.
-
class
ixmp.model.gams.
GAMSModel
(name=None, **model_options)¶ General class for ixmp models using GAMS.
GAMSModel solves a Scenario using the following steps:
- All Scenario data is written to a model input file in GDX format.
- A GAMS program is run to perform calculations, producing output in a GDX file.
- Output, or solution, data is read from the GDX file and stored in the Scenario.
When created and
run()
, GAMSModel constructs file paths and other necessary values using format strings. Thedefaults
may be overridden by the keyword arguments to the constructor:Other Parameters: - name (str, optional) – Override the
name
attribute to provide the model_name for format strings. - model_file (str, optional) – Path to GAMS file, including ‘.gms’ extension.
Default:
'{model_name}.gms'
(in the current directory). - case (str, optional) – Run or case identifier to use in GDX file names. Default:
'{scenario.model}_{scenario.name}'
, where scenario is theScenario
object passed torun()
. Formatted using model_name and scenario. - in_file (str, optional) – Path to write GDX input file. Default:
'{model_name}_in.gdx'
. Formatted using model_name, scenario, and case. - out_file (str, optional) – Path to read GDX output file. Default:
'{model_name}_out.gdx'
. Formatted using model_name, scenario, and case. - solve_args (list of str, optional) – Arguments to be passed to GAMS, e.g. to identify the model input and
output files. Each formatted using model_file, scenario, case,
in_file, and out_file. Default:
'--in="{in_file}"'
'--out="{out_file}"'
- gams_args (list of str, optional) – Additional arguments passed directly to GAMS without formatting, e.g.
to control solver options or behaviour. See the GAMS
Documentation.
For example:
'LogOption=4'
prints output to stdout (not console) and the log file.
- check_solution (bool, optional) – If
True
, raise an exception if the GAMS solver did not reach optimality. (Only for MESSAGE-scheme Scenarios.) - comment (str, optional) – Comment added to Scenario when importing the solution. If omitted, no comment is added.
- equ_list (list of str, optional) – Equations to be imported from the out_file. Default: all.
- var_list (list of str, optional) – Variables to be imported from the out_file. Default: all.
-
defaults
= {'case': '{scenario.model}_{scenario.scenario}', 'check_solution': True, 'comment': None, 'equ_list': None, 'gams_args': ['LogOption=4'], 'in_file': '{model_name}_in.gdx', 'model_file': '{model_name}.gms', 'out_file': '{model_name}_out.gdx', 'solve_args': ['--in="{in_file}"', '--out="{out_file}"'], 'var_list': None}¶ Default model options.
-
name
= 'default'¶ Model name.
-
run
(scenario)¶ Execute the model.
Model API¶
-
class
ixmp.model.base.
Model
(name, **kwargs)¶ In the following, the words REQUIRED, OPTIONAL, etc. have specific meanings as described in IETF RFC 2119.
Model is an abstract class; this means it MUST be subclassed. It has two REQURIED methods that MUST be overridden by subclasses:
name
Name of the model. __init__
(name, **kwargs)Constructor. run
(scenario)Execute the model. -
__init__
(name, **kwargs)¶ Constructor.
Parameters: kwargs – Model options, passed directly from
Scenario.solve()
.Model subclasses MUST document acceptable option values.
-
name
= 'base'¶ Name of the model.
-