check divide-by-zero error #72

Closed
opened 2020-07-23 16:35:49 +08:00 by sb10q · 1 comment

Those should terminate with ZeroDivisionError exception:

from artiq.experiment import *


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

    def reti(self) -> TInt32:
        return 0

    @kernel
    def run(self):
        print(10/self.reti())
from artiq.experiment import *


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

    def retf(self) -> TFloat:
        return 0.0

    @kernel
    def run(self):
        print(10.0/self.retf()) 

Consider adding to the hardware-in-the-loop ARTIQ test suite (currently it is only in the host lit tests).

Those should terminate with ``ZeroDivisionError`` exception: ```python from artiq.experiment import * class Div0(EnvExperiment): def build(self): self.setattr_device("core") def reti(self) -> TInt32: return 0 @kernel def run(self): print(10/self.reti()) ``` ```python from artiq.experiment import * class Div0(EnvExperiment): def build(self): self.setattr_device("core") def retf(self) -> TFloat: return 0.0 @kernel def run(self): print(10.0/self.retf()) ``` Consider adding to the hardware-in-the-loop ARTIQ test suite (currently it is only in the host lit tests).
Poster
Owner

It works already

$ artiq_run div.py 
Core Device Traceback (most recent call last):
  File "div.py", line 13, in .L_Z22artiq_run_div.Div0.runzz (RA=+0x4fc)
    print(10/self.reti())
  File "", line -1, in .L_Z22artiq_run_div.Div0.runzz.check:13:17 (RA=+0x594)
    <unknown>
  File "div.py", line 13, column 18, in artiq_run_div.Div0.run(..., ...)
    print(10/self.reti())
             ^
ZeroDivisionError(0): cannot divide by zero
Traceback (most recent call last):
  File "/nix/store/q0slcz56ki3nvsa1kqsfjr1jwz7kz4cg-python3.7-artiq-6.7285.9c9dc3d0.beta/bin/.artiq_run-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 225, in main
    return run(with_file=True)
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 211, in run
    raise exn
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 204, in run
    exp_inst.run()
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/language/core.py", line 54, in run_on_core
    return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs)
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/core.py", line 137, in run
    self.comm.serve(embedding_map, symbolizer, demangler)
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/comm_kernel.py", line 502, in serve
    self._serve_exception(embedding_map, symbolizer, demangler)
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/comm_kernel.py", line 494, in _serve_exception
    raise python_exn
ZeroDivisionError: cannot divide by zero
$ artiq_run div2.py 
Core Device Traceback (most recent call last):
  File "div2.py", line 13, in .L_Z23artiq_run_div2.Div0.runzz (RA=+0x500)
    print(10.0/self.retf())
  File "", line -1, in .L_Z23artiq_run_div2.Div0.runzz.check:13:19 (RA=+0x594)
    <unknown>
  File "div2.py", line 13, column 20, in artiq_run_div2.Div0.run(..., ...)
    print(10.0/self.retf())
               ^
ZeroDivisionError(0): cannot divide by zero
Traceback (most recent call last):
  File "/nix/store/q0slcz56ki3nvsa1kqsfjr1jwz7kz4cg-python3.7-artiq-6.7285.9c9dc3d0.beta/bin/.artiq_run-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 225, in main
    return run(with_file=True)
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 211, in run
    raise exn
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 204, in run
    exp_inst.run()
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/language/core.py", line 54, in run_on_core
    return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs)
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/core.py", line 137, in run
    self.comm.serve(embedding_map, symbolizer, demangler)
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/comm_kernel.py", line 502, in serve
    self._serve_exception(embedding_map, symbolizer, demangler)
  File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/comm_kernel.py", line 494, in _serve_exception
    raise python_exn
ZeroDivisionError: cannot divide by zero

Handled mostly in the compiler so the lit tests should be good enough.

It works already ```text $ artiq_run div.py Core Device Traceback (most recent call last): File "div.py", line 13, in .L_Z22artiq_run_div.Div0.runzz (RA=+0x4fc) print(10/self.reti()) File "", line -1, in .L_Z22artiq_run_div.Div0.runzz.check:13:17 (RA=+0x594) <unknown> File "div.py", line 13, column 18, in artiq_run_div.Div0.run(..., ...) print(10/self.reti()) ^ ZeroDivisionError(0): cannot divide by zero Traceback (most recent call last): File "/nix/store/q0slcz56ki3nvsa1kqsfjr1jwz7kz4cg-python3.7-artiq-6.7285.9c9dc3d0.beta/bin/.artiq_run-wrapped", line 9, in <module> sys.exit(main()) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 225, in main return run(with_file=True) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 211, in run raise exn File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 204, in run exp_inst.run() File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/language/core.py", line 54, in run_on_core return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/core.py", line 137, in run self.comm.serve(embedding_map, symbolizer, demangler) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/comm_kernel.py", line 502, in serve self._serve_exception(embedding_map, symbolizer, demangler) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/comm_kernel.py", line 494, in _serve_exception raise python_exn ZeroDivisionError: cannot divide by zero ``` ```text $ artiq_run div2.py Core Device Traceback (most recent call last): File "div2.py", line 13, in .L_Z23artiq_run_div2.Div0.runzz (RA=+0x500) print(10.0/self.retf()) File "", line -1, in .L_Z23artiq_run_div2.Div0.runzz.check:13:19 (RA=+0x594) <unknown> File "div2.py", line 13, column 20, in artiq_run_div2.Div0.run(..., ...) print(10.0/self.retf()) ^ ZeroDivisionError(0): cannot divide by zero Traceback (most recent call last): File "/nix/store/q0slcz56ki3nvsa1kqsfjr1jwz7kz4cg-python3.7-artiq-6.7285.9c9dc3d0.beta/bin/.artiq_run-wrapped", line 9, in <module> sys.exit(main()) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 225, in main return run(with_file=True) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 211, in run raise exn File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/frontend/artiq_run.py", line 204, in run exp_inst.run() File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/language/core.py", line 54, in run_on_core return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/core.py", line 137, in run self.comm.serve(embedding_map, symbolizer, demangler) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/comm_kernel.py", line 502, in serve self._serve_exception(embedding_map, symbolizer, demangler) File "/nix/store/h853vd5c3bjspw15lpgvp6lbrkygp2k8-python3-3.7.6-env/lib/python3.7/site-packages/artiq/coredevice/comm_kernel.py", line 494, in _serve_exception raise python_exn ZeroDivisionError: cannot divide by zero ``` Handled mostly in the compiler so the lit tests should be good enough.
sb10q closed this issue 2020-08-04 23:14:39 +08:00
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/artiq-zynq#72
There is no content yet.