Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qhc 736 bug wrong array output for qbloxresult from qprogram #853

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
424f14c
typo and wip
jjmartinezQT Dec 11, 2024
9507e89
reshaping i/q acquisitions
jjmartinezQT Dec 13, 2024
fcb2d26
reshaping higher dims than 2 generically
jjmartinezQT Dec 13, 2024
17bdfb6
reshape
jjmartinezQT Dec 13, 2024
91a237d
reshaping also thresholds after Adrián reshaping
jjmartinezQT Dec 13, 2024
02b3821
including shape in test results
jjmartinezQT Dec 13, 2024
933b117
adding shape
jjmartinezQT Dec 13, 2024
fadd6cf
adding shape
jjmartinezQT Dec 13, 2024
663edb8
wip
jjmartinezQT Dec 13, 2024
66dd306
readding shape to qblox measurement result
jjmartinezQT Dec 13, 2024
70d8729
reshaping
jjmartinezQT Dec 13, 2024
68eeced
using None as default shape for reshaping
jjmartinezQT Dec 13, 2024
f6c3381
Merge branch 'main' into qhc-736-bug-wrong-array-output-for-qbloxresu…
jjmartinezQT Dec 13, 2024
6f1289b
changelog
jjmartinezQT Dec 13, 2024
1b69991
types for shape
jjmartinezQT Dec 17, 2024
c88d1fc
Update src/qililab/result/qprogram/qblox_measurement_result.py
jjmartinezQT Dec 17, 2024
667e80c
print statement
jjmartinezQT Dec 17, 2024
5f3ef12
separation for clarity
jjmartinezQT Dec 17, 2024
d556261
missing 2 dimension
jjmartinezQT Dec 18, 2024
75f68d2
fixing tests
jjmartinezQT Dec 18, 2024
91952a5
fixing unittests
jjmartinezQT Dec 18, 2024
19aa5aa
fixing unittest
jjmartinezQT Dec 18, 2024
1b0159c
Merge branch 'main' into qhc-736-bug-wrong-array-output-for-qbloxresu…
jjmartinezQT Dec 18, 2024
1fb3077
fixing unittest after merging main
jjmartinezQT Dec 18, 2024
2bbe09c
Merge branch 'main' into qhc-736-bug-wrong-array-output-for-qbloxresu…
jjmartinezQT Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

### Bug fixes

- Fixed an issue where having nested loops would output wrong shape in QbloxMeasurementResult.
[#853](https://github.com/qilimanjaro-tech/qililab/pull/853)

- Fixed an issue where appending a configuration to an open QM instance left it hanging. The QM now properly closes before reopening with the updated configuration.
[#851](https://github.com/qilimanjaro-tech/qililab/pull/851)

- Fixed an issue where turning off voltage/current source instruments would set to zero all dacs instead of only the ones specified in the runcard.
[#819](https://github.com/qilimanjaro-tech/qililab/pull/819)
[#819](https://github.com/qilimanjaro-tech/qililab/pull/819)
8 changes: 5 additions & 3 deletions src/qililab/instruments/qblox/qblox_qrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def acquire_qprogram_results(
list[QbloxQProgramMeasurementResult]: Acquired Qblox results in chronological order.
"""
results = []
for acquisition, acquistion_data in acquisitions.items():
for acquisition, acquisition_data in acquisitions.items():
sequencer = next(
(sequencer for sequencer in self.awg_sequencers if sequencer.identifier == channel_id), None
)
Expand All @@ -184,13 +184,15 @@ def acquire_qprogram_results(
sequencer=sequencer.identifier,
timeout=cast(QbloxADCSequencer, sequencer).acquisition_timeout,
)
if acquistion_data.save_adc:
if acquisition_data.save_adc:
self.device.store_scope_acquisition(sequencer=sequencer.identifier, name=acquisition)
raw_measurement_data = self.device.get_acquisitions(sequencer=sequencer.identifier)[acquisition][
"acquisition"
]
measurement_result = QbloxMeasurementResult(
bus=acquisitions[acquisition].bus, raw_measurement_data=raw_measurement_data
bus=acquisitions[acquisition].bus,
raw_measurement_data=raw_measurement_data,
shape=acquisition_data.shape
)
results.append(measurement_result)

Expand Down
4 changes: 3 additions & 1 deletion src/qililab/qprogram/qblox_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AcquisitionData:

bus: str
save_adc: bool
shape: tuple


Sequences = dict[str, QPy.Sequence]
Expand Down Expand Up @@ -531,6 +532,7 @@ def _handle_acquire(self, element: Acquire):
for i, loop in enumerate(self._buses[element.bus].qpy_block_stack)
if isinstance(loop, QPyProgram.IterativeLoop) and not loop.name.startswith("avg")
]
shape = tuple(loop[1].iterations for loop in loops)
num_bins = math.prod(loop[1].iterations for loop in loops)
acquisition_name = f"acquisition_{self._buses[element.bus].next_acquisition_index}"
self._buses[element.bus].qpy_sequence._acquisitions.add(
Expand All @@ -539,7 +541,7 @@ def _handle_acquire(self, element: Acquire):
index=self._buses[element.bus].next_acquisition_index,
)
self._buses[element.bus].acquisitions[acquisition_name] = AcquisitionData(
bus=element.bus, save_adc=element.save_adc
bus=element.bus, save_adc=element.save_adc, shape=shape
)

index_I, index_Q, integration_length = self._append_to_weights_of_bus(element.bus, weights=element.weights)
Expand Down
3 changes: 2 additions & 1 deletion src/qililab/result/qprogram/measurement_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class MeasurementResult(ABC):

name: ResultName

def __init__(self, bus: str):
def __init__(self, bus: str, shape=None):
jjmartinezQT marked this conversation as resolved.
Show resolved Hide resolved
self.bus: str = bus
self.shape = shape

@property
@abstractmethod
Expand Down
8 changes: 5 additions & 3 deletions src/qililab/result/qprogram/qblox_measurement_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ class QbloxMeasurementResult(MeasurementResult):

name = ResultName.QBLOX_QPROGRAM_MEASUREMENT

def __init__(self, bus: str, raw_measurement_data: dict):
def __init__(self, bus: str, raw_measurement_data: dict, shape=None):
jjmartinezQT marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(bus=bus)
self.raw_measurement_data = raw_measurement_data
self.shape = shape

@property
def array(self) -> np.ndarray:
Expand All @@ -52,7 +53,8 @@ def array(self) -> np.ndarray:
"""
path0 = self.raw_measurement_data["bins"]["integration"]["path0"]
path1 = self.raw_measurement_data["bins"]["integration"]["path1"]
return np.array([path0, path1])

return np.array([path0, path1]) if self.shape is None else np.array([path0, path1]).reshape(*self.shape)
jjmartinezQT marked this conversation as resolved.
Show resolved Hide resolved

@property
def threshold(self) -> np.ndarray:
Expand All @@ -61,4 +63,4 @@ def threshold(self) -> np.ndarray:
Returns:
np.ndarray: The thresholded data.
"""
return np.array(self.raw_measurement_data["bins"]["threshold"])
return np.array(self.raw_measurement_data["bins"]["threshold"]) if self.shape is None else np.array(self.raw_measurement_data["bins"]["threshold"]).reshape(*self.shape)
jjmartinezQT marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 8 additions & 8 deletions tests/instruments/qblox/test_qblox_qrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import copy
import re
from unittest.mock import MagicMock, patch, create_autospec
from typing import cast
from unittest.mock import MagicMock, create_autospec, patch

import numpy as np
import pytest
from qblox_instruments.qcodes_drivers.module import Module as QcmQrm
from qblox_instruments.qcodes_drivers.sequencer import Sequencer
from qpysequence import Acquisitions, Program, Sequence, Waveforms, Weights

from qililab.data_management import build_platform
from qililab.instrument_controllers.qblox.qblox_cluster_controller import QbloxClusterController
from qililab.instruments.instrument import ParameterNotFound
from qililab.instruments.qblox import QbloxQRM
from qililab.platform import Platform
from qililab.data_management import build_platform
from qililab.typings import AcquireTriggerMode, IntegrationMode, Parameter
from typing import cast
from qblox_instruments.qcodes_drivers.sequencer import Sequencer
from qblox_instruments.qcodes_drivers.module import Module as QcmQrm
from qililab.qprogram.qblox_compiler import AcquisitionData
from qililab.typings import AcquireTriggerMode, IntegrationMode, Parameter


@pytest.fixture(name="platform")
Expand Down Expand Up @@ -394,8 +394,8 @@ def test_acquire_qprogram_results(self, qrm: QbloxQRM):
qrm.upload_qpysequence(qpysequence=sequence, channel_id=0)

qp_acqusitions = {
"acquisition_0": AcquisitionData(bus="readout_q0", save_adc=False),
"acquisition_1": AcquisitionData(bus="readout_q0", save_adc=True)
"acquisition_0": AcquisitionData(bus="readout_q0", save_adc=False, shape=(-1,)),
"acquisition_1": AcquisitionData(bus="readout_q0", save_adc=True, shape=(-1,))
jjmartinezQT marked this conversation as resolved.
Show resolved Hide resolved
}

qrm.acquire_qprogram_results(acquisitions=qp_acqusitions, channel_id=0)
Expand Down
1 change: 1 addition & 0 deletions tests/result/qprogram/test_qblox_measurement_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_array_property(self, raw_measurement_data: dict, qblox_measurement_resu
path0 = raw_measurement_data["bins"]["integration"]["path0"]
path1 = raw_measurement_data["bins"]["integration"]["path1"]
expected_array = np.array([path0, path1])
print(f"expected_array shape {expected_array.shape}")
jjmartinezQT marked this conversation as resolved.
Show resolved Hide resolved
assert np.allclose(qblox_measurement_result.array, expected_array)

def test_serialization_deserialization(self, qblox_measurement_result: QbloxMeasurementResult):
Expand Down
Loading