NNDy/scripts/runmanager_remote.py
castaneda a9fd8cebed automatic waiting period, with newRun_NNDy.py
integrated with newRun_NNDy.py that is run by lyse and handles the halting of the execution of the script while the shot is running
2025-03-21 15:53:14 +01:00

74 lines
2.1 KiB
Python

#this file runs the experiment through runmanager
from datetime import datetime
import time
from os import listdir
import zmq
#import for labscript
from labscript.labscript import labscript_init
from runmanager import remote
def run_experiment(routine_name, global_var):
hdf_path = f"C:\\Users\\DyLab\\PrepLab\\Experiments\\NNDy_TestSetup\\{routine_name}"
#this way it should be loading the routine based on past executions, with the possibility of only changing the global variables
#it's possible that there could be some issue if the script is changed before running MLOOP
#without further insights on this, it's recommended to always run the sequence once from runmanager GUI before running NNDy
labscript_init(hdf_path,
new = True)
runmanager_client = remote.Client()
runmanager_client.set_view_shots(False)
runmanager_client.set_globals(global_var)
#print of all the shot globals
print(f'globals: \n {runmanager_client.get_globals()}')
#set the path to the shot that will be created
hdf_path = runmanager_client.get_shot_output_folder()
runmanager_client.engage()
#print('engaged')
print(f'engaged, now waiting')
#newRun_NNDy.py will make sure that the script is put on hold until the shot isn't sent to lyse
#ask Jianshun for further info
url = "tcp://" + str("127.0.0.1") + ":" + str(24325)
context = zmq.Context.instance()
server = context.socket(zmq.REP)
server.bind(url)
msg = server.recv_json()
server.send_json(True)
server.unbind(url)
server.close()
print('waiting time is over')
#returns and retrieve the hdf5 file of the shot
try:
hdf_files = listdir(hdf_path)
if len(hdf_files) == 0:
raise ModuleNotFoundError
else:
if len(hdf_files) > 1:
raise ImportError
hdf_file = hdf_path + "/" + hdf_files[0]
except (ModuleNotFoundError, ImportError) as e:
raise Error(f'An error has occured while importing from hdf output folder: {e}')
return hdf_file