modelx.cur_model#

cur_model(model=None)[source]#

Get or set the current model.

When called without arguments, returns the current model. When called with a model argument, sets that model as current and returns it.

The current model is used as the default model for operations like new_space(), defcells(), and other functions that operate on models.

Parameters:

model (str or Model, optional) –

The model to set as current. Can be:

  • A Model object

  • A string with the model name

  • None (default) to just get the current model

Returns:

The current model, or None if no model exists.

Return type:

Model or None

Example

>>> import modelx as mx
>>>
>>> m1 = mx.new_model('Model1')
>>> m2 = mx.new_model('Model2')
>>>
>>> # Get current model
>>> mx.cur_model()
<Model Model2>
>>>
>>> # Set current model by object
>>> mx.cur_model(m1)
<Model Model1>
>>>
>>> # Set current model by name
>>> mx.cur_model('Model2')
<Model Model2>

See also