Skip to content
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
352 changes: 150 additions & 202 deletions docs/tutorials/calibrating_armonk.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _default_options(cls):
default_options.angle_per_gate = None
default_options.phase_offset = 0.0
default_options.max_good_angle_error = np.pi / 2
default_options.amp = 1.0

return default_options

Expand All @@ -145,7 +146,7 @@ def _generate_fit_guesses(

if "amp" in user_opt.p0:
user_opt.p0.set_if_empty(amp=max_y - min_y)
user_opt.bounds.set_if_empty(amp=(-2 * max_abs_y, 2 * max_abs_y))
user_opt.bounds.set_if_empty(amp=(0, 2 * max_abs_y))

# Base the initial guess on the intended angle_per_gate and phase offset.
apg = self._get_option("angle_per_gate")
Expand Down
2 changes: 2 additions & 0 deletions qiskit_experiments/library/calibration/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@

from .drag_analysis import DragCalAnalysis
from .fine_half_angle_analysis import FineHalfAngleAnalysis
from .fine_x_amplitude_analysis import FineXAmplitudeAnalysis
from .fine_amplitude_analysis import FineAmplitudeAnalysis
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ class FineAmplitudeAnalysis(ErrorAmplificationAnalysis):

# The intended angle per gat of the gate being calibrated, e.g. pi for a pi-pulse.

# TODO remove amp from fixed parameter.
__fixed_parameters__ = ["angle_per_gate", "phase_offset", "amp"]
__fixed_parameters__ = ["angle_per_gate", "phase_offset"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Fine Amplitude calibration analysis."""

from qiskit_experiments.curve_analysis import ErrorAmplificationAnalysis


class FineXAmplitudeAnalysis(ErrorAmplificationAnalysis):
r"""An analysis class for fine amplitude calibrations to define the fixed parameters.

# section: note

The following parameters are fixed.

* :math:`{\rm apg}` The angle per gate is set by the user, for example pi for a pi-pulse.
* :math:`{\rm phase\_offset}` The phase offset in the cosine oscillation, for example,
:math:`\pi/2` if a square-root of X gate is added before the repeated gates.
* :math:`{\rm amp}` The amplitude of the oscillation.
"""

# The intended angle per gat of the gate being calibrated, e.g. pi for a pi-pulse.

# TODO remove amp from fixed parameter.
__fixed_parameters__ = ["angle_per_gate", "phase_offset", "amp"]
12 changes: 10 additions & 2 deletions qiskit_experiments/library/calibration/fine_amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from qiskit_experiments.library.characterization import FineAmplitude
from qiskit_experiments.framework import ExperimentData, Options, fix_class_docs
from qiskit_experiments.calibration_management.update_library import BaseUpdater
from qiskit_experiments.library.calibration.analysis import FineXAmplitudeAnalysis


@fix_class_docs
Expand Down Expand Up @@ -141,6 +142,10 @@ def update_calibrations(self, experiment_data: ExperimentData):
target_angle = data[0]["metadata"]["target_angle"]
prev_amp = data[0]["metadata"]["cal_param_value"]

# Protect against cases where the complex amplitude was converted to a list.
if isinstance(prev_amp, list) and len(prev_amp) == 2:
prev_amp = prev_amp[0] + 1.0j * prev_amp[1]

d_theta = BaseUpdater.get_value(experiment_data, "d_theta", result_index)

BaseUpdater.add_parameter_value(
Expand All @@ -157,6 +162,8 @@ def update_calibrations(self, experiment_data: ExperimentData):
class FineXAmplitudeCal(FineAmplitudeCal):
"""A calibration experiment to calibrate the amplitude of the X schedule."""

__analysis_class__ = FineXAmplitudeAnalysis

@classmethod
def _default_experiment_options(cls) -> Options:
r"""Default values for the fine amplitude experiment.
Expand Down Expand Up @@ -194,6 +201,7 @@ def _default_analysis_options(cls) -> Options:
options = super()._default_analysis_options()
options.angle_per_gate = np.pi
options.phase_offset = np.pi / 2
options.amp = 1

return options

Expand Down Expand Up @@ -221,7 +229,7 @@ def _default_experiment_options(cls) -> Options:
options = super()._default_experiment_options()
options.add_sx = False
options.add_xp_circuit = False
options.repetitions = [1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25]
options.repetitions = [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25]
options.target_angle = np.pi / 2
return options

Expand All @@ -244,6 +252,6 @@ def _default_analysis_options(cls) -> Options:
"""Default analysis options."""
options = super()._default_analysis_options()
options.angle_per_gate = np.pi / 2
options.phase_offset = 0
options.phase_offset = np.pi

return options
16 changes: 6 additions & 10 deletions qiskit_experiments/library/characterization/fine_amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
from qiskit.circuit.library import XGate, SXGate
from qiskit.providers.backend import Backend
from qiskit_experiments.framework import BaseExperiment, Options, fix_class_docs
from qiskit_experiments.library.calibration.analysis.fine_amplitude_analysis import (
from qiskit_experiments.library.calibration.analysis import (
FineAmplitudeAnalysis,
FineXAmplitudeAnalysis,
)
from qiskit_experiments.exceptions import CalibrationError

Expand Down Expand Up @@ -118,14 +119,6 @@ def _default_experiment_options(cls) -> Options:

return options

@classmethod
def _default_analysis_options(cls) -> Options:
"""Default analysis options."""
options = super()._default_analysis_options()
options.amp = 1.0

return options

def __init__(self, qubit: int, gate: Gate, backend: Optional[Backend] = None):
"""Setup a fine amplitude experiment on the given qubit.

Expand Down Expand Up @@ -221,6 +214,8 @@ class FineXAmplitude(FineAmplitude):
the appropriate values for the default options.
"""

__analysis_class__ = FineXAmplitudeAnalysis

def __init__(self, qubit: int, backend: Optional[Backend] = None):
"""Initialize the experiment."""
super().__init__(qubit, XGate(), backend=backend)
Expand Down Expand Up @@ -250,6 +245,7 @@ def _default_analysis_options(cls) -> Options:
options = super()._default_analysis_options()
options.angle_per_gate = np.pi
options.phase_offset = np.pi / 2
options.amp = 1.0

return options

Expand Down Expand Up @@ -287,7 +283,7 @@ def _default_experiment_options(cls) -> Options:
options.gate = SXGate()
options.add_sx = False
options.add_xp_circuit = False
options.repetitions = [1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25]
options.repetitions = [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25]

return options

Expand Down
4 changes: 2 additions & 2 deletions test/calibration/experiments/test_fine_amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_x90p(self):

amp_cal = FineSXAmplitude(0)

expected = [1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25]
expected = [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25]
for idx, circ in enumerate(amp_cal.circuits()):
self.assertEqual(circ.count_ops().get("sx", 0), expected[idx])

Expand All @@ -141,7 +141,7 @@ def test_fine_sx_amp(self):
self.assertFalse(exp.experiment_options.add_sx)
self.assertFalse(exp.experiment_options.add_xp_circuit)

expected = [1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25]
expected = [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25]
self.assertEqual(exp.experiment_options.repetitions, expected)
self.assertEqual(exp.analysis_options.angle_per_gate, np.pi / 2)
self.assertEqual(exp.analysis_options.phase_offset, np.pi)
Expand Down