labscript-suite / runmanager

𝗿𝘂𝗻𝗺𝗮𝗻𝗮𝗴𝗲𝗿 is an intuitive graphical interface for controlling 𝘭𝘢𝘣𝘴𝘤𝘳𝘪𝘱𝘵 𝘴𝘶𝘪𝘵𝘦 experiments. Includes multi-dimensional parameter scans and a remote programming interface for automation.
http://labscriptsuite.org
Other
3 stars 45 forks source link

Synchronous compilation of a shot #114

Open dihm opened 4 months ago

dihm commented 4 months ago

I'm currently working with a student on a modification to the installer that will automatically compile the example_apparatus connection table during labscript_profile_create. Goal is to make initial install of labscript less annoying by ensuring BLACS can open with something without requiring manual steps.

Trying things out, it seemed like the synchronous compile functions in runmanager would be perfect (runmanager.compile_labscript and/or runmanager.compile_labscript_with_globals_files). But these functions are not used anywhere in the suite and don't appear to work out of the box.

import labscript
import runmanager
from pathlib import Path

folder = Path("C:\\mydir\\userlib\\labscriptlib\\example_apparatus\\")
script_path = folder.joinpath("connection_table.py")
output_h5_path = folder.joinpath("connection_table.h5")

labscript.labscript_init(output_h5_path, labscript_file=script_path, new=True, load_globals_values=False)
runmanager.compile_labscript(script_path, output_h5_path)
labscript.labscript_cleanup()

Gives the following error

Compilation failed with errors:
Traceback (most recent call last):
  File "C:\Users\naqsL\labscript-suite\userlib\labscriptlib\example_apparatus\connection_table.py", line 27, in <module>
    stop(1.0)
  File "C:\Users\naqsL\src\labscript-suite\labscript\labscript\labscript.py", line 704, in stop
    generate_code()
  File "C:\Users\naqsL\src\labscript-suite\labscript\labscript\labscript.py", line 504, in generate_code
    raise LabscriptError('hdf5 file for compilation not set. Please call labscript_init')
labscript.utils.LabscriptError: hdf5 file for compilation not set. Please call labscript_init

Question is: are we just using these functions incorrectly, or are they actually deprecated and should just be deleted/reworked?

philipstarkey commented 4 months ago

Yep, those functions look completely broken and should be replaced or removed. The correct way to do it is inside the batch_compiler.py file.

I know you said you want to do it synchronously, but I would consider still using the async functions (that spawn a new process running the batch_compiler.py file) and just waiting for it to complete in the terminal. I'm pretty sure you should be able to redirect the compilation output to the terminal as well? The advantage of doing this is that if it crashes badly, it won't take down the whole command and you can output useful error messages and/or continue on with other things.

dihm commented 4 months ago

Makes sense. I'll put together a PR to remove the synchronous functions. I may also add some default options to labscript_compile_* functions so that they just work when compiled naively.