iode.Simulation.model_exchange

Simulation.model_exchange(list_exo: str | List[str] = None) bool[source]

Set a list of endogenous-exogenous pairs for goal seeking. For each pair, the status of the variables is exchanged: endogenous becomes exogenous and vice versa. This enables the model to be run through known endogenous values and to deduce the necessary values for the associated exogenous variables. The exogenous variables take on the value calculated over the entire workspace period.

Parameters:
list_exostr or list(str)

List of endogenous-exogenous pairs. Each pair must be written as endogenous_name-exogenous_name. If the passed list is empty, the internal list of endogenous-exogenous pairs is reset. Default to None (empty).

Examples

>>> from iode import SAMPLE_DATA_DIR, equations, identities, scalars, variables 
>>> from iode import Simulation
>>> equations.load(f"{SAMPLE_DATA_DIR}/fun.eqs")
Loading .../fun.eqs
274 objects loaded 
>>> identities.load(f"{SAMPLE_DATA_DIR}/fun.idt")
Loading .../fun.idt
48 objects loaded 
>>> scalars.load(f"{SAMPLE_DATA_DIR}/fun.scl")
Loading .../fun.scl
161 objects loaded 
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading .../fun.var
394 objects loaded
>>> equations["UY"].lec
'UY := NATY-NDOMY-NIY-NGY-(EFXY-EFMY)-NFY'
>>> identities["XNATY"]
Identity('grt NATY')
>>> # endogenous variable
>>> variables["XNATY", "2000Y1:2015Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 2000Y1:2015Y1
mode: LEVEL

 name       2000Y1  2001Y1  2002Y1  ...  2013Y1  2014Y1  2015Y1
XNATY         0.22    0.70    0.40  ...   -0.20   -0.20   -0.20

>>> # reset exogeneous variable
>>> variables["UY", "2000Y1:2015Y1"] = 0.0
>>> variables["UY", "2000Y1:2015Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 2000Y1:2015Y1
mode: LEVEL

name        2000Y1  2001Y1  2002Y1  ...  2013Y1  2014Y1  2015Y1
UY            0.00    0.00    0.00  ...    0.00    0.00    0.00
>>> simu = Simulation()
>>> success = simu.model_simulate("2000Y1", "2015Y1")
Linking equations ....
Calculating SCC...
Calculating SCC... -> #PRE 31 - #INTER 204 - #POST 39
Reordering interdependent block...
Reordering interdependent block...
2000Y1: 1 iters - error =    1.342 - cpu=...ms
2000Y1: 2 iters - error =   0.4115 - cpu=...ms
2000Y1: 3 iters - error =   0.5272 - cpu=...ms
...
2015Y1: 19 iters - error =  0.00267 - cpu=...ms
2015Y1: 20 iters - error =  0.00141 - cpu=...ms
2015Y1: 21 iters - error = 0.0006749 - cpu=...ms
>>> success
True
>>> # endogenous variable (unchanged)
>>> variables["XNATY", "2000Y1:2015Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 2000Y1:2015Y1
mode: LEVEL

 name       2000Y1  2001Y1  2002Y1  ...  2013Y1  2014Y1  2015Y1
XNATY         0.22    0.70    0.40  ...   -0.20   -0.20   -0.20

>>> # exogeneous variable
>>> variables["UY", "2000Y1:2015Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 2000Y1:2015Y1
mode: LEVEL

name        2000Y1  2001Y1  2002Y1  ...  2013Y1  2014Y1  2015Y1
UY          624.18  645.05  661.61  ...  549.24  533.37  525.13
>>> # exchange UY and XNATY
>>> success = simu.model_exchange("UY-XNATY")
>>> success
True
>>> # update endogenous variable (now UY)
>>> variables["UY", "2000Y1:2002Y1"] = [630.0, 650.0, 670.0]
>>> # rerun simulation
>>> success = simu.model_simulate("2000Y1", "2015Y1")
Linking equations ....
Calculating SCC...
Calculating SCC... -> #PRE 30 - #INTER 204 - #POST 40
Reordering interdependent block...
Reordering interdependent block...
2000Y1: 1 iters - error =  0.09305 - cpu=...ms
2000Y1: 2 iters - error = 0.001205 - cpu=...ms
2000Y1: 3 iters - error =  0.00138 - cpu=...ms
...
2015Y1: 23 iters - error = 0.001306 - cpu=...ms
2015Y1: 24 iters - error = 0.001463 - cpu=...ms
2015Y1: 25 iters - error = 0.0007763 - cpu=...ms
>>> # exogeneous variable (now XNATY)
>>> variables["XNATY", "2000Y1:2015Y1"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 2000Y1:2015Y1
mode: LEVEL

 name       2000Y1  2001Y1  2002Y1  ...  2013Y1  2014Y1  2015Y1
XNATY         0.35    0.67    0.51  ...   -0.20   -0.20   -0.20