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

Remove results manipulation functions #1027

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions doc/source/getting-started/experiment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ We leave to the dedicated tutorial a full explanation of the experiment, but her

from qibolab import create_platform
from qibolab.sequence import PulseSequence
from qibolab.result import magnitude
from qibolab.sweeper import Sweeper, Parameter
from qibolab.execution_parameters import (
ExecutionParameters,
Expand Down Expand Up @@ -238,7 +237,8 @@ We leave to the dedicated tutorial a full explanation of the experiment, but her
_, acq = next(iter(sequence.acquisitions))

# plot the results
amplitudes = magnitude(results[acq.id])
signal_i, signal_q = np.moveaxis(results[acq.id], -1, 0)
amplitudes = np.abs(signal_i + 1j * signal_q)
frequencies = sweeper.values

plt.title("Resonator Spectroscopy")
Expand Down
11 changes: 5 additions & 6 deletions doc/source/tutorials/calibration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ around the pre-defined frequency.
import numpy as np
from qibolab import create_platform
from qibolab.sequence import PulseSequence
from qibolab.result import magnitude
from qibolab.sweeper import Sweeper, Parameter
from qibolab.execution_parameters import (
ExecutionParameters,
Expand Down Expand Up @@ -74,7 +73,8 @@ In few seconds, the experiment will be finished and we can proceed to plot it.
import matplotlib.pyplot as plt

acq = sequence.acquisitions[0][1]
amplitudes = magnitude(results[acq.id])
signal_i, signal_q = np.moveaxis(results[acq.id], -1, 0)
amplitudes = np.abs(signal_i + 1j * signal_q)
frequencies = sweeper.values

plt.title("Resonator Spectroscopy")
Expand Down Expand Up @@ -113,7 +113,6 @@ complex pulse sequence. Therefore with start with that:
from qibolab import create_platform
from qibolab.pulses import Pulse, Delay, Gaussian
from qibolab.sequence import PulseSequence
from qibolab.result import magnitude
from qibolab.sweeper import Sweeper, Parameter
from qibolab.execution_parameters import (
ExecutionParameters,
Expand Down Expand Up @@ -165,7 +164,8 @@ We can now proceed to launch on hardware:
results = platform.execute([sequence], options, [[sweeper]])

_, acq = next(iter(sequence.acquisitions))
amplitudes = magnitude(results[acq.id])
signal_i, signal_q = np.moveaxis(results[acq.id], -1, 0)
amplitudes = np.abs(signal_i + 1j * signal_q)
frequencies = sweeper.values

plt.title("Resonator Spectroscopy")
Expand Down Expand Up @@ -218,7 +218,6 @@ and its impact on qubit states in the IQ plane.
from qibolab import create_platform
from qibolab.pulses import Delay
from qibolab.sequence import PulseSequence
from qibolab.result import unpack
from qibolab.sweeper import Sweeper, Parameter
from qibolab.execution_parameters import (
ExecutionParameters,
Expand Down Expand Up @@ -263,7 +262,7 @@ and its impact on qubit states in the IQ plane.
label="One state",
)
plt.scatter(
*unpack(results_zero[acq0.id]),
*tuple(np.moveaxis(results_zero[acq0.id], -1, 0)),
label="Zero state",
)
plt.show()
Expand Down
6 changes: 6 additions & 0 deletions src/qibolab/identifier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Annotated, Union

import numpy as np
import numpy.typing as npt
from pydantic import BeforeValidator, Field, PlainSerializer

QubitId = Annotated[Union[int, str], Field(union_mode="left_to_right")]
Expand Down Expand Up @@ -41,3 +43,7 @@ def _join(pair: tuple[str, str]) -> str:
tuple[QubitId, QubitId], BeforeValidator(_split), PlainSerializer(_join)
]
"""Two-qubit active interaction identifier."""


Result = npt.NDArray[np.float64]
"""An array of results returned by instruments."""
5 changes: 2 additions & 3 deletions src/qibolab/instruments/abstract.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from abc import ABC, abstractmethod
from typing import Optional

import numpy.typing as npt
from pydantic import ConfigDict, Field

from qibolab.components import Config
from qibolab.components.channels import Channel
from qibolab.execution_parameters import ExecutionParameters
from qibolab.identifier import ChannelId
from qibolab.identifier import ChannelId, Result
from qibolab.sequence import PulseSequence
from qibolab.serialize import Model
from qibolab.sweeper import ParallelSweepers
Expand Down Expand Up @@ -73,7 +72,7 @@ def play(
sequences: list[PulseSequence],
options: ExecutionParameters,
sweepers: list[ParallelSweepers],
) -> dict[int, npt.NDArray]:
) -> dict[int, Result]:
"""Play a pulse sequence and retrieve feedback.

If :class:`qibolab.sweeper.Sweeper` objects are passed as arguments, they are
Expand Down
26 changes: 17 additions & 9 deletions src/qibolab/instruments/qm/program/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@
AveragingMode,
ExecutionParameters,
)
from qibolab.result import collect


def _split(data, npulses, iq=False):
def _collect(i, q, npulses):
"""Collect I and Q components of signal.

I and Q should be the the last dimension of the returned array,
except when multiple results are acquired to the same stream in the
instrument, when they should be second to last.
"""
signal = np.stack([i, q])
return np.moveaxis(signal, 0, -1 - int(npulses > 1))
alecandido marked this conversation as resolved.
Show resolved Hide resolved


def _split(data, npulses):
"""Split results of different readout pulses to list.

These results were acquired in the same acquisition stream in the
instrument.
"""
if npulses == 1:
return [data]
if iq:
return list(np.moveaxis(data, -2, 0))
return list(np.moveaxis(data, -1, 0))


Expand Down Expand Up @@ -111,8 +119,8 @@ def fetch(self, handles):
qres = handles.get(f"{self.name}_Q").fetch_all()
# convert raw ADC signal to volts
u = unit()
signal = collect(u.raw2volts(ires), u.raw2volts(qres))
return _split(signal, self.npulses, iq=True)
signal = _collect(u.raw2volts(ires), u.raw2volts(qres), self.npulses)
return _split(signal, self.npulses)
alecandido marked this conversation as resolved.
Show resolved Hide resolved


@dataclass
Expand Down Expand Up @@ -162,8 +170,8 @@ def download(self, *dimensions):
def fetch(self, handles):
ires = handles.get(f"{self.name}_I").fetch_all()
qres = handles.get(f"{self.name}_Q").fetch_all()
signal = collect(ires, qres)
return _split(signal, self.npulses, iq=True)
signal = _collect(ires, qres, self.npulses)
return _split(signal, self.npulses)


@dataclass
Expand Down Expand Up @@ -223,7 +231,7 @@ def download(self, *dimensions):

def fetch(self, handles):
shots = handles.get(f"{self.name}_shots").fetch_all()
return _split(shots, self.npulses, iq=False)
return _split(shots, self.npulses)


ACQUISITION_TYPES = {
Expand Down
3 changes: 1 addition & 2 deletions src/qibolab/platform/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
from qibolab.components import Config
from qibolab.components.channels import Channel
from qibolab.execution_parameters import ExecutionParameters
from qibolab.identifier import ChannelId, QubitId, QubitPairId
from qibolab.identifier import ChannelId, QubitId, QubitPairId, Result
from qibolab.instruments.abstract import Controller, Instrument, InstrumentId
from qibolab.parameters import NativeGates, Parameters, Settings, update_configs
from qibolab.pulses import PulseId
from qibolab.qubits import Qubit
from qibolab.result import Result
from qibolab.sequence import PulseSequence
from qibolab.sweeper import ParallelSweepers
from qibolab.unrolling import Bounds, batch
Expand Down
91 changes: 0 additions & 91 deletions src/qibolab/result.py

This file was deleted.

34 changes: 0 additions & 34 deletions tests/test_result.py

This file was deleted.