mirror of https://github.com/m-labs/artiq.git
sim: use MPO
This commit is contained in:
parent
2135e37dca
commit
eb4054d976
|
@ -1,5 +1,6 @@
|
|||
from random import Random
|
||||
|
||||
from artiq.language.core import MPO, delay
|
||||
from artiq.language import units
|
||||
from artiq.sim import time
|
||||
|
||||
|
@ -7,37 +8,32 @@ class Core:
|
|||
def run(self, k_function, k_args, k_kwargs):
|
||||
return k_function(*k_args, **k_kwargs)
|
||||
|
||||
class Input:
|
||||
def __init__(self, name, prng_seed=None, wait_max=20, count_max=100, wait_min=0, count_min=0):
|
||||
self.name = name
|
||||
self.wait_min = wait_min
|
||||
self.wait_max = wait_max
|
||||
self.count_min = count_min
|
||||
self.count_max = count_max
|
||||
self.prng = Random(prng_seed)
|
||||
class Input(MPO):
|
||||
parameters = "name"
|
||||
|
||||
def build(self):
|
||||
self.prng = Random()
|
||||
|
||||
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.take_time(duration)
|
||||
delay(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.take_time(duration)
|
||||
delay(duration)
|
||||
return result
|
||||
|
||||
class WaveOutput:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
class WaveOutput(MPO):
|
||||
parameters = "name"
|
||||
|
||||
def pulse(self, frequency, duration):
|
||||
time.manager.event(("pulse", self.name, frequency, duration))
|
||||
time.manager.take_time(duration)
|
||||
delay(duration)
|
||||
|
||||
class VoltageOutput:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
class VoltageOutput(MPO):
|
||||
parameters = "name"
|
||||
|
||||
def set(self, value):
|
||||
time.manager.event(("set_voltage", self.name, value))
|
||||
|
|
|
@ -18,12 +18,13 @@ if __name__ == "__main__":
|
|||
from artiq.sim import devices as sd
|
||||
from artiq.sim import time
|
||||
|
||||
coredev = sd.Core()
|
||||
exp = SimpleSimulation(
|
||||
core=sd.Core(),
|
||||
a=sd.WaveOutput("a"),
|
||||
b=sd.WaveOutput("b"),
|
||||
c=sd.WaveOutput("c"),
|
||||
d=sd.WaveOutput("d"),
|
||||
core=coredev,
|
||||
a=sd.WaveOutput(core=coredev, name="a"),
|
||||
b=sd.WaveOutput(core=coredev, name="b"),
|
||||
c=sd.WaveOutput(core=coredev, name="c"),
|
||||
d=sd.WaveOutput(core=coredev, name="d"),
|
||||
)
|
||||
exp.run()
|
||||
print(time.manager.format_timeline())
|
||||
|
|
Loading…
Reference in New Issue