Created
April 24, 2019 18:25
-
-
Save mfe5003/e19fb9c1e2123ee9da22f473c65c4a7c to your computer and use it in GitHub Desktop.
artiq for loop converted to sequential
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################################################################################## | |
# ParallelForLoopTest | |
# | |
# Connectivity | |
# * TTL4 [output] -> MSOX2024A Channel 1 (trigger) | |
# * TTL7 [output] -> MSOX2024A Channel 2 | |
# | |
# Description | |
# | |
######################################################################################################################## | |
from artiq.experiment import * | |
class SetDigitalOutput(object): | |
def __init__(self, device, state, delay): | |
self._device = device | |
self._state = state | |
self._delay = delay | |
@kernel | |
def run(self): | |
with sequential: | |
delay(self._delay) | |
self._device.set_o(self._state) | |
class ParallelForLoopTest(EnvExperiment): | |
def build(self): | |
# core device | |
self.setattr_device('core') | |
# TTL channels | |
self.setattr_device('ttl4') | |
self.setattr_device('ttl7') | |
def run(self): | |
self.pulses_phase0 = [SetDigitalOutput(self.ttl4, True, 5*ms), SetDigitalOutput(self.ttl7, True, 0*ms)] | |
self.k_run() | |
@kernel | |
def k_run(self): | |
# core | |
self.core.reset() | |
# TTL | |
self.ttl4.output() | |
self.ttl7.output() | |
self.ttl4.off() | |
self.ttl7.off() | |
# short delay so setup pulses are not overwritten | |
delay(1 * ms) | |
# scope trigger | |
self.ttl4.pulse(1 * ms) | |
delay(1 * ms) | |
# set the dio channel in a for loop using funciton pointers | |
with parallel: | |
# parallel_start_mu = now_mu() # uncomment this line to mitigate | |
for pulse in self.pulses_phase0: | |
# at_mu(parallel_start_mu) # uncomment this line to mitigate | |
pulse.run() | |
delay(10 * ms) | |
# lower the ttl channels and wait for visibility | |
self.ttl4.off() | |
self.ttl7.off() | |
delay(5*ms) | |
# unroll the same funciton pointers manually | |
with parallel: | |
self.pulses_phase0[0].run() | |
self.pulses_phase0[1].run() | |
delay(10 * ms) | |
self.ttl4.off() | |
self.ttl7.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment