Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ef5dc84
* First draft of half angle calibration.
eggerdj Sep 3, 2021
348235c
* inits and docstring.
eggerdj Sep 3, 2021
0be733d
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into half…
eggerdj Sep 30, 2021
6f6cfee
* Added transpile options, reference and more doc.
eggerdj Sep 30, 2021
c8c5371
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into half…
eggerdj Oct 6, 2021
a08b0e7
* First draft of half angle.
eggerdj Oct 6, 2021
d3c600d
* Docs and test
eggerdj Oct 9, 2021
1c78d0a
* removed transpile options (for a future PR).
eggerdj Oct 12, 2021
493ec5a
Merge branch 'main' into half_angle
eggerdj Oct 12, 2021
ab469e7
* fix docs.
eggerdj Oct 12, 2021
d2579e9
* Docstring
eggerdj Oct 14, 2021
79239b4
Update qiskit_experiments/library/characterization/half_angle.py
eggerdj Oct 14, 2021
b185ed6
* Added transpiler options for inst_map
eggerdj Oct 14, 2021
6dffacb
Merge branch 'half_angle' of github.com:eggerdj/qiskit-experiments in…
eggerdj Oct 14, 2021
d63a46e
Merge branch 'main' into half_angle
eggerdj Oct 14, 2021
c6cf2ac
* ParameterRepr
eggerdj Oct 14, 2021
c840ddf
Merge branch 'half_angle' of github.com:eggerdj/qiskit-experiments in…
eggerdj Oct 14, 2021
79bb283
Merge branch 'main' into half_angle
eggerdj Oct 24, 2021
0f38958
* Calibration class
eggerdj Oct 24, 2021
6a894bd
Merge branch 'main' into half_angle
eggerdj Oct 27, 2021
b5c8d36
* Improved doc.
eggerdj Oct 27, 2021
920baf8
* Fixed update rule.
eggerdj Oct 28, 2021
9d3722d
* Update for half angle cal.
eggerdj Oct 28, 2021
5f9b775
* Bug fixes.
eggerdj Oct 28, 2021
1572085
* Black
eggerdj Oct 28, 2021
38c7b04
* Test align to bug fix.
eggerdj Oct 28, 2021
5f654ee
* Lint.
eggerdj Oct 28, 2021
d3a1724
* Added comment on options.
eggerdj Oct 28, 2021
843ec67
Update qiskit_experiments/library/characterization/half_angle.py
eggerdj Oct 28, 2021
c0a7af2
Update qiskit_experiments/library/characterization/half_angle.py
eggerdj Oct 28, 2021
a8bd795
Update qiskit_experiments/library/calibration/half_angle_cal.py
eggerdj Oct 28, 2021
d6c10b0
Merge branch 'main' into half_angle
eggerdj Oct 29, 2021
086d6c1
* Changed init arg order.
eggerdj Oct 29, 2021
009534e
* refactor update rule.
eggerdj Oct 29, 2021
bf3cd3e
* Black
eggerdj Oct 29, 2021
dd12058
Update qiskit_experiments/library/calibration/analysis/fine_half_angl…
eggerdj Nov 1, 2021
ff24a78
Update qiskit_experiments/library/calibration/half_angle_cal.py
eggerdj Nov 1, 2021
4ab1352
Update qiskit_experiments/library/characterization/half_angle.py
eggerdj Nov 1, 2021
dedf7a8
Update qiskit_experiments/library/characterization/half_angle.py
eggerdj Nov 1, 2021
af71a42
Update docs/tutorials/fine_calibrations.ipynb
eggerdj Nov 1, 2021
756251a
* Doc.
eggerdj Nov 1, 2021
7f72917
Merge branch 'half_angle' of github.com:eggerdj/qiskit-experiments in…
eggerdj Nov 1, 2021
fcbe7ea
* Decorators, and decorators.
eggerdj Nov 1, 2021
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
2 changes: 2 additions & 0 deletions qiskit_experiments/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
~characterization.EFSpectroscopy
~characterization.CrossResonanceHamiltonian
~characterization.EchoedCrossResonanceHamiltonian
~characterization.HalfAngle

.. _calibration:

Expand Down Expand Up @@ -109,6 +110,7 @@ class instance to manage parameters and pulse schedules.
EFSpectroscopy,
CrossResonanceHamiltonian,
EchoedCrossResonanceHamiltonian,
HalfAngle,
)
from .randomized_benchmarking import StandardRB, InterleavedRB
from .tomography import StateTomography, ProcessTomography
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Calibration Analysis Classes"""

from .drag_analysis import DragCalAnalysis
from .fine_half_angle_analysis import FineHalfAngleAnalysis
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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 half angle calibration analysis."""

from qiskit_experiments.curve_analysis import ErrorAmplificationAnalysis


class FineHalfAngleAnalysis(ErrorAmplificationAnalysis):
r"""Analysis class for the HalfAngle experiment to define the fixed parameters.

# section: note

The following parameters are fixed.
Comment thread
eggerdj marked this conversation as resolved.
Outdated

* :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.
* :math:`{\rm amp}` The amplitude of the oscillation.
"""

__fixed_parameters__ = ["angle_per_gate", "phase_offset", "amp"]
2 changes: 2 additions & 0 deletions qiskit_experiments/library/characterization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
QubitSpectroscopy
CrossResonanceHamiltonian
EchoedCrossResonanceHamiltonian
HalfAngle


Analysis
Expand All @@ -51,3 +52,4 @@
from .t2ramsey_analysis import T2RamseyAnalysis
from .cr_hamiltonian import CrossResonanceHamiltonian, EchoedCrossResonanceHamiltonian
from .cr_hamiltonian_analysis import CrossResonanceHamiltonianAnalysis
from .half_angle import HalfAngle
123 changes: 123 additions & 0 deletions qiskit_experiments/library/characterization/half_angle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# 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.

"""Half angle calibration."""

from typing import Optional
import numpy as np

from qiskit import QuantumCircuit
from qiskit.providers import Backend

from qiskit_experiments.framework import BaseExperiment, Options
from qiskit_experiments.library.calibration.analysis import FineHalfAngleAnalysis


Comment thread
eggerdj marked this conversation as resolved.
class HalfAngle(BaseExperiment):
r"""A calibration experiment class to perform half angle calibration.

# section: overview

This experiment runs circuits that repeat blocks of :code:`sx - sx - y`
circuits inserted in a Ramsey type experiment, i.e. the full gate sequence is thus
:code:`Ry(π/2) - [sx - sx - y] ^ n - sx` where :code:`n` is varied, see [1]. This
gate sequence is designed to amplify X-Y axis errors. Such errors can occur due to
phase errors.
Comment thread
eggerdj marked this conversation as resolved.
Outdated

.. parsed-literal::

┌─────────┐┌────┐┌────┐┌───┐ ┌────┐┌────┐┌───┐┌────┐ ░ ┌─┐
q_0: ┤ Ry(π/2) ├┤ sx ├┤ sx ├┤ y ├...┤ sx ├┤ sx ├┤ y ├┤ sx ├─░─┤M├
└─────────┘└────┘└────┘└───┘ └────┘└────┘└───┘└────┘ ░ └╥┘
meas: 1/════════════════════════════...═══════════════════════════╩═
0

# section: reference
.. ref_arxiv:: 1 1504.06597
"""

__analysis_class__ = FineHalfAngleAnalysis

@classmethod
def _default_experiment_options(cls) -> Options:
r"""Default values for the fine amplitude experiment.
Comment thread
eggerdj marked this conversation as resolved.
Outdated

Experiment Options:
repetitions (List[int]): A list of the number of times that the gate
sequence :code:`[sx sx y]` is repeated.
"""
options = super()._default_experiment_options()
Comment thread
nkanazawa1989 marked this conversation as resolved.
options.repetitions = list(range(15))

return options

@classmethod
def _default_analysis_options(cls) -> Options:
r"""Default analysis options.

If the rotation error is very small the fit may chose a d_theta close to
:math:`\pm\pi`. To prevent this we impose bounds on d_theta.
"""
options = super()._default_analysis_options()
options.normalization = True
options.angle_per_gate = np.pi
Comment thread
eggerdj marked this conversation as resolved.
options.phase_offset = -np.pi / 2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are okay with -pi/2. I believe we might have some freedom between -pi/2 or +pi/2: the choice of + or - will change how we handle the rest of the update rule which needs to be consistent. When I ran it yesterday it gave the correct result, see the NB in the PR. In this NB a sx with an angle of 0.0 needed the update A -> A * exp(-1.0j * dhac / 2) giving an angle of -0.242 which is more or less the value of 0.250 reported by the backend.

options.amp = 1.0
options.bounds = {"d_theta": (-np.pi / 2, np.pi / 2)}
Comment thread
eggerdj marked this conversation as resolved.
Outdated

return options

def __init__(self, qubit: int):
"""Setup a fine amplitude experiment on the given qubit.
Comment thread
eggerdj marked this conversation as resolved.
Outdated

Args:
qubit: The qubit on which to run the fine amplitude calibration experiment.
"""
super().__init__([qubit])

@staticmethod
def _pre_circuit() -> QuantumCircuit:
"""Return the preparation circuit for the experiment."""
return QuantumCircuit(1)

def circuits(self, backend: Optional[Backend] = None):
"""Create the circuits for the half angle calibration experiment."""

circuits = []

for repetition in self.experiment_options.repetitions:
circuit = self._pre_circuit()

# First ry gate
circuit.rz(np.pi / 2, 0)
circuit.sx(0)
circuit.rz(-np.pi / 2, 0)
Comment thread
eggerdj marked this conversation as resolved.

# Error amplifying sequence
for _ in range(repetition):
circuit.sx(0)
circuit.sx(0)
circuit.y(0)
Comment thread
eggerdj marked this conversation as resolved.

circuit.sx(0)
circuit.measure_all()

circuit.metadata = {
"experiment_type": self._type,
"qubits": self.physical_qubits,
"xval": repetition,
"unit": "repetition number",
}

circuits.append(circuit)

return circuits
52 changes: 52 additions & 0 deletions test/test_half_angle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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.

"""Test the half angle experiment."""

import numpy as np

from qiskit import QuantumCircuit
from qiskit.test import QiskitTestCase

from qiskit_experiments.test.mock_iq_backend import MockIQBackend
from qiskit_experiments.library import HalfAngle


class HalfAngleTestBackend(MockIQBackend):
"""A simple and primitive backend, to be run by the half angle tests."""

def __init__(self, error: float):
"""Initialize the class."""
super().__init__()
self._error = error

def _compute_probability(self, circuit: QuantumCircuit) -> float:
"""Returns the probability of measuring the excited state."""

n_gates = circuit.metadata["xval"]

return 0.5 * np.sin((-1) ** n_gates * n_gates * self._error) + 0.5


class TestHalfAngle(QiskitTestCase):
Comment thread
eggerdj marked this conversation as resolved.
"""Class to test the half angle experiment."""

def test_end_to_end(self):
"""Test a full experiment end to end."""

tol = 0.005
for error in [-0.05, -0.02, 0.02, 0.05]:
hac = HalfAngle(0)
exp_data = hac.run(HalfAngleTestBackend(error)).block_for_results()
d_theta = exp_data.analysis_results(1).value.value

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directly specifying the entry name is safer. index=0 for parameters can be removed when API for artifacts become available. Then this will become 0.

@eggerdj eggerdj Nov 1, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion moved to issue #478


self.assertTrue(abs(d_theta - error) < tol)