-
Notifications
You must be signed in to change notification settings - Fork 131
Readout angle experiment #525
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3c53f5a
Readout angle experiment
yaelbh 4db9581
readout angle files
yaelbh e42b942
Merge branch 'main' into angle
yaelbh 8486d35
removed fix_class_docs
yaelbh 5a749db
bug fix in composite save
yaelbh af1e618
removed debug prints
yaelbh d88eceb
moved location of analysis file
yaelbh a2aa28b
removed the parallel test
yaelbh 79d5319
black
yaelbh 605cd48
lint
yaelbh b243f3d
black
yaelbh cbe890c
lint
yaelbh 25990b3
black
yaelbh 46c3f04
update init file
yaelbh e8d6473
docs
yaelbh efba207
release notes
yaelbh 3c1877a
Merge branch 'main' into angle
yaelbh 249dde4
Merge branch 'main' into angle
yaelbh d47326d
Merge branch 'main' into angle
yaelbh 4529137
addressing review comments
yaelbh cefd7c4
Merge branch 'main' into angle
yaelbh a89727b
Merge branch 'main' into angle
yaelbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
qiskit_experiments/library/characterization/analysis/readout_angle_analysis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # 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. | ||
| """ | ||
| Readout Angle Analysis class. | ||
| """ | ||
|
|
||
| import numpy as np | ||
|
|
||
| from qiskit_experiments.framework import BaseAnalysis, AnalysisResultData | ||
|
|
||
|
|
||
| class ReadoutAngleAnalysis(BaseAnalysis): | ||
| """ | ||
| A class to analyze readout angle experiments | ||
| """ | ||
|
|
||
| # pylint: disable=unused-argument | ||
| def _run_analysis(self, experiment_data, **kwargs): | ||
| angles = [] | ||
| for i in range(2): | ||
| center = complex(*experiment_data.data(i)["memory"][0]) | ||
| angles.append(np.angle(center)) | ||
|
|
||
| angle = (angles[0] + angles[1]) / 2 | ||
| if (np.abs(angles[0] - angles[1])) % (2 * np.pi) > np.pi: | ||
| angle += np.pi | ||
|
|
||
| analysis_results = [ | ||
| AnalysisResultData( | ||
| name="ReadoutAngle", | ||
| value=angle, | ||
| extra={"angle_ground": angles[0], "angle_excited": angles[1]}, | ||
| ) | ||
| ] | ||
|
|
||
| return analysis_results, [] |
101 changes: 101 additions & 0 deletions
101
qiskit_experiments/library/characterization/readout_angle.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # 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. | ||
| """ | ||
| Readout Angle Experiment class. | ||
| """ | ||
|
|
||
| from typing import List, Optional | ||
|
|
||
| from qiskit.circuit import QuantumCircuit | ||
| from qiskit.qobj.utils import MeasLevel | ||
| from qiskit.providers.backend import Backend | ||
|
|
||
| from qiskit_experiments.framework import BaseExperiment, Options | ||
| from qiskit_experiments.library.characterization.analysis.readout_angle_analysis import ( | ||
| ReadoutAngleAnalysis, | ||
| ) | ||
|
|
||
|
|
||
| class ReadoutAngle(BaseExperiment): | ||
| r""" | ||
| Readout angle experiment class | ||
|
|
||
| # section: overview | ||
|
|
||
| Design and analyze experiments for estimating readout angle of the qubit. | ||
| The readout angle is the average of two angles: the angle of the IQ | ||
| cluster center of the ground state, and the angle of the IQ cluster center | ||
| of the excited state. | ||
|
|
||
| Each experiment consists of the following steps: | ||
|
|
||
| 1. Circuits generation: two circuits, the first circuit measures the qubit | ||
| in the ground state, the second circuit sets the qubit in the excited state | ||
| and measures it. Measurements are in level 1 (kerneled). | ||
|
|
||
| 2. Backend execution: actually running the circuits on the device | ||
| (or a simulator that supports level 1 measurements). The backend returns | ||
| the cluster centers of the ground and excited states. | ||
|
|
||
| 3. Analysis of results: return the average of the angles of the two centers. | ||
|
|
||
| """ | ||
|
|
||
| __analysis_class__ = ReadoutAngleAnalysis | ||
|
|
||
| @classmethod | ||
| def _default_run_options(cls) -> Options: | ||
| """Default run options.""" | ||
| options = super()._default_run_options() | ||
|
|
||
| options.meas_level = MeasLevel.KERNELED | ||
| options.meas_return = "avg" | ||
|
|
||
| return options | ||
|
|
||
| def __init__( | ||
| self, | ||
| qubit: int, | ||
| backend: Optional[Backend] = None, | ||
| ): | ||
| """ | ||
| Initialize the readout angle experiment class | ||
|
|
||
| Args: | ||
| qubit: the qubit whose readout angle is to be estimated | ||
| backend: Optional, the backend to run the experiment on. | ||
| """ | ||
| # Initialize base experiment | ||
| super().__init__([qubit], backend=backend) | ||
|
|
||
| def circuits(self) -> List[QuantumCircuit]: | ||
| """ | ||
| Return a list of experiment circuits | ||
|
|
||
| Returns: | ||
| The experiment circuits | ||
| """ | ||
| circ0 = QuantumCircuit(1, 1) | ||
| circ0.measure(0, 0) | ||
|
|
||
| circ1 = QuantumCircuit(1, 1) | ||
| circ1.x(0) | ||
| circ1.measure(0, 0) | ||
|
|
||
| for i, circ in enumerate([circ0, circ1]): | ||
| circ.metadata = { | ||
| "experiment_type": self._type, | ||
| "qubit": self.physical_qubits[0], | ||
| "xval": i, | ||
| } | ||
|
|
||
| return [circ0, circ1] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| features: | ||
| - | | ||
| A new readout angle experiment. The experiment computes the average of the angles of the IQ clusters of the ground and excited states. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # 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 readout angle experiment | ||
| """ | ||
|
|
||
| import numpy as np | ||
|
|
||
| from qiskit.test import QiskitTestCase | ||
| from qiskit_experiments.library import ReadoutAngle | ||
| from qiskit_experiments.test.mock_iq_backend import MockIQBackend | ||
|
|
||
|
|
||
| class ReadoutAngleBackend(MockIQBackend): | ||
| """ | ||
| Mock IQ backend tailored to the readout angle test | ||
| """ | ||
|
|
||
| def _compute_probability(self, circuit): | ||
| return 1 - circuit.metadata["xval"] | ||
|
|
||
|
|
||
| class TestReadoutAngle(QiskitTestCase): | ||
| """ | ||
| Test the readout angle experiment | ||
| """ | ||
|
|
||
| def test_readout_angle_end2end(self): | ||
| """ | ||
| Test readout angle experiment using a simulator. | ||
| """ | ||
| backend = ReadoutAngleBackend(iq_cluster_centers=(5.0, 5.0, -3.0, 3.0)) | ||
| exp = ReadoutAngle(0) | ||
| expdata = exp.run(backend, shots=100000).block_for_results() | ||
| res = expdata.analysis_results(0) | ||
| self.assertAlmostEqual(res.value % (2 * np.pi), np.pi / 2, places=2) | ||
|
|
||
| backend = ReadoutAngleBackend(iq_cluster_centers=(5.0, 5.0, 0, -3.0)) | ||
| exp = ReadoutAngle(0) | ||
| expdata = exp.run(backend, shots=100000).block_for_results() | ||
| res = expdata.analysis_results(0) | ||
| self.assertAlmostEqual(res.value % (2 * np.pi), 15 * np.pi / 8, places=2) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.