type inferencer crash on artiq_sinara_tester #432

Closed
opened 2024-06-20 16:51:38 +08:00 by sb10q · 3 comments
Owner

ARTIQ 567cd45eee11df62a3ce29453c00935b445a1492

cd artiq/examples/nac3devices
python3 -m artiq.frontend.artiq_ddb_template nac3devices.json > device_db.py
python3 -m artiq.frontend.artiq_sinara_tester

Crash:

****** Sinara system tester ******

thread '<unnamed>' panicked at nac3core/src/typecheck/type_inferencer/mod.rs:1784:26:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/sb/artiq/artiq/frontend/artiq_sinara_tester.py", line 1020, in <module>
    main()
  File "/home/sb/artiq/artiq/frontend/artiq_sinara_tester.py", line 1012, in main
    experiment.run(tests)
  File "/home/sb/artiq/artiq/frontend/artiq_sinara_tester.py", line 959, in run
    self.core.reset()
  File "/home/sb/artiq/artiq/language/core.py", line 82, in run_on_core
    return self.core.run(fake_method, args, kwargs)
  File "/home/sb/artiq/artiq/coredevice/core.py", line 116, in run
    kernel_library = self.compile(function, args, kwargs, embedding_map)
  File "/home/sb/artiq/artiq/coredevice/core.py", line 110, in compile
    return self.compiler.compile_method_to_mem(obj, name, args, embedding_map)
pyo3_runtime.PanicException: internal error: entered unreachable code

No hardware necessary for repro.

ARTIQ 567cd45eee11df62a3ce29453c00935b445a1492 ``` cd artiq/examples/nac3devices python3 -m artiq.frontend.artiq_ddb_template nac3devices.json > device_db.py python3 -m artiq.frontend.artiq_sinara_tester ``` Crash: ``` ****** Sinara system tester ****** thread '<unnamed>' panicked at nac3core/src/typecheck/type_inferencer/mod.rs:1784:26: internal error: entered unreachable code note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Traceback (most recent call last): File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/home/sb/artiq/artiq/frontend/artiq_sinara_tester.py", line 1020, in <module> main() File "/home/sb/artiq/artiq/frontend/artiq_sinara_tester.py", line 1012, in main experiment.run(tests) File "/home/sb/artiq/artiq/frontend/artiq_sinara_tester.py", line 959, in run self.core.reset() File "/home/sb/artiq/artiq/language/core.py", line 82, in run_on_core return self.core.run(fake_method, args, kwargs) File "/home/sb/artiq/artiq/coredevice/core.py", line 116, in run kernel_library = self.compile(function, args, kwargs, embedding_map) File "/home/sb/artiq/artiq/coredevice/core.py", line 110, in compile return self.compiler.compile_method_to_mem(obj, name, args, embedding_map) pyo3_runtime.PanicException: internal error: entered unreachable code ``` No hardware necessary for repro.
sb10q added the
high-priority
label 2024-06-20 16:51:38 +08:00
lyken was assigned by sb10q 2024-06-20 16:51:38 +08:00
Collaborator

(All code references are referencing to 567cd45eee)

Following the logs, the offending line is in artiq/frontend/artiq_sinara_tester.py:879.

# In class SinaraTester(EnvExperiment)
    @kernel
    def setup_shuttler_set_output(self, dcbias: ShuttlerDCBias, dds: ShuttlerDDS, trigger: ShuttlerTrigger, ch: int32, volt: float):
        self.core.break_realtime()
        dcbias[ch].set_waveform( # Offending line
            a0=shuttler_volt_to_mu(volt),
            a1=0,
            a2=0,
            a3=0,
        )
        delay_mu(int64(self.core.ref_multiplier))

In particular, it is dcbias[ch] that is causing a panic in nac3core's typecheck/type_inferencer/mod.rs's infer_subscript() within impl Inferencer.

The reason is that dcbias is declared to be of type object class ShuttlerDCBias in the function parameters, and it is simply illegal to index into a value that is typed as an object (NOTE: except for ndarrays, and disregarding __getitem__ and its friends, nac3core does not have that currently if I am correct). More formally, nac3core only supports indexing into a Tuple, a List, or an ndarray if the value being index-ed is an object.

The parameters of SinaraTester.setup_shutter_set_output (and also SinaraTester.setup_shutter_init) are mistyped and should have been:

    def setup_shuttler_set_output(
        self,
        dcbias: list[ShuttlerDCBias], # from `dcbias: ShuttlerDCBias`
        dds: list[ShuttlerDDS], # from `dds: ShuttlerDDS`
        trigger: ShuttlerTrigger,
        ch: int32,
        volt: float
    ):
        # ...

I believe so is because of how SinaraTester.setup_shutter_set_output is being used. Here is what I found in artiq/frontend/artiq_sinara_tester.py by tracing through the source code:

  1. SinaraTester.setup_shuttler_set_output is used by SinaraTester.setup_shuttler_init (which I believe is also mistyped for the parameters dcbias and dds) like so:
    @kernel
    def setup_shuttler_init(self, relay: ShuttlerRelay, adc: ShuttlerADC, dcbias: ShuttlerDCBias, 
                            dds: ShuttlerDDS, trigger: TTLOut, config: ShuttlerConfig):
        self.core.breal_realtime()
        # ...
        for ch in range(16):
            self.setup_shuttler_set_output(dcbias, dds, trigger, ch, 0.0)
  1. SinaraTester.setup_shuttler_init is used by SinaraTester.test_shuttler like so:
    def test_shuttler(self):
        print("*** Testing Shuttler.")

        for card_n, (card_name, card_dev) in enumerate(self.shuttler):
            print("Testing: ", card_name)

            output_voltage = 0.0

            self.setup_shuttler_init(card_dev["relay"], card_dev["adc"], card_dev["dcbias"], card_dev["dds"], card_dev["trigger"], card_dev["config"])
            # ...
        # ...
  1. the type of card_dev["dcbias"] in SinaraTester.setup_shuttler_init could be inferred from how SinaraTester.build() constructs self.shuttler:
shuttler_name = name.replace("_config", "")
self.shuttler[shuttler_name] = ({
    "config": self.get_device(name),
    "trigger": self.get_device("{}_trigger".format(shuttler_name)),
    "leds": [self.get_device("{}_led{}".format(shuttler_name, i)) for i in range(2)],
    "dcbias": [self.get_device("{}_dcbias{}".format(shuttler_name, i)) for i in range(16)],
    "dds": [self.get_device("{}_dds{}".format(shuttler_name, i)) for i in range(16)],
    "relay": self.get_device("{}_relay".format(shuttler_name)),
    "adc": self.get_device("{}_adc".format(shuttler_name)),
})

Therefore self.shuttler[<a shutter_name>]["dcbias"] is a list[coredevice.shuttler.DCBias], the same goes for self.shuttler[<a shutter_name>]["dds"].

Other things to consider:

  1. nac3core should change the panic caused by this issue to a proper error report.
  2. I actually fixed the parameter types of SinaraTester.setup_shutter_set_output and SinaraTester.setup_shutter_init, and it did fix the panic. But in fact there are more compiling issues with artiq/frontend/artiq_sinara_tester.py. Here are some of them (there are more):
nac3artiq.CompileError: compilation failed
----------
Incorrect argument type for a2. Expected int64, but got int32 at /home/lyken/artiq/artiq/frontend/artiq_sinara_tester.py:879:32
----------
Incorrect argument type for other. Expected N, but got float at /home/lyken/artiq/artiq/frontend/artiq_sinara_tester.py:469:36

Notes:
    ndarray_ndims ∈ {uint32}
    N ∈ {int32, ndarray[int32, ndarray_ndims]}
----------
type error at identifier `print` (cannot find symbol `print`) at /home/lyken/artiq/artiq/frontend/artiq_sinara_tester.py:855:13
(All code references are referencing to https://github.com/m-labs/artiq/tree/567cd45eee11df62a3ce29453c00935b445a1492) Following the logs, the offending line is in `artiq/frontend/artiq_sinara_tester.py:879`. ```python # In class SinaraTester(EnvExperiment) @kernel def setup_shuttler_set_output(self, dcbias: ShuttlerDCBias, dds: ShuttlerDDS, trigger: ShuttlerTrigger, ch: int32, volt: float): self.core.break_realtime() dcbias[ch].set_waveform( # Offending line a0=shuttler_volt_to_mu(volt), a1=0, a2=0, a3=0, ) delay_mu(int64(self.core.ref_multiplier)) ``` In particular, it is `dcbias[ch]` that is causing a panic in `nac3core`'s `typecheck/type_inferencer/mod.rs`'s `infer_subscript()` within `impl Inferencer`. The reason is that `dcbias` is declared to be of type object `class ShuttlerDCBias` in the function parameters, and it is simply illegal to index into a value that is typed as an object (NOTE: except for `ndarray`s, and disregarding `__getitem__` and its friends, `nac3core` does not have that currently if I am correct). More formally, `nac3core` only supports indexing into a `Tuple`, a `List`, or an `ndarray` if the value being index-ed is an object. The parameters of `SinaraTester.setup_shutter_set_output` (and also `SinaraTester.setup_shutter_init`) are mistyped and should have been: ```python def setup_shuttler_set_output( self, dcbias: list[ShuttlerDCBias], # from `dcbias: ShuttlerDCBias` dds: list[ShuttlerDDS], # from `dds: ShuttlerDDS` trigger: ShuttlerTrigger, ch: int32, volt: float ): # ... ``` I believe so is because of how `SinaraTester.setup_shutter_set_output` is being used. Here is what I found in `artiq/frontend/artiq_sinara_tester.py` by tracing through the source code: 1. `SinaraTester.setup_shuttler_set_output` is used by `SinaraTester.setup_shuttler_init` (which I believe is also mistyped for the parameters `dcbias` and `dds`) like so: ```python @kernel def setup_shuttler_init(self, relay: ShuttlerRelay, adc: ShuttlerADC, dcbias: ShuttlerDCBias, dds: ShuttlerDDS, trigger: TTLOut, config: ShuttlerConfig): self.core.breal_realtime() # ... for ch in range(16): self.setup_shuttler_set_output(dcbias, dds, trigger, ch, 0.0) ``` 2. `SinaraTester.setup_shuttler_init` is used by `SinaraTester.test_shuttler` like so: ```python def test_shuttler(self): print("*** Testing Shuttler.") for card_n, (card_name, card_dev) in enumerate(self.shuttler): print("Testing: ", card_name) output_voltage = 0.0 self.setup_shuttler_init(card_dev["relay"], card_dev["adc"], card_dev["dcbias"], card_dev["dds"], card_dev["trigger"], card_dev["config"]) # ... # ... ``` 3. the type of `card_dev["dcbias"]` in `SinaraTester.setup_shuttler_init` could be inferred from how `SinaraTester.build()` constructs `self.shuttler`: ```python shuttler_name = name.replace("_config", "") self.shuttler[shuttler_name] = ({ "config": self.get_device(name), "trigger": self.get_device("{}_trigger".format(shuttler_name)), "leds": [self.get_device("{}_led{}".format(shuttler_name, i)) for i in range(2)], "dcbias": [self.get_device("{}_dcbias{}".format(shuttler_name, i)) for i in range(16)], "dds": [self.get_device("{}_dds{}".format(shuttler_name, i)) for i in range(16)], "relay": self.get_device("{}_relay".format(shuttler_name)), "adc": self.get_device("{}_adc".format(shuttler_name)), }) ``` Therefore `self.shuttler[<a shutter_name>]["dcbias"]` is a `list[coredevice.shuttler.DCBias]`, the same goes for `self.shuttler[<a shutter_name>]["dds"]`. Other things to consider: 1. `nac3core` should change the panic caused by this issue to a proper error report. 2. I actually fixed the parameter types of `SinaraTester.setup_shutter_set_output` and `SinaraTester.setup_shutter_init`, and it did fix the panic. But in fact there are more compiling issues with `artiq/frontend/artiq_sinara_tester.py`. Here are some of them (there are *more*): ``` nac3artiq.CompileError: compilation failed ---------- Incorrect argument type for a2. Expected int64, but got int32 at /home/lyken/artiq/artiq/frontend/artiq_sinara_tester.py:879:32 ---------- Incorrect argument type for other. Expected N, but got float at /home/lyken/artiq/artiq/frontend/artiq_sinara_tester.py:469:36 Notes: ndarray_ndims ∈ {uint32} N ∈ {int32, ndarray[int32, ndarray_ndims]} ---------- type error at identifier `print` (cannot find symbol `print`) at /home/lyken/artiq/artiq/frontend/artiq_sinara_tester.py:855:13 ```
Author
Owner

I fixed sinara_tester, but the original NAC3 error message needs to be fixed.

I fixed sinara_tester, but the original NAC3 error message needs to be fixed.
Collaborator

I will work on improving the error after completing #427.

I will work on improving the error after completing https://git.m-labs.hk/M-Labs/nac3/issues/427.
lyken added a new dependency 2024-06-27 17:12:41 +08:00
sb10q closed this issue 2024-07-07 14:22:04 +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.

Reference: M-Labs/nac3#432
No description provided.