forked from M-Labs/artiq
test/portability: port to NAC3
This commit is contained in:
parent
c763b9b717
commit
9f664afb00
|
@ -1,6 +1,8 @@
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from fractions import Fraction
|
|
||||||
|
|
||||||
|
from numpy import int32, int64
|
||||||
|
|
||||||
|
from artiq.coredevice.core import Core
|
||||||
from artiq.experiment import *
|
from artiq.experiment import *
|
||||||
from artiq.sim import devices as sim_devices
|
from artiq.sim import devices as sim_devices
|
||||||
from artiq.test.hardware_testbench import ExperimentCase
|
from artiq.test.hardware_testbench import ExperimentCase
|
||||||
|
@ -16,13 +18,18 @@ def _run_on_host(k_class, *args, **kwargs):
|
||||||
return k_inst
|
return k_inst
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _Primes(EnvExperiment):
|
class _Primes(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
maximum: KernelInvariant[int32]
|
||||||
|
|
||||||
def build(self, output_list, maximum):
|
def build(self, output_list, maximum):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.output_list = output_list
|
self.output_list = output_list
|
||||||
self.maximum = maximum
|
self.maximum = maximum
|
||||||
|
|
||||||
def _add_output(self, x):
|
@rpc
|
||||||
|
def _add_output(self, x: int32):
|
||||||
self.output_list.append(x)
|
self.output_list.append(x)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
|
@ -39,8 +46,11 @@ class _Primes(EnvExperiment):
|
||||||
self._add_output(x)
|
self._add_output(x)
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _Math(EnvExperiment):
|
class _Math(EnvExperiment):
|
||||||
"""Test kernel math"""
|
core: KernelInvariant[Core]
|
||||||
|
x: KernelInvariant[float]
|
||||||
|
x_sqrt: Kernel[float]
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
|
@ -52,7 +62,18 @@ class _Math(EnvExperiment):
|
||||||
self.x_sqrt = self.x**0.5
|
self.x_sqrt = self.x**0.5
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _Misc(EnvExperiment):
|
class _Misc(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
|
||||||
|
input: KernelInvariant[int32]
|
||||||
|
al: KernelInvariant[list[int32]]
|
||||||
|
list_copy_in: KernelInvariant[list[float]]
|
||||||
|
|
||||||
|
half_input: Kernel[int32]
|
||||||
|
acc: Kernel[int32]
|
||||||
|
list_copy_out: Kernel[list[float]]
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
|
|
||||||
|
@ -73,7 +94,10 @@ class _Misc(EnvExperiment):
|
||||||
self.list_copy_out = self.list_copy_in
|
self.list_copy_out = self.list_copy_in
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _PulseLogger(EnvExperiment):
|
class _PulseLogger(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
|
||||||
def build(self, parent_test, name):
|
def build(self, parent_test, name):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.parent_test = parent_test
|
self.parent_test = parent_test
|
||||||
|
@ -86,20 +110,29 @@ class _PulseLogger(EnvExperiment):
|
||||||
t_usec = round(self.core.mu_to_seconds(t-origin)*1000000)
|
t_usec = round(self.core.mu_to_seconds(t-origin)*1000000)
|
||||||
self.parent_test.output_list.append((self.name, t_usec, l, f))
|
self.parent_test.output_list.append((self.name, t_usec, l, f))
|
||||||
|
|
||||||
def on(self, t, f):
|
@rpc
|
||||||
|
def on(self, t: int64, f: int32):
|
||||||
self._append(t, True, f)
|
self._append(t, True, f)
|
||||||
|
|
||||||
def off(self, t):
|
@rpc
|
||||||
|
def off(self, t: int64):
|
||||||
self._append(t, False, 0)
|
self._append(t, False, 0)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def pulse(self, f, duration):
|
def pulse(self, f: int32, duration: float):
|
||||||
self.on(now_mu(), f)
|
self.on(now_mu(), f)
|
||||||
delay(duration)
|
self.core.delay(duration)
|
||||||
self.off(now_mu())
|
self.off(now_mu())
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _Pulses(EnvExperiment):
|
class _Pulses(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
a: KernelInvariant[_PulseLogger]
|
||||||
|
b: KernelInvariant[_PulseLogger]
|
||||||
|
c: KernelInvariant[_PulseLogger]
|
||||||
|
d: KernelInvariant[_PulseLogger]
|
||||||
|
|
||||||
def build(self, output_list):
|
def build(self, output_list):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.output_list = output_list
|
self.output_list = output_list
|
||||||
|
@ -115,22 +148,28 @@ class _Pulses(EnvExperiment):
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
with parallel:
|
with parallel:
|
||||||
with sequential:
|
with sequential:
|
||||||
self.a.pulse(100+i, 20*us)
|
self.a.pulse(100+i, 20.*us)
|
||||||
self.b.pulse(200+i, 20*us)
|
self.b.pulse(200+i, 20.*us)
|
||||||
with sequential:
|
with sequential:
|
||||||
self.c.pulse(300+i, 10*us)
|
self.c.pulse(300+i, 10.*us)
|
||||||
self.d.pulse(400+i, 20*us)
|
self.d.pulse(400+i, 20.*us)
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _MyException(Exception):
|
class _MyException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _NestedFinally(EnvExperiment):
|
class _NestedFinally(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
|
||||||
def build(self, trace):
|
def build(self, trace):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.trace = trace
|
self.trace = trace
|
||||||
|
|
||||||
def _trace(self, i):
|
@rpc
|
||||||
|
def _trace(self, i: int32):
|
||||||
self.trace.append(i)
|
self.trace.append(i)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
|
@ -148,12 +187,17 @@ class _NestedFinally(EnvExperiment):
|
||||||
finally:
|
finally:
|
||||||
self._trace(2)
|
self._trace(2)
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _NestedExceptions(EnvExperiment):
|
class _NestedExceptions(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
|
||||||
def build(self, trace):
|
def build(self, trace):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.trace = trace
|
self.trace = trace
|
||||||
|
|
||||||
def _trace(self, i):
|
@rpc
|
||||||
|
def _trace(self, i: int32):
|
||||||
self.trace.append(i)
|
self.trace.append(i)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
|
@ -177,12 +221,17 @@ class _NestedExceptions(EnvExperiment):
|
||||||
finally:
|
finally:
|
||||||
self._trace(4)
|
self._trace(4)
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _Exceptions(EnvExperiment):
|
class _Exceptions(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
|
||||||
def build(self, trace):
|
def build(self, trace):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.trace = trace
|
self.trace = trace
|
||||||
|
|
||||||
def _trace(self, i):
|
@rpc
|
||||||
|
def _trace(self, i: int32):
|
||||||
self.trace.append(i)
|
self.trace.append(i)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
|
@ -224,13 +273,19 @@ class _Exceptions(EnvExperiment):
|
||||||
self._trace(104)
|
self._trace(104)
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _RPCExceptions(EnvExperiment):
|
class _RPCExceptions(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
catch: KernelInvariant[bool]
|
||||||
|
success: Kernel[bool]
|
||||||
|
|
||||||
def build(self, catch):
|
def build(self, catch):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.catch = catch
|
self.catch = catch
|
||||||
|
|
||||||
self.success = False
|
self.success = False
|
||||||
|
|
||||||
|
@rpc
|
||||||
def exception_raiser(self):
|
def exception_raiser(self):
|
||||||
raise _MyException
|
raise _MyException
|
||||||
|
|
||||||
|
@ -253,13 +308,18 @@ class _RPCExceptions(EnvExperiment):
|
||||||
self.success = True
|
self.success = True
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class _Keywords(EnvExperiment):
|
class _Keywords(EnvExperiment):
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
value: KernelInvariant[int32]
|
||||||
|
|
||||||
def build(self, value, output):
|
def build(self, value, output):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.value = value
|
self.value = value
|
||||||
self.output = output
|
self.output = output
|
||||||
|
|
||||||
def rpc(self, kw):
|
@rpc
|
||||||
|
def rpc(self, kw: int32):
|
||||||
self.output.append(kw)
|
self.output.append(kw)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
|
@ -323,6 +383,7 @@ class HostVsDeviceCase(ExperimentCase):
|
||||||
uut = self.execute(_RPCExceptions, catch=True)
|
uut = self.execute(_RPCExceptions, catch=True)
|
||||||
self.assertTrue(uut.success)
|
self.assertTrue(uut.success)
|
||||||
|
|
||||||
|
@unittest.skip("NAC3TODO https://git.m-labs.hk/M-Labs/nac3/issues/533")
|
||||||
def test_keywords(self):
|
def test_keywords(self):
|
||||||
for f in self.execute, _run_on_host:
|
for f in self.execute, _run_on_host:
|
||||||
output = []
|
output = []
|
||||||
|
@ -331,9 +392,3 @@ class HostVsDeviceCase(ExperimentCase):
|
||||||
output = []
|
output = []
|
||||||
f(_Keywords, value=1, output=output)
|
f(_Keywords, value=1, output=output)
|
||||||
self.assertEqual(output, [1])
|
self.assertEqual(output, [1])
|
||||||
output = []
|
|
||||||
f(_Keywords, value=False, output=output)
|
|
||||||
self.assertEqual(output, [False])
|
|
||||||
output = []
|
|
||||||
f(_Keywords, value=True, output=output)
|
|
||||||
self.assertEqual(output, [True])
|
|
||||||
|
|
Loading…
Reference in New Issue