From 89aa3a3d9de50a2abd0985cc8e6d2ab501eb6f6c Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 12 Apr 2022 16:01:56 +0800 Subject: [PATCH] sim/devices: port to NAC3 --- artiq/sim/devices.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/artiq/sim/devices.py b/artiq/sim/devices.py index 18b997b69..fc258ed48 100644 --- a/artiq/sim/devices.py +++ b/artiq/sim/devices.py @@ -1,18 +1,18 @@ from random import Random -import numpy -from artiq.language.core import kernel +from artiq.language.core import kernel, sequential, delay_mu from artiq.sim import time class Core: def __init__(self, dmgr): - self.ref_period = 1 + self.ref_period = 1e-6 self._level = 0 def run(self, k_function, k_args, k_kwargs): self._level += 1 - r = k_function.artiq_embedded.function(*k_args, **k_kwargs) + with sequential: + r = getattr(k_function.__self__, k_function.__name__).__wrapped__(k_function.__self__, *k_args, **k_kwargs) self._level -= 1 if self._level == 0: print(time.manager.format_timeline()) @@ -20,33 +20,35 @@ class Core: return r def seconds_to_mu(self, seconds): - return numpy.int64(seconds//self.ref_period) + return round(seconds/self.ref_period) def mu_to_seconds(self, mu): return mu*self.ref_period + def delay(self, seconds): + delay_mu(self.seconds_to_mu(seconds)) + class Input: def __init__(self, dmgr, name): self.core = dmgr.get("core") self.name = name - self.prng = Random() @kernel def gate_rising(self, duration): time.manager.event(("gate_rising", self.name, duration)) - delay(duration) + self.core.delay(duration) @kernel def gate_falling(self, duration): time.manager.event(("gate_falling", self.name, duration)) - delay(duration) + self.core.delay(duration) @kernel def gate_both(self, duration): time.manager.event(("gate_both", self.name, duration)) - delay(duration) + self.core.delay(duration) @kernel def count(self, up_to_timestamp_mu): @@ -75,7 +77,7 @@ class Output: @kernel def pulse(self, duration): time.manager.event(("pulse", self.name, duration)) - delay(duration) + self.core.delay(duration) @kernel def on(self): @@ -94,7 +96,7 @@ class WaveOutput: @kernel def pulse(self, frequency, duration): time.manager.event(("pulse", self.name, frequency, self.core.seconds_to_mu(duration))) - delay(duration) + self.core.delay(duration) class VoltageOutput: