Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subkernel: handle subkernel exceptions in (sub)kernel #2455

Merged
merged 4 commits into from
Jul 31, 2024

Conversation

Spaqin
Copy link
Collaborator

@Spaqin Spaqin commented Jun 21, 2024

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")

For testing raising subkernel exceptions within subkernels:

from artiq.experiment import *


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

    @subkernel(destination=1)
    def exc_call(self) -> TInt32:
        self.simple_exception()
        try:
            subkernel_await(self.simple_exception, 10000)
            retval = 1
        except IndexError:
            retval = 0
        return retval

    @subkernel(destination=2)
    def simple_exception(self):
        raise IndexError("err")
    
    @kernel
    def run(self):
        self.core.reset()
        self.exc_call()
        v = subkernel_await(self.exc_call, 1000)
        print(v)

Tested with Kasli SoC master -> 2.0 sat -> 1.1 sat, and SoC master -> SoC sat -> 1.1 sat

Type of Changes

Type
🐛 Bug fix

Steps (Choose relevant, delete irrelevant before submitting)

All Pull Requests

  • Use correct spelling and grammar.

Code Changes

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

Git Logistics

  • 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.
  • 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 Spaqin changed the title [WIP] Subkernel: pass exceptions to kernel Subkernel: pass exceptions to kernel Jun 25, 2024
@architeuthidae architeuthidae mentioned this pull request Jun 25, 2024
2 tasks
@sbourdeauducq
Copy link
Member

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.

Can this get fixed? Sounds pretty inconsistent and not user-friendly.
I would prefer fixing this properly in 9 than trying to keep compatibility with 8.

@Spaqin
Copy link
Collaborator Author

Spaqin commented Jul 5, 2024

Can this get fixed? Sounds pretty inconsistent and not user-friendly. I would prefer fixing this properly in 9 than trying to keep compatibility with 8.

I am just working on that.

@Spaqin Spaqin changed the title Subkernel: pass exceptions to kernel Subkernel: handle subkernel exceptions in (sub)kernel Jul 8, 2024
@sbourdeauducq sbourdeauducq merged commit e63ac34 into m-labs:master Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants