support class attributes #102

Open
opened 2021-11-19 12:55:12 +08:00 by sb10q · 2 comments

e.g.

class Foo:
   MY_ATTR = 32
e.g. ```python class Foo: MY_ATTR = 32 ```
sb10q added the
low-priority
label 2021-11-19 12:55:12 +08:00
sb10q added the
UROP0622
label 2022-06-24 18:03:41 +08:00
Poster
Owner

Needs to be supported in nac3artiq + nac3standalone

Need to find a way to annotate it in nac3artiq. How about something like

class Foo:
   MY_ATTR0 = 32 # host only
   MY_ATTR1: int32 = 32  # host only
   MY_ATTR2: KernelInvariant[int32] = 32  # accessible to the kernel
   MY_ATTR3: Kernel[int32] = 32  # do we want to support this? OK if such attributes are immutable
Needs to be supported in nac3artiq + nac3standalone Need to find a way to annotate it in nac3artiq. How about something like ```python class Foo: MY_ATTR0 = 32 # host only MY_ATTR1: int32 = 32 # host only MY_ATTR2: KernelInvariant[int32] = 32 # accessible to the kernel MY_ATTR3: Kernel[int32] = 32 # do we want to support this? OK if such attributes are immutable ```
Poster
Owner

Example code (nac3artiq) that should work but does not:

from artiq.experiment import *
from artiq.coredevice.core import Core


@nac3
class XXX:
    TEST: KernelInvariant[int32] = 32

@nac3
class NAC3Devices(EnvExperiment):
    core: KernelInvariant[Core]

    YYY: KernelInvariant[int32] = 32

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

    @kernel
    def run(self):
        print_rpc(XXX.TEST)
        print_rpc(self.YYY)
        print_rpc(NAC3Devices.YYY)
Example code (nac3artiq) that should work but does not: ```python from artiq.experiment import * from artiq.coredevice.core import Core @nac3 class XXX: TEST: KernelInvariant[int32] = 32 @nac3 class NAC3Devices(EnvExperiment): core: KernelInvariant[Core] YYY: KernelInvariant[int32] = 32 def build(self): self.setattr_device("core") @kernel def run(self): print_rpc(XXX.TEST) print_rpc(self.YYY) print_rpc(NAC3Devices.YYY) ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#102
There is no content yet.