Skip to content

Commit

Permalink
Merge pull request #559 from qiboteam/refactoring_action_parameters
Browse files Browse the repository at this point in the history
Refactoring action parameters
  • Loading branch information
GabrielePalazzo authored Oct 17, 2023
2 parents 0ee1b4e + 00b3c70 commit fdc62be
Show file tree
Hide file tree
Showing 33 changed files with 48 additions and 140 deletions.
17 changes: 16 additions & 1 deletion src/qibocal/auto/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def wrapper(*args, **kwds):
return wrapper


DEFAULT_PARENT_PARAMETERS = {
"nshots": None,
"relaxation_time": None,
}
"""Default values of the parameters of `Parameters`"""


class Parameters:
"""Generic action parameters.
Expand All @@ -70,14 +77,22 @@ def load(cls, parameters):
"""Load parameters from runcard.
Possibly looking into previous steps outputs.
Parameters defined in Parameters class are removed from `parameters`
before `cls` is created.
Then `nshots` and `relaxation_time` are assigned to cls.
.. todo::
move the implementation to History, since it is required to resolve
the linked outputs
"""
return cls(**parameters)
for parameter, value in DEFAULT_PARENT_PARAMETERS.items():
DEFAULT_PARENT_PARAMETERS[parameter] = parameters.pop(parameter, value)
instantiated_class = cls(**parameters)
for parameter, value in DEFAULT_PARENT_PARAMETERS.items():
setattr(instantiated_class, parameter, value)
return instantiated_class


class Data:
Expand Down
5 changes: 0 additions & 5 deletions src/qibocal/protocols/characterization/allxy/allxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -18,10 +17,6 @@ class AllXYParameters(Parameters):

beta_param: float = None
"""Beta parameter for drag pulse."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -24,10 +23,6 @@ class AllXYDragParameters(Parameters):
"""Final beta parameter for Drag pulse."""
beta_step: float
"""Step beta parameter for Drag pulse."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -29,10 +28,6 @@ class DragPulseTuningParameters(allxy_drag_pulse_tuning.AllXYDragParameters):
"""DRAG pulse beta end sweep parameter."""
beta_step: float
"""DRAG pulse beta sweep step parameter."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
4 changes: 0 additions & 4 deletions src/qibocal/protocols/characterization/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
class SingleShotClassificationParameters(Parameters):
"""SingleShotClassification runcard inputs."""

nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""
classifiers_list: Optional[list[str]] = field(default_factory=lambda: ["qubit_fit"])
"""List of models to classify the qubit states"""
savedir: Optional[str] = " "
Expand Down
5 changes: 0 additions & 5 deletions src/qibocal/protocols/characterization/coherence/spin_echo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass
from typing import Optional

import numpy as np
import plotly.graph_objects as go
Expand All @@ -26,10 +25,6 @@ class SpinEchoParameters(Parameters):
"""Final delay between pulses [ns]."""
delay_between_pulses_step: int
"""Step delay between pulses (ns)."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
5 changes: 0 additions & 5 deletions src/qibocal/protocols/characterization/coherence/t1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -27,10 +26,6 @@ class T1Parameters(Parameters):
"""Final delay before readout (ns)."""
delay_before_readout_step: int
"""Step delay before readout (ns)."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
5 changes: 0 additions & 5 deletions src/qibocal/protocols/characterization/coherence/t2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass
from typing import Optional

import numpy as np
import plotly.graph_objects as go
Expand All @@ -26,10 +25,6 @@ class T2Parameters(Parameters):
"""Final delay between RX(pi/2) pulses in ns."""
delay_between_pulses_step: int
"""Step delay between RX(pi/2) pulses in ns."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
5 changes: 0 additions & 5 deletions src/qibocal/protocols/characterization/coherence/zeno.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -22,10 +21,6 @@ class ZenoParameters(Parameters):

readouts: int
"Number of readout pulses"
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


ZenoType = np.dtype([("msr", np.float64), ("phase", np.float64)])
Expand Down
5 changes: 0 additions & 5 deletions src/qibocal/protocols/characterization/dispersive_shift.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import asdict, dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -32,10 +31,6 @@ class DispersiveShiftParameters(Parameters):
"""Width [Hz] for frequency sweep relative to the readout frequency (Hz)."""
freq_step: int
"""Frequency step for sweep (Hz)."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -21,11 +20,6 @@
class FastResetParameters(Parameters):
"""FastReset runcard inputs."""

nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
class FastResetResults(Results):
Expand Down
5 changes: 0 additions & 5 deletions src/qibocal/protocols/characterization/flipping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -27,10 +26,6 @@ class FlippingParameters(Parameters):
"""Maximum number of flips ([RX(pi) - RX(pi)] sequences). """
nflips_step: int
"""Flip step."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class QubitFluxParameters(Parameters):
If given flux will be swept on the given qubits in a sequential fashion (n qubits will result to n different executions).
Multiple qubits may be measured in each execution as specified by the ``qubits`` option in the runcard.
"""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""
transition: Optional[str] = "01"
"""Flux spectroscopy transition type ("01" or "02"). Default value is 01"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ class ResonatorFluxParameters(Parameters):
If given flux will be swept on the given qubits in a sequential fashion (n qubits will result to n different executions).
Multiple qubits may be measured in each execution as specified by the ``qubits`` option in the runcard.
"""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
4 changes: 0 additions & 4 deletions src/qibocal/protocols/characterization/qubit_spectroscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class QubitSpectroscopyParameters(Parameters):
"""Drive pulse duration [ns]. Same for all qubits."""
drive_amplitude: Optional[float] = None
"""Drive pulse amplitude (optional). Same for all qubits."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
4 changes: 0 additions & 4 deletions src/qibocal/protocols/characterization/rabi/amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class RabiAmplitudeParameters(Parameters):
"""Step amplitude multiplicative factor."""
pulse_length: Optional[float]
"""RX pulse duration (ns)."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
4 changes: 0 additions & 4 deletions src/qibocal/protocols/characterization/rabi/length.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class RabiLengthParameters(Parameters):
"""Step pi pulse duration (ns)."""
pulse_amplitude: Optional[float] = None
"""Pi pulse amplitude. Same for all qubits."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
4 changes: 0 additions & 4 deletions src/qibocal/protocols/characterization/ramsey.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class RamseyParameters(Parameters):
n_osc: Optional[int] = 0
"""Number of oscillations to induce detuning (optional).
If 0 standard Ramsey experiment is performed."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class StandardRBParameters(Parameters):
"""A list of depths/sequence lengths. If a dictionary is given the list will be build."""
niter: int
"""Sets how many iterations over the same depth value."""
nshots: int
"""For each sequence how many shots for statistics should be performed."""
uncertainties: Union[str, float] = 95
"""Method of computing the error bars of the signal and uncertainties of the fit. If ``None``,
does not compute them. If ``"std"``, computes the standard deviation. If ``float`` or ``int``
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -17,11 +16,6 @@
class ReadoutCharacterizationParameters(Parameters):
"""ReadoutCharacterization runcard inputs."""

nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
class ReadoutCharacterizationResults(Results):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass, field
from os import error
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -26,10 +25,6 @@ class ResonatorAmplitudeParameters(Parameters):
"""Amplitude start."""
amplitude_stop: float = 1.0
"""Amplitude stop value"""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""
error_threshold: float = 0.003
"""Probability error threshold to stop the best amplitude search"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -25,10 +24,6 @@ class ResonatorFrequencyParameters(Parameters):
"""Width [Hz] for frequency sweep relative to the readout frequency (Hz)."""
freq_step: int
"""Frequency step for sweep (Hz)."""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -22,10 +21,6 @@ class TwpaFrequencyParameters(Parameters):
"""Relative frequency width [Hz]"""
frequency_step: float
"""Frequency step [Hz]"""
nshots: Optional[int] = None
"""Number of shots."""
relaxation_time: Optional[int] = None
"""Relaxation time (ns)."""


@dataclass
Expand Down Expand Up @@ -98,7 +93,9 @@ def _acquisition(
)

classification_data = classification._acquisition(
classification.SingleShotClassificationParameters(nshots=params.nshots),
classification.SingleShotClassificationParameters.load(
{"nshots": params.nshots}
),
platform,
qubits,
)
Expand Down
Loading

0 comments on commit fdc62be

Please sign in to comment.