Update scripts/experiment_remote.py

cleaning up of the code and commenting
This commit is contained in:
castaneda 2025-03-21 15:26:18 +01:00
parent 49bc1ec08a
commit d84103560e

View File

@ -1,34 +1,46 @@
#imports for runmanager - labscript #imports for runmanager - labscript
from runmanager_remote import run_experiment from runmanager_remote import run_experiment
from lyse import *
import pandas as pd import importlib
_module_cache = {}
import TestDA
import xarray as xr # 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
if __name__ == '__main__':
def cost_function(cost_model, hdf5_file):
routine_name = 'TestSetup' module_name = cost_model
TestVar = {'T_wlm': 1, #looks in the cache if the file was accessed already, otherwise imports the cost function
'delta_freq': 0, if module_name not in _module_cache:
'wait_AWG': 5, try:
'buffer_time': 5, module = importlib.import_module(module_name)
'carrier_amp': 2 cost_func = getattr(module, 'cost')
} _module_cache[module_name] = {
"cost_func": cost_func ,
}
hdf_output_file = run_experiment(routine_name, global_var = TestVar) except (ModuleNotFoundError, AttributeError) as e:
raise ImportError(f'Failed to load cost function from "{module_name}.py": {e}')
print('run finished')
cost_model = _module_cache[module_name]["cost_func"]
#df = pd.DataFrame(lyse_run.get_result('wlm', 'wlm_df'), columns = ['timestamp [s]','wavelength [nm]', 'frequency [THz]'])
#print(df) return cost_model(hdf5_file)
#results = TestDA.analysis(hdf_output_file) if __name__ == '__main__':
cost = TestDA.cost(hdf_output_file) #provide routine_name and cost_model like in NNDy.py
#print('I am back') 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) print(cost)