e-courage: modularizing backwards compatability
This commit is contained in:
parent
ef9d73a32c
commit
5863188617
|
|
@ -22,6 +22,8 @@ class Configuration(object):
|
||||||
self.policy_ops = policy_ops
|
self.policy_ops = policy_ops
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
sanitize_config(self)
|
||||||
|
|
||||||
|
|
||||||
def append_configs(sim_configs={}, initial_state={}, seeds={}, raw_exogenous_states={}, env_processes={}, partial_state_update_blocks={}, _exo_update_per_ts=True):
|
def append_configs(sim_configs={}, initial_state={}, seeds={}, raw_exogenous_states={}, env_processes={}, partial_state_update_blocks={}, _exo_update_per_ts=True):
|
||||||
if _exo_update_per_ts is True:
|
if _exo_update_per_ts is True:
|
||||||
|
|
@ -39,8 +41,7 @@ def append_configs(sim_configs={}, initial_state={}, seeds={}, raw_exogenous_sta
|
||||||
env_processes=env_processes,
|
env_processes=env_processes,
|
||||||
partial_state_update_blocks=partial_state_update_blocks
|
partial_state_update_blocks=partial_state_update_blocks
|
||||||
)
|
)
|
||||||
back_compatable_config = sanitize_config(config)
|
configs.append(config)
|
||||||
configs.append(back_compatable_config)
|
|
||||||
elif isinstance(sim_configs, dict):
|
elif isinstance(sim_configs, dict):
|
||||||
config = Configuration(
|
config = Configuration(
|
||||||
sim_config=sim_configs,
|
sim_config=sim_configs,
|
||||||
|
|
@ -50,8 +51,7 @@ def append_configs(sim_configs={}, initial_state={}, seeds={}, raw_exogenous_sta
|
||||||
env_processes=env_processes,
|
env_processes=env_processes,
|
||||||
partial_state_update_blocks=partial_state_update_blocks
|
partial_state_update_blocks=partial_state_update_blocks
|
||||||
)
|
)
|
||||||
back_compatable_config = sanitize_config(config)
|
configs.append(config)
|
||||||
configs.append(back_compatable_config)
|
|
||||||
|
|
||||||
|
|
||||||
class Identity:
|
class Identity:
|
||||||
|
|
@ -124,7 +124,7 @@ class Processor:
|
||||||
return sdf_values, bdf_values
|
return sdf_values, bdf_values
|
||||||
|
|
||||||
if len(partial_state_updates) != 0:
|
if len(partial_state_updates) != 0:
|
||||||
# backwards compatibility
|
# backwards compatibility # ToDo: Move this
|
||||||
partial_state_updates = sanitize_partial_state_updates(partial_state_updates)
|
partial_state_updates = sanitize_partial_state_updates(partial_state_updates)
|
||||||
|
|
||||||
bdf = self.create_matrix_field(partial_state_updates, 'policies')
|
bdf = self.create_matrix_field(partial_state_updates, 'policies')
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,19 @@ from copy import deepcopy
|
||||||
|
|
||||||
|
|
||||||
def sanitize_config(config):
|
def sanitize_config(config):
|
||||||
new_config = deepcopy(config)
|
|
||||||
# for backwards compatibility, we accept old arguments via **kwargs
|
# for backwards compatibility, we accept old arguments via **kwargs
|
||||||
# TODO: raise specific deprecation warnings for key == 'state_dict', key == 'seed', key == 'mechanisms'
|
# TODO: raise specific deprecation warnings for key == 'state_dict', key == 'seed', key == 'mechanisms'
|
||||||
for key, value in new_config.kwargs.items():
|
for key, value in config.kwargs.items():
|
||||||
if key == 'state_dict':
|
if key == 'state_dict':
|
||||||
new_config.initial_state = value
|
config.initial_state = value
|
||||||
elif key == 'seed':
|
elif key == 'seed':
|
||||||
new_config.seeds = value
|
config.seeds = value
|
||||||
elif key == 'mechanisms':
|
elif key == 'mechanisms':
|
||||||
new_config.partial_state_updates = value
|
config.partial_state_updates = value
|
||||||
|
|
||||||
if new_config.initial_state == {}:
|
if config.initial_state == {}:
|
||||||
raise Exception('The initial conditions of the system have not been set')
|
raise Exception('The initial conditions of the system have not been set')
|
||||||
|
|
||||||
del config
|
|
||||||
return new_config
|
|
||||||
|
|
||||||
|
|
||||||
def sanitize_partial_state_updates(partial_state_updates):
|
def sanitize_partial_state_updates(partial_state_updates):
|
||||||
new_partial_state_updates = deepcopy(partial_state_updates)
|
new_partial_state_updates = deepcopy(partial_state_updates)
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ class Executor:
|
||||||
config_idx += 1
|
config_idx += 1
|
||||||
|
|
||||||
if self.exec_context == ExecutionMode.single_proc:
|
if self.exec_context == ExecutionMode.single_proc:
|
||||||
|
# ToDO: Deprication Handler - "sanitize" in appropriate place
|
||||||
tensor_field = create_tensor_field(partial_state_updates.pop(), eps.pop())
|
tensor_field = create_tensor_field(partial_state_updates.pop(), eps.pop())
|
||||||
result = self.exec_method(simulation_execs, var_dict_list, states_lists, configs_structs, env_processes_list, Ts, Ns)
|
result = self.exec_method(simulation_execs, var_dict_list, states_lists, configs_structs, env_processes_list, Ts, Ns)
|
||||||
return result, tensor_field
|
return result, tensor_field
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue