Hi all,
Consider this post a general ask for advice around handling errors and experiment deletions. We run an ion trap, and at times when writing new experiments we will have exceptions raised. This can be problematic if the exception is raised at an inconvenient time, such as when the ion is pumped into a dark state, and depending on how long it takes for us to reset everything it may cause the ion to heat-up and be ejected. To help avoid this, what I would like to do is have a code structure that handles exceptions (and exceptionless deletions) such that we run some code that will bring the hardware into a better state before raising the exception.
My first attempts of this were to have experiments be written as a seperate class from the runtime experiment, where the runtime experiment handles the exceptions. For example
from artiq.experiment import *
from artiq_common_methods.experiments import Example, Termination
class GracefulTermination(EnvExperiment):
def build(self):
self.experiment = Example(self)
self.setattr_device("scheduler")
self.termination = Termination(self)
def run(self):
try:
self.experiment.run()
except Exception as e:
self.termination.yb171(e)
except SystemExit as e:
self.termination.yb171(e)
In this example the GracefulTermination
experiment is what is run, but in it's run
method it calls self.experiment.run()
. It then just has try, except checks to handle the exceptions. If an exception is called then it calls a termination method which would set the hardware in such a way that the ion remains stable after the error, then it raises the exception.
The current issue with this implimentation is that it doesn't handle exceptionless deletions, where you would use the scheduler to delete an experiment, and it does so successfully without raising any errors. In this case the hardware may still be left in an underisable state. I don't know of a good way to intercept this and handle it correctly.
I'd also like to know if there is a better way of doing this? Is there a method I can write that would overwright a parent method similar to what we do with run
and EnvExperiment
(from what I've seen there isn't)? Is there a way of having the scheduler handle it etc.
Kind regards,
Liam