How to re-run experiments?
randym3110 opened this issue · 0 comments
randym3110 commented
I've run the script and saved results in a *.tar.gz file. I would like to use the same values stored in the "experiments" file to re-run the simulations. I´ve tried out the following script, but the new simulations do not use the previous results:
import os
import shutil
from ema_workbench import ema_logging, perform_experiments, save_results, load_results
from ema_workbench.em_framework import RealParameter, ScalarOutcome, SequentialEvaluator
if name == 'main':
ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
ema_logging.log_to_stderr(ema_logging.INFO)
# Define the path to the previous results file
results_path = 'D:/r_munoz/australia/results/var_49k_ok_2.tar.gz'
# Load the previous results
previous_results = load_results(results_path)
# Extract the uncertainty and lever values from the previous results
uncertainties = previous_results[0]['u_climate_sce']
levers = previous_results[0]['frac_tree']
# Create a new model instance
model = Model('simpleModel', function=shaman)
# Set the uncertainties and levers based on the previous results
model.uncertainties = [
RealParameter('u_climate_sce', min(uncertainties), max(uncertainties)),
RealParameter('c_var', min(previous_results[0]['c_var']), max(previous_results[0]['c_var'])),
RealParameter('hmax_var', min(previous_results[0]['hmax_var']), max(previous_results[0]['hmax_var'])),
RealParameter('imax_var', min(previous_results[0]['imax_var']), max(previous_results[0]['imax_var'])),
RealParameter('alfa_var', min(previous_results[0]['alfa_var']), max(previous_results[0]['alfa_var']))
]
model.levers = [
RealParameter('frac_tree', min(levers), max(levers)),
RealParameter('k_vol', min(previous_results[0]['k_vol']), max(previous_results[0]['k_vol']))
]
# Specify the outcomes
model.outcomes = [
ScalarOutcome('return_period'),
ScalarOutcome('price_policy')
]
# Specify the number of repetitions and scenarios
n_reps = 70
n_scenarios = 70
# Clear the previous results directory
shutil.rmtree('D:/r_munoz/australia/results/')
# Run the model and save the results
evaluator = SequentialEvaluator(model)
results = perform_experiments(model, n_scenarios, n_reps, evaluator=evaluator)
print('end!')`