Accessing the scan inside a scan model

The scan experiment that created a scan model can always be accessed via the attribute self._scan inside the scan model (once the _initialize() method of the scan class has executed). This can be particularly useful in attributes defined as properties via @property. Checks can then be performed on attributes of the scan class inside @property methods in the scan model to dynamically determine the appropriate value for a particular configuration.

For example, the fit function to use for fitting could be set via a GUI argument using this method:

from artiq.experiment import *
from scan_framework import *

class MyModel(ScanModel):
    namespace = "my_namespace"

        if self._scan.fit_function == 'Sin':
            return fitting.Sine
        if self._scan.fit_function == 'RabiSpectrum':
            return fitting.RabiSpectrum


class MyScan(Scan1D, EnvExperiment):

    def build(self):
        self.setattr_argument('fit_function', EnumerationValue([


Alternatively, the same can be accomplished by simply setting the scan model’s fit_function attribute directly in the scan based off the fit_function argument. The ability to access the scan instance via self._scan within a scan model may be necessary or more convenient, however, in other circumstances.