From 5599ec16ea04aec484c671470161fa89a90efa28 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Tue, 23 Feb 2016 21:00:22 +0100 Subject: [PATCH] sim: align API closer to non-sim * add Output * also clear timeline after it has been printed (multiple kernel invocations) The sim core device API has diverged quite a bit from the non-sim API. More work is needed. --- artiq/sim/devices.py | 55 ++++++++++++++++++++++++++++----- examples/sim/al_spectroscopy.py | 10 +++--- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/artiq/sim/devices.py b/artiq/sim/devices.py index 7d1c387a3..95e72f984 100644 --- a/artiq/sim/devices.py +++ b/artiq/sim/devices.py @@ -1,7 +1,6 @@ from random import Random -from artiq.language.core import delay, kernel -from artiq.language import units +from artiq.language.core import delay, at_mu, kernel from artiq.sim import time @@ -16,6 +15,7 @@ class Core: self._level -= 1 if self._level == 0: print(time.manager.format_timeline()) + time.manager.timeline.clear() return r @@ -27,18 +27,57 @@ class Input: self.prng = Random() @kernel - def wait_edge(self): - duration = self.prng.randrange(0, 20)*units.ms - time.manager.event(("wait_edge", self.name, duration)) + def gate_rising(self, duration): + time.manager.event(("gate_rising", self.name, duration)) delay(duration) @kernel - def count_gate(self, duration): - result = self.prng.randrange(0, 100) - time.manager.event(("count_gate", self.name, duration, result)) + def gate_falling(self, duration): + time.manager.event(("gate_falling", self.name, duration)) delay(duration) + + @kernel + def gate_both(self, duration): + time.manager.event(("gate_both", self.name, duration)) + delay(duration) + + @kernel + def count(self): + result = self.prng.randrange(0, 100) + time.manager.event(("count", self.name, result)) return result + @kernel + def timestamp_mu(self): + result = time.manager.get_time_mu() + result += self.prng.randrange(100, 1000) + time.manager.event(("timestamp_mu", self.name, result)) + at_mu(result) + return result + + +class Output: + def __init__(self, dmgr, name): + self.core = dmgr.get("core") + self.name = name + + @kernel + def set_o(self, value): + time.manager.event(("set", self.name, value)) + + @kernel + def pulse(self, duration): + time.manager.event(("pulse", self.name, duration)) + delay(duration) + + @kernel + def on(self): + self.set_o(True) + + @kernel + def off(self): + self.set_o(False) + class WaveOutput: def __init__(self, dmgr, name): diff --git a/examples/sim/al_spectroscopy.py b/examples/sim/al_spectroscopy.py index bfbf1c5c4..d20d2934d 100644 --- a/examples/sim/al_spectroscopy.py +++ b/examples/sim/al_spectroscopy.py @@ -20,7 +20,8 @@ class AluminumSpectroscopy(EnvExperiment): def run(self): state_0_count = 0 for count in range(100): - self.mains_sync.wait_edge() + self.mains_sync.gate_rising(1*s/60) + at_mu(self.mains_sync.timestamp_mu() + 100*us) delay(10*us) self.laser_cooling.pulse(100*MHz, 100*us) delay(5*us) @@ -34,9 +35,10 @@ class AluminumSpectroscopy(EnvExperiment): delay(5*us) with parallel: self.state_detection.pulse(100*MHz, 10*us) - photon_count = self.pmt.count_gate(10*us) - if (photon_count < self.photon_limit_low - or photon_count > self.photon_limit_high): + self.pmt.gate_rising(10*us) + photon_count = self.pmt.count() + if (photon_count < self.photon_limit_low or + photon_count > self.photon_limit_high): break if photon_count < self.photon_limit_low: state_0_count += 1