artiq icon indicating copy to clipboard operation
artiq copied to clipboard

Subkernel: pass exceptions to kernel

Open Spaqin opened this issue 1 month ago • 2 comments

ARTIQ Pull Request

Description of Changes

As discussed in another PR about documentation, it's not the best situation if the subkernel await/message pass throws an exception if it cannot be caught. So the exception is extracted from the message (in a way that's still compatible with ARTIQ-8) and sent to the kernel CPU, taking inspiration from RPC.

One caveat is that at the moment exception raised by subkernel called by another subkernel (k->sk1->sk2*) will still not be handled within the first subkernel. Only the main kernel can handle it at the moment, as subkernels only pass the exception source when one arises, rather than the whole exception data.

Tested with a Kasli 2.0 + 1.1 sat with following code:

from artiq.experiment import *


class ExceptionTest(EnvExperiment):
    def build(self):
        self.setattr_device("core")

    @subkernel(destination=1)
    def simple_return(self):
        raise IndexError("err")
    
    @kernel
    def run(self):
        self.core.reset()
        self.simple_return()
        try:
            subkernel_await(self.simple_return, 1)
        except:
            print("caught")

Type of Changes

Type
:bug: Bug fix

Steps (Choose relevant, delete irrelevant before submitting)

All Pull Requests

  • [x] Use correct spelling and grammar.

Code Changes

  • [x] Test your changes or have someone test them. Mention what was tested and how.

Git Logistics

  • [x] Split your contribution into logically separate changes (git rebase --interactive). Merge/squash/fixup commits that just fix or amend previous commits. Remove unintended changes & cleanup. See tutorial.
  • [x] Write short & meaningful commit messages. Review each commit for messages (git show). Format:
    topic: description. < 50 characters total.
    
    Longer description. < 70 characters per line
    

Licensing

See copyright & licensing for more info. ARTIQ files that do not contain a license header are copyrighted by M-Labs Limited and are licensed under LGPLv3+.

Spaqin avatar Jun 21 '24 05:06 Spaqin