From 765e40c4cb1c966a5ed0fdeed5e33b73e984a68f Mon Sep 17 00:00:00 2001 From: Yves Salathe Date: Wed, 25 Jan 2023 21:29:59 +0100 Subject: [PATCH 1/2] UHF multi-detector: pad result vectors to have equal length --- pycqed/measurement/det_fncs/hard/UHFQC.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pycqed/measurement/det_fncs/hard/UHFQC.py b/pycqed/measurement/det_fncs/hard/UHFQC.py index d582f74558..2cabaccfac 100644 --- a/pycqed/measurement/det_fncs/hard/UHFQC.py +++ b/pycqed/measurement/det_fncs/hard/UHFQC.py @@ -44,6 +44,22 @@ def get_values(self): for detector in self.detectors: new_values = detector.get_values(arm=False, is_single_detector=False) values_list.append(new_values) + + # Pad all result vectors for them to have equal length. + maximum = 0 + minimum = len(values_list[0][0]) #left index of values_list: detector; right index: channel + for feedline in values_list: + for result in feedline: + if len(result)>maximum: maximum=len(result) + if len(result) Date: Wed, 25 Jan 2023 14:35:51 +0100 Subject: [PATCH 2/2] Loop over detectors in the inner-most poll loop in the UHF multi detector. --- pycqed/measurement/det_fncs/hard/UHFQC.py | 71 ++++++++++++++++++++--- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/pycqed/measurement/det_fncs/hard/UHFQC.py b/pycqed/measurement/det_fncs/hard/UHFQC.py index 2cabaccfac..4d836f6663 100644 --- a/pycqed/measurement/det_fncs/hard/UHFQC.py +++ b/pycqed/measurement/det_fncs/hard/UHFQC.py @@ -4,6 +4,7 @@ """ import logging +import time import numpy as np import numpy.fft as fft from string import ascii_uppercase @@ -15,7 +16,6 @@ from pycqed.instrument_drivers.physical_instruments.QuTech.CC import CC from pycqed.instrument_drivers.physical_instruments.ZurichInstruments.UHFQuantumController import UHFQC - log = logging.getLogger(__name__) @@ -25,8 +25,6 @@ class Multi_Detector_UHF(Multi_Detector): """ def get_values(self): - values_list = [] - # Since master (holding cc object) is first in self.detectors, self.detectors[0].AWG.stop() @@ -40,10 +38,57 @@ def get_values(self): # Run (both in parallel and implicitly) self.detectors[0].AWG.start() + # Define the timeout as the timeout defined for the first UHF + timeout = self.detectors[0].UHFQC.timeout() + # Get data + # Initialize the dictionaries to store the data from the detector + data_raw = [] + gotem = [] for detector in self.detectors: - new_values = detector.get_values(arm=False, is_single_detector=False) - values_list.append(new_values) + data_raw.append({k: [] for k, _ in enumerate(detector.UHFQC._acquisition_nodes)}) + gotem.append([False]*len(detector.UHFQC._acquisition_nodes)) + + start_time = time.time() + # Outer loop: repeat until all results are acquired or timeout is reached + while (time.time() - start_time) < timeout and not all(all(g) for g in gotem): + + # Inner loop over detectors + for m, detector in enumerate(self.detectors): + + # Poll the data with a short interval + poll_interval_seconds = 0.010 + dataset = detector.UHFQC.poll(poll_interval_seconds) + + # Loop over the nodes (channels) of the detector + for n, p in enumerate(detector.UHFQC._acquisition_nodes): + + # check if the node is in the dataset returned by the poll() function + if p in dataset: + + # Note: we only expect one vector per node (m: detector, n: channel) + data_raw[m][n] = dataset[p][0]['vector'] + + # check if the vector has the right length + if len(data_raw[m][n]) == detector.get_num_samples(): + gotem[m][n] = True + + # Error handling + if not all(all(g) for g in gotem): + for m, detector in enumerate(self.detectors): + detector.UHFQC.acquisition_finalize() + for n, _c in enumerate(detector.UHFQC._acquisition_nodes): + if n in data_raw[m]: + print("\t{}: Channel {}: Got {} of {} samples".format( + detector.UHFQC.devname, n, len(data_raw[m][n]), detector.get_num_samples())) + raise TimeoutError("Error: Didn't get all results!") + + # Post-process the data + # Note: the detector must feature the get_values_postprocess() function + # to be used within the multi-detector + values_list = [] + for m, detector in enumerate(self.detectors): + values_list.append(detector.get_values_postprocess(data_raw[m])) # Pad all result vectors for them to have equal length. maximum = 0 @@ -383,6 +428,9 @@ def arm(self): self.UHFQC.acquisition_arm() self.UHFQC.sync() + def get_num_samples(self): + return self.nr_sweep_points + def get_values(self, arm=True, is_single_detector=True): if is_single_detector: if self.always_prepare: @@ -399,8 +447,11 @@ def get_values(self, arm=True, is_single_detector=True): if self.AWG is not None: self.AWG.start() - data_raw = self.UHFQC.acquisition_poll(samples=self.nr_sweep_points, arm=False, acquisition_time=0.01) + data_raw = self.UHFQC.acquisition_poll(samples=self.get_num_samples(), arm=False, acquisition_time=0.01) + + return self.get_values_postprocess(data_raw) + def get_values_postprocess(self, data_raw): # if len(data_raw[next(iter(data_raw))])>1: # print('[DEBUG UHF SWF] SHOULD HAVE HAD AN ERROR') # data = np.array([data_raw[key] @@ -750,6 +801,9 @@ def arm(self): self.UHFQC.acquisition_arm() self.UHFQC.sync() + def get_num_samples(self): + return self.nr_shots + def get_values(self, arm=True, is_single_detector=True): if is_single_detector: if self.always_prepare: @@ -767,7 +821,10 @@ def get_values(self, arm=True, is_single_detector=True): self.AWG.start() # Get the data - data_raw = self.UHFQC.acquisition_poll(samples=self.nr_shots, arm=False, acquisition_time=0.01) + data_raw = self.UHFQC.acquisition_poll(samples=self.get_num_samples(), arm=False, acquisition_time=0.01) + return self.get_values_postprocess(data_raw) + + def get_values_postprocess(self, data_raw): data = np.array([data_raw[key] # data = np.array([data_raw[key][-1] for key in sorted(data_raw.keys())])*self.scaling_factor