Running MIMOSA
Base run
A basic run of MIMOSA requires 4 steps: loading the parameters, building the model instance, solving the model and finally saving the output. With this code, the default parameter values are used (see Parameter reference).
from mimosa import MIMOSA, load_params
params = load_params() # (1)!
model1 = MIMOSA(params) # (2)!
model1.solve() # (3)!
model1.save("run1") # (4)!
- Read the default parameters
- Build the model using the parameters
- Once the model is built, send the model to the solver.
Note that if you use the NEOS solver, use the syntaxmodel1.solve(use_neos=True, neos_email="your.email@email.com") - Export the output to the file output/run1.csv
ACCREU cost-benefit analysis
ACCREU adaptation expenditure is a solver control by default, and solve()
therefore optimises mitigation and adaptation jointly. To use the ordered
cost-benefit workflow, select analytical adaptation and the sequential strategy.
One call to solve() then first optimises mitigation without adaptation and
evaluates analytical optimal adaptation along the resulting pathway. The final
values are loaded into the public model, so they can be saved normally:
from mimosa import MIMOSA, load_params
params = load_params()
params["model structure"]["damage module"] = "ACCREU"
options = params["economics"]["damages"]["accreu"]
options["adaptation"] = "sectoral"
options["adaptation_determination"] = "analytical_optimum"
options["cba_strategy"] = "mitigation_then_adaptation"
model = MIMOSA(params)
model.solve()
model.save("run_accreu_cba")
For an adaptation-only scenario, select analytical_optimum and call
run_simulation() without controls. run_nopolicy_baseline() always disables
both mitigation and adaptation so avoided damages have a consistent reference.
The sequential strategy rejects a fixed carbon budget. Transferred pathways
remain available as model.workflow_control_values for diagnostics.
The joint strategy also supports analytical_optimum. In that combination,
MIMOSA performs one ordinary optimisation: the solver chooses mitigation while
adaptation responds through its analytical optimum equations. This differs from
mitigation_then_adaptation, which first chooses mitigation in a model without
adaptation.
Configuring the time grid
The time.dt parameter sets the initial timestep length, while time.periods
optionally maps change years to the new timestep length used after that year.
The default grid uses five-year timesteps through 2050 and ten-year timesteps
thereafter:
params = load_params()
params["time"]["start"] = 2025
params["time"]["end"] = 2150
params["time"]["dt"] = 5
params["time"]["periods"] = {2050: 10}
Additional changes can be added to the mapping. For example, with end = 2290,
{2050: 10, 2150: 20} uses five-year timesteps through 2050, ten-year
timesteps through 2150, and twenty-year timesteps thereafter. Every change year
and the final year must lie on the resulting grid. Within model equations,
m.period_length[t] gives the number of years between timestep t - 1 and t;
it is zero for the initial timestep.
Reading the output
Once the script above has finished running, it has produced two output files in the folder output: run1.csv and run1.csv.params.json. The latter is a JSON file with all the input parameters used for this particular run (for reproducibility), together with the MIMOSA version, scenario type and runtime in seconds. For optimisation output, the runtime measures the complete model.solve() call and excludes model creation and prerunning. For simulation output, it measures the model.run_simulation() call that produced the saved result. The CSV file contains all the output data. Every variable in MIMOSA is saved in this file in a format similar to IAMC data format:
output/run1.csv
| Variable | Region | Unit | 2020 | 2025 | 2030 | 2035 | 2040 | 2045 | 2050 | 2055 | 2060 | 2065 | 2070 | 2075 | 2080 | 2085 | 2090 | 2095 | 2100 | 2105 | 2110 | 2115 | 2120 | 2125 | 2130 | 2135 | 2140 | 2145 | 2150 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| regional_emissions | CAN | GtCO2/yr | 0.511577 | 0.383683 | 0.255789 | 0.155544 | 0.136527 | 0.113384 | 0.0944834 | 0.0845257 | 0.077836 | 0.0694752 | 0.0588413 | 0.0469933 | 0.0359533 | 0.0269266 | 0.0199594 | 0.014565 | 0.0104499 | 0.0517489 | 0.0517486 | 0.0517485 | 0.0517484 | 0.0517483 | 0.0517482 | 0.0517481 | 0.051748 | 0.0517478 | 0.0517476 |
| regional_emissions | USA | GtCO2/yr | 5.39382 | 4.04537 | 2.69691 | 1.34846 | 0.789513 | 0.649695 | 0.531854 | 0.430432 | 0.341586 | 0.262853 | 0.195861 | 0.142273 | 0.101621 | 0.072636 | 0.0549502 | 0.0495887 | 0.0582421 | 0.534749 | 0.534749 | 0.534749 | 0.534749 | 0.534749 | 0.534749 | 0.534749 | 0.534749 | 0.534748 | 0.534748 |
| regional_emissions | MEX | GtCO2/yr | 0.572878 | 0.429658 | 0.286439 | 0.250682 | 0.235195 | 0.210891 | 0.184067 | 0.159748 | 0.137097 | 0.114491 | 0.0904155 | 0.0650686 | 0.0402638 | 0.0171455 | -0.00403092 | -0.0236268 | -0.0413935 | 6.53385e-05 | 6.49712e-05 | 6.47857e-05 | 6.46547e-05 | 6.45457e-05 | 6.4444e-05 | 6.4339e-05 | 6.42181e-05 | 6.40555e-05 | 6.37559e-05 |
| ... | ... |
These output files can be easily imported for plotting software (like using Plotly in Python). An easier way, however, to quickly visualise and compare MIMOSA outputs, is by using the MIMOSA Dashboard. After opening the online Dashboard, simply drag and drop all output files to the drag-and-drop input to visualise one or multiple MIMOSA output files. Also include the parameter files to directly see the difference in input parameters.
Derived global variables
Add derived regional and missing global series to the exported results.
Indirect costs are attributed to damage, mitigation, and adaptation using their shares of cumulative direct costs. Only costs before the current time step are included, and annual cost flows are weighted by the length of the interval over which they affect capital accumulation. Global series are the baseline-GDP-weighted aggregations of the regional attributed costs. All attributed series are zero in the initial period or when cumulative direct costs are zero. Damage and adaptation shares are zero when damages are ignored; a missing adaptation-cost series is also treated as zero.
Some variables are defined only by time and region because their global counterparts are not needed while solving the model. To keep selected variables available at the global level without adding equations to the optimisation problem, MIMOSA derives the corresponding series while exporting the results.
A variable can be aggregated when it:
- is a Pyomo variable indexed by time and region;
- does not already have a
global_<variable name>counterpart.
Regional population quantities, such as variables measured in billion
people, are summed directly:
Regional cost variables are aggregated when they have fraction_of_GDP as
their unit and contain costs in their name.
If an exported <variable name>_abs quantity exists, its regional values are
used as the numerator:
Otherwise, absolute regional costs are reconstructed from the GDP-relative values:
Regional adaptation effectiveness variables measured as
fraction_of_gross_damages are weighted by the corresponding sector's
absolute gross damages. The corresponding gross-damage variable is inferred
from the name: <sector>_adaptation_level uses
<sector>_damage_costs_gross. If global gross damages are zero, the exported
avoided fraction is NaN.
The resulting global_* rows are added only to the exported CSV file. They
are not added as Pyomo components and therefore cannot be accessed as
attributes of the model. Global variables that already exist in the model are
exported normally and are not replaced by this calculation.
Source code in mimosa/export/save.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |