m-labs / artiq

A leading-edge control system for quantum information experiments
https://m-labs.hk/artiq
GNU Lesser General Public License v3.0
428 stars 199 forks source link

Run only analyse part of experiment #428

Closed r-srinivas closed 8 years ago

r-srinivas commented 8 years ago

Is there anyway of choosing to run only the analyse part of the experiment? It would be useful to be able to rerun just the analyse part sometimes to tweak fitting parameters and to have the option of saving the results of the fit. I have the following experiment here,

from artiq.experiment import *
import numpy as np
from scipy.optimize import curve_fit

def fit(x, f):
        return (np.cos(f*x/2))**2

class Fit_Test(EnvExperiment):

    def build(self):
        self.setattr_device("scheduler")        

        self.setattr_argument("rabi_frequency", NumberValue(1, min=0.5, max=5))
        self.setattr_argument("points", NumberValue(100, min=0.5, max=1000, ndecimals=0))
        self.setattr_argument("fit_frequency", NumberValue(1, min=0.5, max=5))
        self.setattr_argument("save", BooleanValue(True))

    def run(self):
        l = int(self.points)
        self.set_dataset("population", np.full(l, np.nan), broadcast=True)
        self.set_dataset("time", np.full(l, np.nan), broadcast=True)
        for i in range(l):
            time = i*2*np.pi/l
            population = (np.cos(self.rabi_frequency*time/2))**2
            self.mutate_dataset("time", i, time)
            self.mutate_dataset("population", i, population)

    def analyze(self):       
        x = self.get_dataset("time")
        y = self.get_dataset("population")
        popt, pcov = curve_fit(fit, x, y, p0=self.fit_frequency)
        population_fit = fit(x, popt)
        print(popt)
        self.set_dataset("population_fit", population_fit, broadcast=True)
        if self.save:
            self.set_dataset("flopping_frequency", float(popt), broadcast=True, persist=True)

It only saves the fit if save is checked but if I initially didn't save the fit and want to save it later I have to rerun the whole experiment. Is there a way of doing this without creating a separate experiment?

sbourdeauducq commented 8 years ago

See #230. Modifying the master's dataset database automatically from the browser is not planned, though.