forked from M-Labs/artiq
1
0
Fork 0

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.
This commit is contained in:
Robert Jördens 2016-02-23 21:00:22 +01:00
parent 856821849f
commit 5599ec16ea
2 changed files with 53 additions and 12 deletions

View File

@ -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):

View File

@ -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