deflex.model_multi_scenarios¶
-
deflex.
model_multi_scenarios
(scenarios, cpu_fraction=0.2, log_file=None, results=False)[source]¶ Model multi scenarios in parallel. Keep in mind that the memory usage is the critical resource for large models. So start with a low cpu_fraction to avoid memory errors.
Parameters: - scenarios (iterable) – Multiple scenarios to be modelled in parallel.
- cpu_fraction (float) – Fraction of available cpu cores to use for the parallel modelling. A resulting dezimal number of cores will be rounded up to an integer.
- log_file (str) – Filename to store the log file.
- results (bool) – Store an spreadsheet results file (default: False).
Examples
>>> from deflex import fetch_test_files, TEST_PATH >>> fn1 = fetch_test_files("de03_fictive_csv") >>> fn2 = fetch_test_files("de03_fictive_broken.xlsx") >>> my_log_file = os.path.join(TEST_PATH, "my_log_file.csv") >>> my_scenarios = [fn1, fn2] >>> model_multi_scenarios(my_scenarios, log_file=my_log_file) >>> my_log = pd.read_csv(my_log_file, index_col=[0]) >>> good = my_log.loc["de03_fictive_csv"] >>> rv = good["return_value"] >>> datetime.strptime(rv, "%Y-%m-%d %H:%M:%S.%f").year > 2019 True >>> good["trace"] nan >>> os.path.basename(good["dump"]) 'de03_fictive_csv.dflx' >>> good["results"] False >>> broken = my_log.loc["de03_fictive_broken.xlsx"] >>> broken["return_value"].replace("'", "") # doctest: +ELLIPSIS 'ValueError(Missing time series for geothermal (capacity: 12.56) in DE02... >>> broken["trace"] # doctest: +ELLIPSIS 'Traceback (most recent call last)... >>> broken["dump"] nan >>> os.remove(my_log_file) >>> os.remove(good["dump"])