I'm using the scheduler for the first time, and can't get it to work properly. When I run the experiment below,

def build(self):
        # Import core and scheduler
        self.setattr_device("core")
        self.setattr_device("scheduler")


    def prepare(self):
        self.delay = self.get_dataset("parameters.delay")

        # Parameters for experiments
        detection_time_us = 500
        pmt_reps = 100

        # Define bright pmt experiment and its inputs for the scheduler
        self.expid_bright_ion = {
            "file": "Z:\\Artiq\\Artiq_WS\\repository\\detection_check.py",
            "class_name": "Detection",
            "arguments": {"detection_time": detection_time_us,
                          "n_reps": pmt_reps,
                          "shutter935_open": True,
                          "use_camera": False,
                          "show_hist": False},
            "log_level": self.scheduler.expid["log_level"],
            # "repo_rev": "N/A"
        }


    @kernel
    def run(self):
        # Initialize core timeline
        self.core.break_realtime()
        delay(self.delay * us)
        self.core.reset()
        delay(self.delay * us)

        # Run bright ion pmt detection experiment
        self.scheduler.submit("main", expid=self.expid_bright_ion)

The experiment with the scheduler schedules does actually run successfully, but this experiment throws the following error:

root:Terminating with exception (RPCReturnValueError: type mismatch: cannot serialize 218628 as None (<function Scheduler.submit at 0x000002564A2A0CA0> has returned 218628))
Traceback (most recent call last):
  File "C:\Users\iontrap\Anaconda3\envs\artiq6\lib\site-packages\artiq\master\worker_impl.py", line 300, in main
    exp_inst.run()
  File "C:\Users\iontrap\Anaconda3\envs\artiq6\lib\site-packages\artiq\language\core.py", line 54, in run_on_core
    return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs)
  File "C:\Users\iontrap\Anaconda3\envs\artiq6\lib\site-packages\artiq\coredevice\core.py", line 137, in run
    self.comm.serve(embedding_map, symbolizer, demangler)
  File "C:\Users\iontrap\Anaconda3\envs\artiq6\lib\site-packages\artiq\coredevice\comm_kernel.py", line 642, in serve
    self._serve_rpc(embedding_map)
  File "C:\Users\iontrap\Anaconda3\envs\artiq6\lib\site-packages\artiq\coredevice\comm_kernel.py", line 563, in _serve_rpc
    self._send_rpc_value(bytearray(return_tags),
  File "C:\Users\iontrap\Anaconda3\envs\artiq6\lib\site-packages\artiq\coredevice\comm_kernel.py", line 432, in _send_rpc_value
    check(value is None,
  File "C:\Users\iontrap\Anaconda3\envs\artiq6\lib\site-packages\artiq\coredevice\comm_kernel.py", line 418, in check
    raise RPCReturnValueError(
artiq.coredevice.comm_kernel.RPCReturnValueError: type mismatch: cannot serialize 218628 as None (<function Scheduler.submit at 0x000002564A2A0CA0> has returned 218628)

218528 is the rid of the experiment being scheduled. Unfortunately, the traceback is rather opaque.

Try adding a -> TInt32 return type annotation to the scheduler.submit method (inside ARTIQ, worker_impl.py).

But I'm not really sure if this is usable as a RPC anyway due to expid not being a kernel supported type. You may want to define your own RPC that calls submit.

5 days later

It seems like my approach to using the scheduler is not how it was intended to be used. What's the correct way/syntax to use the scheduler to schedule an experiment?

What I was hoping to accomplish was to schedule multiple experiments and then have those experiments analyzed together. It seems like the scheduler can put the experiments in the pipeline, but not collect the results for a joint analysis. What would be the correct way to go about this?

    ajras What's the correct way/syntax to use the scheduler to schedule an experiment?

    The issue you have in the code above is with RPC and kernel types, not with the scheduler specifically. Just don't call the scheduler from a kernel directly since the scheduler.submit method isn't designed for RPC.

    ajras It seems like the scheduler can put the experiments in the pipeline, but not collect the results for a joint analysis. What would be the correct way to go about this?

    Can you just import the sub-experiments and call their methods directly?

    Ah, thank you!! I should make a wrapper function for the scheduler.submit then, somewhat like the docs example?

    I hadn't thought of importing the sub-experiments directly. That sounds like a promising direction! Thank you for the suggestion!

    5 days later

    @sb10q I'm running into some issues when initializing an experiment within another experiment. What's the correct way to do this? If I simply import the experiment and initialize it inside another experiment, I get the error

    Traceback (most recent call last):
      File "C:\Users\iontrap\Anaconda3\envs\artiq6\lib\site-packages\artiq\master\worker_impl.py", line 295, in main
        exp_inst.prepare()
      File "Z:\Artiq\Artiq_WS\repository\calibrations\calibration.py", line 53, in prepare
        self.det_bright_exp = Detection()
    TypeError: __init__() missing 1 required positional argument: 'managers_or_parent'

    How do a set the managers/parent correctly? And here's what I'm running

    from artiq.experiment import *
    from detection_check import Detection  # experiment I want to run in "Calibration" experiment
    
    class Calibration(EnvExperiment):
        """Calibration"""
    
    
        def build(self):
            self.setattr_device("core")
    
    
        def prepare(self):
            # Create instance of a detection experiment (which is EnvExperiment)
            self.det_bright_exp = Detection()
            # Set inputs for Detection class experiment
            self.det_bright_exp.detection_time = detection_time_us
            self.det_bright_exp.pmt_reps = pmt_reps
            self.det_bright_exp.shutter935_open = True
            self.det_bright_exp.use_camera = False
            self.det_bright_exp.show_hist = False
            # Prepare Detection's prepare method
            self.det_bright_exp.prepare()

    self.det_bright_exp = Detection(self)

    Note that sub-objects do not need to be Experiments at all, unless you also want to run them independently in the dashboard/master.

    Perfect. Thank you! It's working great 🙂