Compilation in runmanager is slow when using scipy.interpolate.interp1d

40 ملاحظات
پہلے نہ پڑھے ہوئے پیغام پر جائیں

Lars Kohfahl

نہ پڑھا ہوا،
3 مئی، 2021، 12:43:38 PM3/5/21
بنام the labscript suite
Hi, I am currently trying to speed up our runmanager compilation process. the reason is that compiling an experiment script takes roughly 4.5sec but our shots are executed faster which results in blacs having an empty queue and waiting for new compiled shots.
I have tested some things and worked myself through the compilation process to find the bottle neck: We have a unit-conversion class that uses scipy.interpolate.interp1d functions to account for non-linear beahviour of e.g. a VCO. Using this conversion class slows down script compilation from roughly 2sec to 4.5sec. I thought first the reason is the function but printing the time stamps in the compilation process revealed that it is not. Actually the problem is "if compiler.save_hg_info" in the labscript-function save_labscripts.
When using our unit-conversion-class, save_hg_info is executed 9 times and otherwise just 3 times. Each execution takes 400ms.
Now I am wondering: Can someone explain what this save_hg_info is needed for (didn't we move to git for version control?), why it is so slow in general and why is it  called a different number if times depending on the unit_conversion class.

I have attached the unit_conversion_class for clarification.

Best regards,
Lars
apq_laser_unitconv.py

Zak V

نہ پڑھا ہوا،
3 مئی، 2021، 5:33:28 PM3/5/21
بنام the labscript suite
Hi Lars,

There's a bunch of helpful information on the related github issue #38 but I'll try to summarize some of the more important points and answer your questions here.

Labscript (the python package) saves a copy of your labscript (i.e. your python file that describes your sequence), as well as copies of some other modules that it imports, into the shot's hdf5 file in its 'labscriptlib' group. That's great because it gives you a record of the instructions used to compile the shot. In addition to that, by default labscript saves the output of some mercurial functions to the hdf5 file as attributes of the objects in the hdf5 file's 'labscriptlib' group. This is useful because you can see which mercurial commit you were on when you compiled the shot and see if there were any changes in your working version of the code since your last commit. That doesn't really tell you much that the full copies of the files didn't already tell you, but it can still be helpful. Not surprisingly, the code to do this was written back when labscript version control was done with mercurial, which is why mercurial is used there.

Unfortunately, the mercurial commands can take a while to execute and will often be the slowest part of the compilation. If you import more of your modules, the mercurial commands will be run on more files. That's why you see the number of mercurial command executions increase when you use your unit conversion class. Labscript will attempt to run those commands even if you don't use mercurial for version management of your labscriptlib, and it will attempt to run them even if you don't have mercurial installed at all.

There are a few options for speeding this up. The simplest is to set `labscript.compiler.save_hg_info = False` at the top of your labscript. This will prevent the mercurial commands from being run at all, which speeds things up at the cost of not saving the mercurial information. That doesn't cost you anything though if you don't use mercurial for version controlling your labscriptlib.

Alternatively, labscript PR #72 (which is still under review and hasn't been merged into mainline labscript) resolves this issue another way. It caches the output of the mercurial commands and only re-runs the commands when a file changes. So the first shot compilation after starting runmanager may be slow still but the subsequent ones will be much faster because the mercurial commands won't be re-run. The mercurial information will still be saved to the shot files though using the cached results. That PR also adds support for doing this same thing with git instead of mercurial, which is helpful if you use git to manage your labscriptlib. If you have a developer labscript install and want to go this route, checkout the code in the PR, then optionally add the following section to your labconfig, setting the options to True or False as desired:

```
[labscript]
save_hg_info = False
save_git_info = True
```

If you need additional compilation speedup, Phil made some further optimizations in labscript PR #73 which you can try out as well.

Cheers,
Zak

Lars Kohfahl

نہ پڑھا ہوا،
4 مئی، 2021، 4:07:28 AM4/5/21
بنام the labscript suite
Hi Zak,
thanks for the detailed explanation. I wasn't aware of the solutions already found. I will at first deactivate save_hg_info and, if time allows test PR #72.

Lars
سبھی کو جواب دیں
مصنف کو جواب دیں
فارورڈ کریں
0 نئے پیغامات