2015-06-29 10:08:39 +08:00
|
|
|
from math import sqrt
|
|
|
|
|
|
|
|
from artiq.language import *
|
|
|
|
from artiq.test.hardware_testbench import ExperimentCase
|
2015-06-26 12:19:11 +08:00
|
|
|
from artiq.coredevice.runtime_exceptions import RTIOUnderflow
|
|
|
|
|
|
|
|
|
2015-06-29 10:08:39 +08:00
|
|
|
class RTT(Experiment, AutoDB):
|
|
|
|
class DBKeys:
|
|
|
|
core = Device()
|
|
|
|
ttl_inout = Device()
|
|
|
|
rtt = Result()
|
|
|
|
|
|
|
|
@kernel
|
|
|
|
def run(self):
|
|
|
|
self.ttl_inout.output()
|
|
|
|
delay(1*us)
|
|
|
|
with parallel:
|
|
|
|
self.ttl_inout.gate_rising(2*us)
|
|
|
|
with sequential:
|
|
|
|
delay(1*us)
|
2015-07-02 04:34:49 +08:00
|
|
|
t0 = now_mu()
|
2015-06-26 12:19:11 +08:00
|
|
|
self.ttl_inout.pulse(1*us)
|
2015-07-02 04:34:49 +08:00
|
|
|
self.rtt = mu_to_seconds(self.ttl_inout.timestamp() - t0)
|
2015-06-29 10:08:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Loopback(Experiment, AutoDB):
|
|
|
|
class DBKeys:
|
|
|
|
core = Device()
|
|
|
|
loop_in = Device()
|
|
|
|
loop_out = Device()
|
|
|
|
rtt = Result()
|
|
|
|
|
|
|
|
@kernel
|
|
|
|
def run(self):
|
|
|
|
with parallel:
|
|
|
|
self.loop_in.gate_rising(2*us)
|
|
|
|
with sequential:
|
|
|
|
delay(1*us)
|
2015-07-02 04:34:49 +08:00
|
|
|
t0 = now_mu()
|
2015-06-29 10:08:39 +08:00
|
|
|
self.loop_out.pulse(1*us)
|
2015-07-02 04:34:49 +08:00
|
|
|
self.rtt = mu_to_seconds(self.loop_in.timestamp() - t0)
|
2015-06-29 10:08:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
class PulseRate(Experiment, AutoDB):
|
|
|
|
class DBKeys:
|
|
|
|
core = Device()
|
|
|
|
loop_out = Device()
|
|
|
|
pulse_rate = Result()
|
|
|
|
|
|
|
|
@kernel
|
|
|
|
def run(self):
|
2015-07-02 04:34:49 +08:00
|
|
|
dt = seconds_to_mu(1000*ns)
|
2015-06-29 10:08:39 +08:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
for i in range(1000):
|
2015-07-02 04:34:49 +08:00
|
|
|
self.loop_out.pulse_mu(dt)
|
|
|
|
delay_mu(dt)
|
2015-06-29 10:08:39 +08:00
|
|
|
except RTIOUnderflow:
|
|
|
|
dt += 1
|
|
|
|
self.core.break_realtime()
|
|
|
|
else:
|
2015-07-02 04:34:49 +08:00
|
|
|
self.pulse_rate = mu_to_seconds(2*dt)
|
2015-06-29 10:08:39 +08:00
|
|
|
break
|
|
|
|
|
2015-06-26 12:19:11 +08:00
|
|
|
|
2015-06-29 10:08:39 +08:00
|
|
|
class CoredeviceTest(ExperimentCase):
|
2015-06-26 12:19:11 +08:00
|
|
|
def test_rtt(self):
|
2015-06-29 10:08:39 +08:00
|
|
|
rtt = self.execute(RTT)["rtt"]
|
|
|
|
print(rtt)
|
2015-06-26 12:19:11 +08:00
|
|
|
self.assertGreater(rtt, 0*ns)
|
2015-06-29 10:08:39 +08:00
|
|
|
self.assertLess(rtt, 100*ns)
|
2015-06-26 12:19:11 +08:00
|
|
|
|
2015-06-29 10:08:39 +08:00
|
|
|
def test_loopback(self):
|
|
|
|
rtt = self.execute(Loopback)["rtt"]
|
|
|
|
print(rtt)
|
|
|
|
self.assertGreater(rtt, 0*ns)
|
|
|
|
self.assertLess(rtt, 40*ns)
|
2015-06-26 12:19:11 +08:00
|
|
|
|
2015-06-29 10:08:39 +08:00
|
|
|
def test_pulse_rate(self):
|
|
|
|
rate = self.execute(PulseRate)["pulse_rate"]
|
|
|
|
print(rate)
|
2015-06-26 12:19:11 +08:00
|
|
|
self.assertGreater(rate, 100*ns)
|
2015-06-29 10:08:39 +08:00
|
|
|
self.assertLess(rate, 2500*ns)
|
|
|
|
|
|
|
|
|
|
|
|
class RPCTiming(Experiment, AutoDB):
|
|
|
|
class DBKeys:
|
|
|
|
core = Device()
|
|
|
|
repeats = Argument(100)
|
|
|
|
rpc_time_mean = Result()
|
|
|
|
rpc_time_stddev = Result()
|
|
|
|
|
|
|
|
def nop(self, x):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@kernel
|
|
|
|
def bench(self):
|
|
|
|
self.ts = [0. for _ in range(self.repeats)]
|
|
|
|
for i in range(self.repeats):
|
2015-07-02 04:34:49 +08:00
|
|
|
t1 = self.core.get_rtio_counter_mu()
|
2015-06-29 10:08:39 +08:00
|
|
|
self.nop(1)
|
2015-07-02 04:34:49 +08:00
|
|
|
t2 = self.core.get_rtio_counter_mu()
|
|
|
|
self.ts[i] = mu_to_seconds(t2 - t1)
|
2015-06-29 10:08:39 +08:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.bench()
|
|
|
|
mean = sum(self.ts)/self.repeats
|
|
|
|
self.rpc_time_stddev = sqrt(
|
|
|
|
sum([(t - mean)**2 for t in self.ts])/self.repeats)*s
|
|
|
|
self.rpc_time_mean = mean*s
|
2015-06-26 12:19:11 +08:00
|
|
|
|
|
|
|
|
2015-06-29 10:08:39 +08:00
|
|
|
class RPCTest(ExperimentCase):
|
|
|
|
def test_rpc_timing(self):
|
|
|
|
res = self.execute(RPCTiming)
|
|
|
|
print(res)
|
|
|
|
self.assertGreater(res["rpc_time_mean"], 100*ns)
|
2015-07-02 04:34:49 +08:00
|
|
|
self.assertLess(res["rpc_time_mean"], 15*ms)
|
2015-06-29 10:08:39 +08:00
|
|
|
self.assertLess(res["rpc_time_stddev"], 1*ms)
|