NNDy/scripts/experiment_remote.py
castaneda d84103560e Update scripts/experiment_remote.py
cleaning up of the code and commenting
2025-03-21 15:26:18 +01:00

46 lines
1.5 KiB
Python

#imports for runmanager - labscript
from runmanager_remote import run_experiment
import importlib
_module_cache = {}
# use this script if you want to test a single iteration of NNDy with your sequence and DA,
# if you get the cost dictionary printed at the end as expected, the test is passed
def cost_function(cost_model, hdf5_file):
module_name = cost_model
#looks in the cache if the file was accessed already, otherwise imports the cost function
if module_name not in _module_cache:
try:
module = importlib.import_module(module_name)
cost_func = getattr(module, 'cost')
_module_cache[module_name] = {
"cost_func": cost_func ,
}
except (ModuleNotFoundError, AttributeError) as e:
raise ImportError(f'Failed to load cost function from "{module_name}.py": {e}')
cost_model = _module_cache[module_name]["cost_func"]
return cost_model(hdf5_file)
if __name__ == '__main__':
#provide routine_name and cost_model like in NNDy.py
routine_name = ''
cost_model = ''
#set the input parameters with the values that you want to test in a dictionary
TestVar = {
}
hdf_output_file = run_experiment(routine_name, global_var = TestVar)
print('run finished')
cost = cost_function(cost_model, hdf_output_file)
#print('I am back')
print(cost)