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.MODELS: Dict[str, Type] = {'dantzig': <class 'ixmp.model.dantzig.DantzigModel'>, '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.

ixmp.model.get_model(name, **model_options)

Return a model for name (or the default) with model_options.

class ixmp.model.gams.GAMSModel(name=None, **model_options)

General class for ixmp models using GAMS.

GAMSModel solves a Scenario using the following steps:

  1. All Scenario data is written to a model input file in GDX format.

  2. A GAMS program is run to perform calculations, producing output in a GDX file.

  3. 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. The defaults 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}_{}', where scenario is the Scenario object passed to run(). 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: Mapping[str, object] = {'case': '{scenario.model}_{scenario.scenario}', 'check_solution': True, 'comment': None, 'equ_list': None, 'gams_args': ['LogOption=4'], 'in_file': '{temp_dir}/{model_name}_in.gdx', 'model_file': '{model_name}.gms', 'out_file': '{temp_dir}/{model_name}_out.gdx', 'solve_args': ['--in="{in_file}"', '--out="{out_file}"'], 'use_temp_dir': True, 'var_list': None}

Default model options.

name = 'default'

Model name.


Execute the model.


Return the GAMS version as a string, e.g. ‘24.7.4’.

class ixmp.model.dantzig.DantzigModel(name=None, **model_options)

Dantzig’s cannery/transport problem as a GAMSModel.

Provided for testing ixmp code.

classmethod initialize(scenario, with_data=False)

Initialize the problem.

If with_data is True (default: False), the set and parameter values from the original problem are also populated. Otherwise, the sets and parameters are left empty.

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 of the model.

__init__(name, **kwargs)



Set up scenario with required items.

initialize_items(scenario, items)

Helper for initialize().


Execute the model.

abstract __init__(name, **kwargs)




Model options, passed directly from Scenario.solve().

Model subclasses MUST document acceptable option values.

classmethod initialize(scenario)

Set up scenario with required items.

Implementations of initialize():

  • may add sets, set elements, and/or parameter values.

  • may accept any number of keyword arguments to control behaviour.

  • must not modify existing parameter data in scenario, either by deleting or overwriting values.


scenario (Scenario) – Object to initialize.

See also


classmethod initialize_items(scenario, items)

Helper for initialize().

All of the items are added to scenario. Existing items are not modified. Errors are logged if the description in items conflicts with the index set(s) and/or index name(s) of existing items.

initialize_items may perform one commit. scenario is in the same state (checked in, or checked out) after initialize_items is complete.

  • scenario (Scenario) – Object to initialize.

  • items (dict of (str -> dict)) – Each key is the name of an ixmp item (set, parameter, equation, or variable) to initialize. Each dict must have the key ‘ix_type’; one of ‘set’, ‘par’, ‘equ’, or ‘var’; any other entries are keyword arguments to the methods init_set() etc.


ValueError – if scenario has a solution, i.e. has_solution() is True.

name = 'base'

Name of the model.

abstract run(scenario)

Execute the model.


scenario (Scenario) – Scenario object to solve by running the Model.