attribute writeback breaks with multiple kernel calls #242

Closed
opened 2022-03-26 20:27:17 +08:00 by sb10q · 2 comments
from numpy import int32
from artiq.experiment import *
from artiq.coredevice.core import Core


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

    def build(self):
        self.setattr_device("core")
        self.x = 0

    @kernel
    def foo(self):
        print_rpc(self.x)
        self.x +=1

    def run(self):
        for i in range(10):
            self.foo()
0
1
Core Device Traceback:
Traceback (most recent call first):
  File "<artiq>/coredevice/comm_kernel.py", line 667, in service
    setattr(old_val, name, values[counter])
IndexError(0): tuple index out of range

End of Core Device Traceback

Traceback (most recent call last):
  File "/nix/store/0vvlm0aplm57gs7y6jqhqjcirlrasilp-python3.9-artiq-8.0.unknown.beta/bin/.artiq_run-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/frontend/artiq_run.py", line 171, in main
    return run(with_file=True)
  File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/frontend/artiq_run.py", line 157, in run
    raise exn
  File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/frontend/artiq_run.py", line 152, in run
    exp_inst.run()
  File "nac3devices.py", line 22, in run
    self.foo()
  File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/language/core.py", line 77, in run_on_core
    self.core.run(fake_method, args, kwargs)
  File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/coredevice/core.py", line 92, in run
    self.comm.serve(self.embedding_map, symbolizer)
  File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/coredevice/comm_kernel.py", line 811, in serve
    self._serve_exception(embedding_map, symbolizer)
  File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/coredevice/comm_kernel.py", line 793, in _serve_exception
    raise python_exn
IndexError: tuple index out of range
```python from numpy import int32 from artiq.experiment import * from artiq.coredevice.core import Core @nac3 class NAC3Devices(EnvExperiment): core: KernelInvariant[Core] x: Kernel[int32] def build(self): self.setattr_device("core") self.x = 0 @kernel def foo(self): print_rpc(self.x) self.x +=1 def run(self): for i in range(10): self.foo() ``` ``` 0 1 Core Device Traceback: Traceback (most recent call first): File "<artiq>/coredevice/comm_kernel.py", line 667, in service setattr(old_val, name, values[counter]) IndexError(0): tuple index out of range End of Core Device Traceback Traceback (most recent call last): File "/nix/store/0vvlm0aplm57gs7y6jqhqjcirlrasilp-python3.9-artiq-8.0.unknown.beta/bin/.artiq_run-wrapped", line 9, in <module> sys.exit(main()) File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/frontend/artiq_run.py", line 171, in main return run(with_file=True) File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/frontend/artiq_run.py", line 157, in run raise exn File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/frontend/artiq_run.py", line 152, in run exp_inst.run() File "nac3devices.py", line 22, in run self.foo() File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/language/core.py", line 77, in run_on_core self.core.run(fake_method, args, kwargs) File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/coredevice/core.py", line 92, in run self.comm.serve(self.embedding_map, symbolizer) File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/coredevice/comm_kernel.py", line 811, in serve self._serve_exception(embedding_map, symbolizer) File "/nix/store/464lcnypcz7ci35w6lh9qzib69l6jica-python3-3.9.6-env/lib/python3.9/site-packages/artiq/coredevice/comm_kernel.py", line 793, in _serve_exception raise python_exn IndexError: tuple index out of range ```
sb10q added this to the Prealpha milestone 2022-03-26 20:27:17 +08:00
sb10q added the
high-priority
label 2022-03-26 20:27:17 +08:00
pca006132 was assigned by sb10q 2022-03-26 20:27:17 +08:00

Just add the following line before https://github.com/m-labs/artiq/blob/nac3/artiq/coredevice/core.py#L92

self.embedding_map.attributes_writeback = []
Just add the following line before https://github.com/m-labs/artiq/blob/nac3/artiq/coredevice/core.py#L92 ```python self.embedding_map.attributes_writeback = [] ```
Poster
Owner

How about this?

diff --git a/artiq/coredevice/core.py b/artiq/coredevice/core.py
index 8b55bd62..55aa598e 100644
--- a/artiq/coredevice/core.py
+++ b/artiq/coredevice/core.py
@@ -57,7 +57,6 @@ class Core:
         self.comm.core = self
         self.target = target
         self.compiler = nac3artiq.NAC3(target)
-        self.embedding_map = EmbeddingMap()
 
     def close(self):
         self.comm.close()
@@ -80,7 +79,8 @@ class Core:
             self.compiler.compile_method_to_file(obj, name, args, file_output, embedding_map)
 
     def run(self, function, args, kwargs):
-        kernel_library = self.compile(function, args, kwargs, self.embedding_map)
+        embedding_map = EmbeddingMap()
+        kernel_library = self.compile(function, args, kwargs, embedding_map)
         if self.first_run:
             self.comm.check_system_info()
             self.first_run = False
@@ -89,7 +89,7 @@ class Core:
 
         self.comm.load(kernel_library)
         self.comm.run()
-        self.comm.serve(self.embedding_map, symbolizer)
+        self.comm.serve(embedding_map, symbolizer)
 
     @portable
     def seconds_to_mu(self, seconds: float) -> int64:
How about this? ``` diff --git a/artiq/coredevice/core.py b/artiq/coredevice/core.py index 8b55bd62..55aa598e 100644 --- a/artiq/coredevice/core.py +++ b/artiq/coredevice/core.py @@ -57,7 +57,6 @@ class Core: self.comm.core = self self.target = target self.compiler = nac3artiq.NAC3(target) - self.embedding_map = EmbeddingMap() def close(self): self.comm.close() @@ -80,7 +79,8 @@ class Core: self.compiler.compile_method_to_file(obj, name, args, file_output, embedding_map) def run(self, function, args, kwargs): - kernel_library = self.compile(function, args, kwargs, self.embedding_map) + embedding_map = EmbeddingMap() + kernel_library = self.compile(function, args, kwargs, embedding_map) if self.first_run: self.comm.check_system_info() self.first_run = False @@ -89,7 +89,7 @@ class Core: self.comm.load(kernel_library) self.comm.run() - self.comm.serve(self.embedding_map, symbolizer) + self.comm.serve(embedding_map, symbolizer) @portable def seconds_to_mu(self, seconds: float) -> int64: ```
sb10q closed this issue 2022-03-26 20:42:34 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
2 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#242
There is no content yet.