Skip to content

Commit

Permalink
refactor: clean up result management
Browse files Browse the repository at this point in the history
  • Loading branch information
sorewachigauyo authored and alecandido committed Oct 28, 2024
1 parent c0b9564 commit 3a48f83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/qibolab/_core/instruments/keysight/qcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def play(

for result, input_op in zip(raw.values(), input_ops):

ret[input_op.id] = parse_result(result, options, sweepers)
ret[input_op.id] = parse_result(result, options)

return ret

Expand Down
33 changes: 12 additions & 21 deletions src/qibolab/_core/instruments/keysight/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
AveragingMode,
ExecutionParameters,
)
from qibolab._core.sweeper import ParallelSweepers


def fetch_result(
Expand Down Expand Up @@ -40,9 +39,7 @@ def fetch_result(
return raw


def parse_result(
result: np.ndarray, options: ExecutionParameters, sweepers: list[ParallelSweepers]
) -> np.ndarray:
def parse_result(result: np.ndarray, options: ExecutionParameters) -> np.ndarray:
"""Parses resulting numpy array into Qibolab expected array shape.
Arguments:
Expand All @@ -55,22 +52,16 @@ def parse_result(
"""
# For single shot, qibolab expects result format (nshots, ...)
# QCS returns (..., nshots), so we need to shuffle the arrays
if options.averaging_mode is AveragingMode.SINGLESHOT and len(sweepers) > 0:
tmp = np.zeros(options.results_shape(sweepers))
# For IQ data, QCS returns complex results
if options.acquisition_type is AcquisitionType.INTEGRATION:
for k in range(options.nshots):
tmp[k, ..., 0] = np.real(result[..., k])
tmp[k, ..., 1] = np.imag(result[..., k])
else:
for k in range(options.nshots):
tmp[k, ...] = result[..., k]

if (
options.averaging_mode is not AveragingMode.SINGLESHOT
and options.acquisition_type is not AcquisitionType.INTEGRATION
):
return result
# For single shot, qibolab expects result format (nshots, ...)
# QCS returns (..., nshots), so we need to shuffle the arrays
if options.averaging_mode is AveragingMode.SINGLESHOT:
result = np.moveaxis(result, -1, 0)
# For IQ data, QCS returns complex results
elif options.acquisition_type is AcquisitionType.INTEGRATION:
tmp = np.zeros(options.results_shape(sweepers))
tmp[..., 0] = np.real(result)
tmp[..., 1] = np.imag(result)
else:
if options.acquisition_type is not AcquisitionType.INTEGRATION:
return result
return tmp
return np.moveaxis(np.stack([np.real(result), np.imag(result)]), 0, -1)

0 comments on commit 3a48f83

Please sign in to comment.