sim: use MPO

This commit is contained in:
Sebastien Bourdeauducq 2014-08-13 18:16:40 +08:00
parent 2135e37dca
commit eb4054d976
2 changed files with 21 additions and 24 deletions

View File

@ -1,5 +1,6 @@
from random import Random from random import Random
from artiq.language.core import MPO, delay
from artiq.language import units from artiq.language import units
from artiq.sim import time from artiq.sim import time
@ -7,37 +8,32 @@ class Core:
def run(self, k_function, k_args, k_kwargs): def run(self, k_function, k_args, k_kwargs):
return k_function(*k_args, **k_kwargs) return k_function(*k_args, **k_kwargs)
class Input: class Input(MPO):
def __init__(self, name, prng_seed=None, wait_max=20, count_max=100, wait_min=0, count_min=0): parameters = "name"
self.name = name
self.wait_min = wait_min def build(self):
self.wait_max = wait_max self.prng = Random()
self.count_min = count_min
self.count_max = count_max
self.prng = Random(prng_seed)
def wait_edge(self): def wait_edge(self):
duration = self.prng.randrange(self.wait_min, self.wait_max)*units.ms duration = self.prng.randrange(0, 20)*units.ms
time.manager.event(("wait_edge", self.name, duration)) time.manager.event(("wait_edge", self.name, duration))
time.manager.take_time(duration) delay(duration)
def count_gate(self, duration): def count_gate(self, duration):
result = self.prng.randrange(self.count_min, self.count_max) result = self.prng.randrange(0, 100)
time.manager.event(("count_gate", self.name, duration, result)) time.manager.event(("count_gate", self.name, duration, result))
time.manager.take_time(duration) delay(duration)
return result return result
class WaveOutput: class WaveOutput(MPO):
def __init__(self, name): parameters = "name"
self.name = name
def pulse(self, frequency, duration): def pulse(self, frequency, duration):
time.manager.event(("pulse", self.name, frequency, duration)) time.manager.event(("pulse", self.name, frequency, duration))
time.manager.take_time(duration) delay(duration)
class VoltageOutput: class VoltageOutput(MPO):
def __init__(self, name): parameters = "name"
self.name = name
def set(self, value): def set(self, value):
time.manager.event(("set_voltage", self.name, value)) time.manager.event(("set_voltage", self.name, value))

View File

@ -18,12 +18,13 @@ if __name__ == "__main__":
from artiq.sim import devices as sd from artiq.sim import devices as sd
from artiq.sim import time from artiq.sim import time
coredev = sd.Core()
exp = SimpleSimulation( exp = SimpleSimulation(
core=sd.Core(), core=coredev,
a=sd.WaveOutput("a"), a=sd.WaveOutput(core=coredev, name="a"),
b=sd.WaveOutput("b"), b=sd.WaveOutput(core=coredev, name="b"),
c=sd.WaveOutput("c"), c=sd.WaveOutput(core=coredev, name="c"),
d=sd.WaveOutput("d"), d=sd.WaveOutput(core=coredev, name="d"),
) )
exp.run() exp.run()
print(time.manager.format_timeline()) print(time.manager.format_timeline())