Skip to content
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
19b57ea
implement HEAT ZY experiment
Oct 25, 2021
0c4844e
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into expe…
Oct 26, 2021
128da19
code cleanup
Oct 26, 2021
64dc82b
update method name
Oct 26, 2021
de7b49e
minor update doc
Oct 26, 2021
2e99cb7
Update qiskit_experiments/library/characterization/heat.py
nkanazawa1989 Oct 26, 2021
1c82d77
fix class name
Oct 26, 2021
832e708
class name to be more specific
Oct 27, 2021
6ef4648
reorganization
Oct 27, 2021
b59ae69
remove import
Oct 27, 2021
e93aca1
Update qiskit_experiments/library/heat/base_experiment.py
nkanazawa1989 Nov 1, 2021
bd4dd7b
Update qiskit_experiments/library/heat/base_experiment.py
nkanazawa1989 Nov 1, 2021
1797fc5
comments
Nov 1, 2021
508c4ca
Merge branch 'experiment/heat' of github.com:nkanazawa1989/qiskit-exp…
Nov 1, 2021
cb4d564
simplify the class structure
Nov 1, 2021
4aa3355
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into expe…
Nov 1, 2021
c2269be
conform to #462
Nov 1, 2021
2468670
add comment
Nov 1, 2021
1efd760
set default opt level=0
Nov 1, 2021
b69b166
update opt level to 1
Nov 3, 2021
facae9c
fix gate name
Nov 5, 2021
149b598
separate analysis
Nov 5, 2021
ba5f37c
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into expe…
Nov 5, 2021
3dd3763
conform to new composite analysis
Nov 5, 2021
e6787e6
remove dedicated analysis
Nov 5, 2021
1e2655a
cleanup
Nov 5, 2021
bfdf62d
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into expe…
nkanazawa1989 Dec 10, 2021
5eb5086
remove decorator
nkanazawa1989 Dec 10, 2021
c6a0791
use stateful analysis class
nkanazawa1989 Dec 10, 2021
cfe5810
use callback
nkanazawa1989 Dec 13, 2021
0da7655
cleanup curve analysis (#574)
Dec 10, 2021
577eeb1
Release note for calibrations (#575)
eggerdj Dec 10, 2021
5c3b8e6
Calibration tutorials (#577)
eggerdj Dec 13, 2021
260fcb1
Update fit_result_plotters.py (#578)
Dec 14, 2021
60f6013
Small bugfix in interleaved RB data processing (#580)
gadial Dec 14, 2021
98c020c
renamed file remsey_xy_analysis.py to ramsey_xy_analysis.py (#581)
yaelbh Dec 14, 2021
a4042b3
Update resultsdb tutorial (#582)
coruscating Dec 14, 2021
72eb4b6
Update T2, T2 tutorials to use Aer 0.10 noise model (#579)
chriseclectic Dec 14, 2021
798007b
Edit and condense release notes for 0.2 release (#576)
chriseclectic Dec 14, 2021
f7d7e5f
Bump package version (#597)
chriseclectic Jan 7, 2022
f6ee573
Copied changes to readoutAngle from qiskit-monitoring to qiskit-exper…
merav-aharoni Jan 10, 2022
14ed531
Fix bug with nested composite analysis (#596)
chriseclectic Jan 12, 2022
da129e6
Mitigation experiment (#415)
gadial Jan 13, 2022
29eaf03
Removed sub-experiment info from composite analysis result (#603)
yaelbh Jan 13, 2022
c8b2486
Deleted some lines that are not needed anymore (#594)
yaelbh Jan 17, 2022
735b58b
class reorganization
nkanazawa1989 Jan 19, 2022
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
1 change: 1 addition & 0 deletions qiskit_experiments/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class instance to manage parameters and pulse schedules.
)
from .randomized_benchmarking import StandardRB, InterleavedRB
from .tomography import StateTomography, ProcessTomography
from .heat import ZXHeatZError, ZXHeatYError
from .quantum_volume import QuantumVolume

# Experiment Sub-modules
Expand Down
16 changes: 16 additions & 0 deletions qiskit_experiments/library/heat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.
"""
Hamiltonian Error Amplifying Tomography Experiments.
"""

from .zx_heat import ZXHeatYError, ZXHeatZError
126 changes: 126 additions & 0 deletions qiskit_experiments/library/heat/base_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# 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.
"""
Analysis for HEAT experiments.
"""

from abc import ABC

import numpy as np

from qiskit_experiments.curve_analysis import ErrorAmplificationAnalysis
from qiskit_experiments.exceptions import AnalysisError
from qiskit_experiments.framework import (
CompositeAnalysis,
CompositeExperimentData,
AnalysisResultData,
Options,
FitVal,
)


class HeatAnalysis(ErrorAmplificationAnalysis):
"""An analysis class for HEAT experiment to define the fixed parameters."""

__fixed_parameters__ = ["angle_per_gate", "phase_offset", "amp"]

@classmethod
def _default_options(cls) -> Options:
"""Default analysis options."""
options = super()._default_options()
options.angle_per_gate = np.pi
options.phase_offset = np.pi / 2
options.amp = 1.0

return options


class CompositeHeatAnalysis(CompositeAnalysis, ABC):
r"""A composite error amplification analysis to get unitary error coefficients.

# section: fit_model

This analysis takes a set of `d_theta` parameters from two error amplification
analysis results. Each parameter is extracted from the HEAT experiment with
different control qubit states. Namely,

.. math::

A_{I\beta} = \frac{{d\theta_{\beta 0}} + d\theta_{\beta 1}}}{2}

A_{Z\beta} = \frac{{d\theta_{\beta 0}} - d\theta_{\beta 1}}}{2}

where, :math:`\beta \in [X, Y, Z]` is one of single qubit Pauli terms,
:math:`d\theta_{\beta k}` is `d_theta` parameter extracted from the HEAT experiment
with the control qubit state :math:`|k\rangle \in [|0\rangle, |1\rangle]`.

# section: see_also
qiskit_experiments.curve_analysis.standard_analysis.error_amplification_analysis.\
ErrorAmplificationAnalysis

"""
__fit_params__ = []
__out_params__ = []

def _run_analysis(self, experiment_data: CompositeExperimentData, **options):

# Validate setup
if len(self.__fit_params__) != 2:
raise AnalysisError(
f"{self.__class__.__name__} assumes two fit parameters extracted from "
"a set of experiments with different control qubit state input. "
f"{len(self.__fit_params__)} input parameter names are specified."
)

if len(self.__out_params__) != 2:
raise AnalysisError(
f"{self.__class__.__name__} assumes two output parameters computed with "
"a set of experiment results with different control qubit state input. "
f"{len(self.__out_params__)} output parameter names are specified."
)

# Create analysis data of nested experiment and discard redundant entry.
# Note that experiment_data is mutable.
super()._run_analysis(experiment_data, **options)

sub_analysis_results = [
experiment_data.component_experiment_data(i).analysis_results(pname)
for i, pname in enumerate(self.__fit_params__)
]

# Check data quality
is_good_quality = all(r.quality == "good" for r in sub_analysis_results)

# Compute unitary terms
ib = (sub_analysis_results[0].value.value + sub_analysis_results[1].value.value) / 2
zb = (sub_analysis_results[0].value.value - sub_analysis_results[1].value.value) / 2

# Compute new variance
sigma = np.sqrt(
sub_analysis_results[0].value.stderr ** 2 + sub_analysis_results[1].value.stderr ** 2
)

estimate_ib = AnalysisResultData(
name=self.__out_params__[0],
value=FitVal(value=ib, stderr=sigma, unit="rad"),
quality="good" if is_good_quality else "bad",
)

estimate_zb = AnalysisResultData(
name=self.__out_params__[1],
value=FitVal(value=zb, stderr=sigma, unit="rad"),
quality="good" if is_good_quality else "bad",
)

composite_analysis_results = [estimate_ib, estimate_zb]

return composite_analysis_results, None
194 changes: 194 additions & 0 deletions qiskit_experiments/library/heat/base_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# 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.
"""
Base Class for general Hamiltonian Error Amplifying Tomography experiments.
"""

from abc import ABC
from typing import List, Tuple, Optional

from qiskit import circuit, QuantumCircuit
from qiskit.providers import Backend

from qiskit_experiments.framework import BaseExperiment, BatchExperiment, Options, fix_class_docs
from .base_analysis import HeatAnalysis


@fix_class_docs
class HeatElement(BaseExperiment):
"""Base class of HEAT experiment elements.

This class implements a single error amplification sequence.

Subclasses must implement :py:meth:`_echo_circuit` to provide echo sequence that
selectively amplifies a specific Pauli component local to the target qubit.

"""

__analysis_class__ = HeatAnalysis

def __init__(
self,
qubits: Tuple[int, int],
prep_circ: QuantumCircuit,
echo_circ: QuantumCircuit,
meas_circ: QuantumCircuit,
backend: Optional[Backend] = None,
**kwargs
):
"""Create new HEAT sub experiment.

Args:
qubits: Index of control and target qubit, respectively.
prep_circ: A circuit to prepare qubit before the echo sequence.
echo_circ: A circuit to selectively amplify the specific error term.
meas_circ: A circuit to project target qubit onto the basis of interest.
backend: Optional, the backend to run the experiment on.

Keyword Args:
See :meth:`experiment_options` for details.
"""
super().__init__(qubits=qubits, backend=backend)
self.set_experiment_options(**kwargs)

# These are not user configurable options. Be frozen once assigned.
self._prep_circuit = prep_circ
self._echo_circuit = echo_circ
self._meas_circuit = meas_circ

@classmethod
def _default_experiment_options(cls) -> Options:
"""Default experiment options.

Experiment Options:
repetitions (Sequence[int]): A list of the number of echo repetitions.
cr_gate (Gate): A gate instance representing the ZX(pi/2).
"""
options = super()._default_experiment_options()
options.repetitions = list(range(21))
options.heat_gate = circuit.Gate("heat", num_qubits=2, params=[])

return options

@classmethod
def _default_transpile_options(cls) -> Options:
"""Default transpile options."""
options = super()._default_transpile_options()
options.basis_gates = ["sx", "x", "rz", "cr"]
options.optimization_level = 0

return options

def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
opt = self.experiment_options

circs = list()
for repetition in opt.repetitions:
circ = circuit.QuantumCircuit(2, 1)
circ.compose(self._prep_circuit, qubits=[0, 1], inplace=True)
circ.barrier()
for _ in range(repetition):
circ.append(self.experiment_options.heat_gate, [0, 1])
circ.compose(self._echo_circuit, qubits=[0, 1], inplace=True)
circ.barrier()
circ.compose(self._meas_circuit, qubits=[0, 1], inplace=True)
circ.measure(1, 0)

# add metadata
circ.metadata = {
"experiment_type": self.experiment_type,
"qubits": self.physical_qubits,
"xval": repetition,
}

circs.append(circ)

return circs


@fix_class_docs
class BaseCompositeHeat(BatchExperiment, ABC):
"""Base class of HEAT experiments.

This class implements a batch experiment consisting of multiple HEAT element experiments
to compute specific unitary error terms from extracted `d_theta` parameters.

Class Attributes:
- ``__heat_elements__``: A dictionary of fit parameter name and associated experiment
class.

"""

__heat_elements__ = {}

def __init__(
self,
heat_experiments: List[HeatElement],
backend: Optional[Backend] = None,
):
"""Create new HEAT experiment.

Args:
heat_experiments: A list of configured HEAT experiments.
backend: Optional, the backend to run the experiment on.
"""
super().__init__(experiments=heat_experiments, backend=backend)

@classmethod
def _default_experiment_options(cls) -> Options:
"""Default experiment options.

Experiment Options:
repetitions (Sequence[int]): A list of the number of echo repetitions.
cr_gate (Gate): A gate instance representing the ZX(pi/2).
"""
options = super()._default_experiment_options()
options.repetitions = list(range(21))
options.cr_gate = circuit.Gate("cr", num_qubits=2, params=[])

return options

def set_experiment_options(self, **fields):
"""Set the analysis options for :meth:`run` method.

Same experiment options are applied to all subset HEAT experiments.

Args:
fields: The fields to update the options
"""
for comp_exp in self.component_experiment():
comp_exp.set_experiment_options(**fields)

super().set_experiment_options(**fields)

@classmethod
def _default_transpile_options(cls) -> Options:
"""Default transpile options."""
options = super()._default_transpile_options()
options.basis_gates = ["sx", "x", "rz", "cr"]
options.optimization_level = 0

return options

def set_transpile_options(self, **fields):
"""Set the transpiler options for :meth:`run` method.

Same transpile options are applied to all subset HEAT experiments.

Args:
fields: The fields to update the options
"""
# TODO wait for #380 to apply individual transpile options to nested experiments
for comp_exp in self.component_experiment():
comp_exp.set_transpile_options(**fields)

super().set_transpile_options(**fields)
Loading