iode.Simulation.model_simulate
- Simulation.model_simulate(from_period: str | Period, to_period: str | Period, list_eqs: str | List[str] = None, quiet: bool = False) bool[source]
Run the simulation of a model for a given sample.
To simulate a model, all equations of the model must have been loaded or created. In addition, all the variables and scalars used in the model equations must have been loaded or created. Values of exogenous variables and of scalar cannot be \(NA\) (Not Available) over the simulation sample.
- Parameters:
- from_periodstr or Period
The starting period for the simulation.
- to_periodstr or Period
The ending period for the simulation.
- list_eqsstr or list(str), optional
List of equations representing the model. Default to empty (all equations).
- quietbool, optional
If True, suppresses the log messages during the simulation process. Default to False.
- Returns:
- bool
True if the simulation is successful, False otherwise.
Examples
>>> from iode import SAMPLE_DATA_DIR, equations, identities, lists, 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 >>> lists.load(f"{SAMPLE_DATA_DIR}/fun.lst") Loading .../fun.lst 17 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
>>> # exogenous variable >>> equations["UY"].lec 'UY := NATY-NDOMY-NIY-NGY-(EFXY-EFMY)-NFY' >>> # reset values >>> 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
>>> # endogenous variable >>> identities["XNATY"] Identity('grt NATY') >>> 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
>>> # simulate the model (no reordering) >>> 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 >>> 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