Hi everyone,
I am trying to perform a mid-circuit measurement where in the beginning of my control code, I use self.ttl0_counter.gate_rising_mu() and self.ttl0_counter.fetch_count() to detect and count photons in a repeating loop until the photon counts meets a preset threshold. Once the photon counts meets the threshold, I exit the loop and move onto the rest of the experiment.
My questions are:
Is there a way to set how long one iteration of the mid-circuit measurement will take? I know the detection time is pre-defined using self.ttl0_counter.gate_rising_mu(), but I am unsure how long self.ttl0_counter.fetch_count() takes. I want to give fetch_count() enough time to finish but also keep the amount of time it takes the same each time. The structure of my code looks like this:
@kernel
def run(self):
self.core.reset()
for i in range(self.n_cycles):
counts = 0
n_repeats = -1
while counts < self.photon_threshold: # photon_threshold = 1
self.init_loop()
with parallel:
delay_mu(self.delay_after_init_loop) # This is a 12 us delay
n_repeats += 1
counts = self.ttl0_counter.fetch_count()
self.remainder_of_experiment() # the remainder of the experiment
@kernel
def init_loop(self):
cursor = now_mu()
at_mu(cursor)
delay_mu(self.green_laser_duration_mu)
self.suservo0_ch0.set(en_out=1, en_iir=0, profile=0)
delay_mu(self.readout_duration_mu)
self.suservo0_ch0.set(en_out=0, en_iir=0, profile=0)
at_mu(cursor)
delay_mu(self.green_laser_duration_mu)
self.suservo0_ch1.set(en_out=1, en_iir=0, profile=1)
delay_mu(self.readout_duration_mu)
self.suservo0_ch1.set(en_out=0, en_iir=0, profile=1)
at_mu(cursor)
self.ttl4.pulse_mu(self.green_laser_duration_mu)
self.ttl0_counter.gate_rising_mu(self.readout_duration_mu)
Currently, I use a 12 us delay (self.delay_after_init_loop) after each self.init_loop() iteration, which I find is necessary to not give me an underflow error. If I structure my parallel loop as shown above, will it ensure the fetch_count() step will happen during that 12us window? And if fetch_count() finishes faster than 12us, will the code just wait until the 12us is done before either going through the loop again or moving onto the remainder of the experiment? My goal here is to keep the amount of time each iteration of self.init_loop followed by self.ttl0_counter.fetch_count() the same each time.
Thanks!