-
Notifications
You must be signed in to change notification settings - Fork 131
Restless Experiments #689
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
Restless Experiments #689
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
f2945b3
First draft of RestlessEnabledExperiment
catornow 9660509
Modified the draft
catornow b7edd2a
Moved restless_experiment to framework folder and modified it
catornow d460e70
Implemented is_restless check
catornow 3e8c5f3
Removed restless node tests for this PR
catornow 6ef6690
Small modification
catornow 7c9e1e8
Black
catornow 271ce98
Fixed Lint error
catornow bf4f981
Removed backend arg
catornow cfcd629
Aligned code with current main
catornow c8ab58e
Merge branch 'RestlessMixin' of github.com:catornow/qiskit-experiment…
catornow 0aac8bd
Modified code and added override_processor arg
catornow 8c688ce
Some docstring modifications
catornow 155657d
Added documentation
catornow b977083
If esp readout is enabled it is set to False
catornow 747e445
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into Rest…
catornow 41fb63f
Lint error
catornow cf15779
Small modifications
catornow 4a665a8
Update qiskit_experiments/framework/restless_experiment.py
catornow 2f06ff5
Update qiskit_experiments/framework/restless_experiment.py
catornow db4bcb8
Update qiskit_experiments/framework/restless_experiment.py
catornow 4ab4f4e
Update qiskit_experiments/framework/restless_experiment.py
catornow 3bfc2c4
Update qiskit_experiments/framework/restless_experiment.py
catornow acd51ad
Update qiskit_experiments/framework/restless_experiment.py
catornow a011453
Update qiskit_experiments/test/mock_iq_backend.py
catornow 19a544c
Black
catornow 545b644
Corrected mistake
catornow 927c6c2
Update qiskit_experiments/framework/restless_experiment.py
catornow 56c5494
Update qiskit_experiments/test/mock_iq_backend.py
catornow 5915e33
Small modification
catornow ec85768
Update qiskit_experiments/framework/restless_experiment.py
catornow 8b30550
Update qiskit_experiments/framework/restless_experiment.py
catornow f254817
Small modification
catornow f31cef7
Merge branch 'RestlessMixin' of github.com:catornow/qiskit-experiment…
catornow 72efed1
Modification of the doc string for esp readout
catornow 768ffb5
Added test to check restless run options
catornow 4342863
Merge branch 'main' into RestlessMixin
catornow 2e79e24
Lint error
catornow 5f424ad
Update qiskit_experiments/framework/restless_experiment.py
catornow 2b66f12
Update qiskit_experiments/framework/restless_experiment.py
catornow b096209
Update qiskit_experiments/framework/restless_experiment.py
catornow 0bf8e72
Update qiskit_experiments/library/characterization/fine_amplitude.py
catornow cef56f8
Update qiskit_experiments/library/characterization/fine_amplitude.py
catornow 5a03619
Implemented Daniel's suggestions
catornow a74f24b
Implemented Daniel's suggestions
catornow 4aafda5
Added a check that the repetition delay has to be positive or zero.
catornow dba1fc6
Adapted doc string
catornow 6a736da
Attempt solving lint error
catornow 567ce0f
Modified RestlessMixin to avoid no-member lint errors
catornow e3d1ab8
Update qiskit_experiments/framework/restless_mixin.py
catornow c78a723
Update qiskit_experiments/framework/restless_mixin.py
catornow 7ee9173
Update qiskit_experiments/framework/restless_mixin.py
catornow ba9909b
Update qiskit_experiments/test/mock_iq_backend.py
catornow 54b7d5f
Update qiskit_experiments/test/mock_iq_backend.py
catornow 55a8183
Modified restless mock backend
catornow a55d405
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into Rest…
catornow 8ff090a
Corrected `init_qubit` to `init_qubits`
catornow d232b18
Modified doc string of enable_restless
catornow 7c7c2d5
Small modification
catornow 5067925
Fixed docs error
catornow 79991cc
Update qiskit_experiments/framework/restless_mixin.py
catornow 077e21e
Update qiskit_experiments/library/characterization/fine_amplitude.py
catornow a15d451
Update test/data_processing/test_restless_experiment.py
catornow 3427aa3
Update test/data_processing/test_restless_experiment.py
catornow 9d3da96
Implemented Daniel's suggestions
catornow 0a4d4a2
Black
catornow b6784ec
Optional rep_delay
catornow d9a27cf
Added mixin documentation
catornow 9904d96
Changed `override_restless_processor` to `override_processor_by_restl…
catornow e229c26
Implemented Naoki's suggestions
catornow 709bec8
DataProcessorError is raised if the data_processor analysis options d…
catornow 85d97a6
Update qiskit_experiments/framework/restless_mixin.py
eggerdj 3189b73
Merge branch 'main' into RestlessMixin
eggerdj 7799cc4
Black
catornow 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| # 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. | ||
|
|
||
| """Restless mixin class.""" | ||
|
|
||
| from typing import Callable, Sequence, Optional | ||
|
|
||
| from qiskit.providers import Backend | ||
| from qiskit_experiments.data_processing.data_processor import DataProcessor | ||
| from qiskit_experiments.data_processing.exceptions import DataProcessorError | ||
| from qiskit_experiments.data_processing import nodes | ||
| from qiskit_experiments.framework.base_analysis import BaseAnalysis | ||
|
|
||
|
|
||
| class RestlessMixin: | ||
| """A mixin to facilitate restless experiments. | ||
|
|
||
| This class defines the following methods | ||
|
|
||
| - :meth:`enable_restless` | ||
| - :meth:`_get_restless_processor` | ||
| - :meth:`_t1_check` | ||
|
|
||
| A restless enabled experiment is an experiment that can be run in a restless | ||
| measurement setting. In restless measurements, the qubit is not reset after | ||
| each measurement. Instead, the outcome of the previous quantum non-demolition | ||
| measurement is the initial state for the current circuit. Restless measurements | ||
| therefore require special data processing which is provided by sub-classes of | ||
| the :code:`RestlessNode`. Restless experiments are a fast alternative for | ||
| several calibration and characterization tasks, for details see | ||
| https://arxiv.org/pdf/2202.06981.pdf. | ||
| This class makes it possible for users to enter a restless run-mode without having | ||
| to manually set all the required run options and the data processor. The required options | ||
| are ``rep_delay``, ``init_qubits``, ``memory``, and ``meas_level``. Furthermore, | ||
| subclasses can override the :meth:`_get_restless_processor` method if they require more | ||
| complex restless data processing such as two-qubit calibrations. In addition, this | ||
| class makes it easy to determine if restless measurements are supported for a given | ||
| experiments. | ||
| """ | ||
|
|
||
| analysis: BaseAnalysis | ||
eggerdj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| set_run_options: Callable | ||
| backend: Backend | ||
| _physical_qubits: Sequence[int] | ||
| _num_qubits: int | ||
|
|
||
| def enable_restless( | ||
| self, rep_delay: Optional[float] = None, override_processor_by_restless: bool = True | ||
| ): | ||
| """Enables a restless experiment by setting the restless run options and the | ||
| restless data processor. | ||
|
|
||
| Args: | ||
| rep_delay: The repetition delay. This is the delay between a measurement | ||
| and the subsequent quantum circuit. Since the backends have | ||
| dynamic repetition rates, the repetition delay can be set to a small | ||
| value which is required for restless experiments. Typical values are | ||
| 1 us or less. | ||
| override_processor_by_restless: If False, a data processor that is specified in the | ||
| analysis options of the experiment is not overridden by the restless data | ||
| processor. The default is True. | ||
|
|
||
| Raises: | ||
| DataProcessorError: if the attribute rep_delay_range is not defined for the backend. | ||
| DataProcessorError: if a data processor has already been set but | ||
| override_processor_by_restless is True. | ||
| DataProcessorError: if the experiment analysis does not have the data_processor | ||
| option. | ||
| DataProcessorError: if the rep_delay is equal to or greater than the | ||
| T1 time of one of the physical qubits in the experiment. | ||
| """ | ||
| try: | ||
| if not rep_delay: | ||
| rep_delay = self.backend.configuration().rep_delay_range[0] | ||
| except AttributeError as error: | ||
| raise DataProcessorError( | ||
| "The restless experiment can not be enabled because " | ||
| "the attribute rep_delay_range is not defined for this backend " | ||
| "and a minimum rep_delay can not be set." | ||
| ) from error | ||
|
|
||
| # The excited state promotion readout analysis option is set to | ||
| # False because it is not compatible with a restless experiment. | ||
| if self._t1_check(rep_delay): | ||
| if not self.analysis.options.get("data_processor", None): | ||
catornow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.set_run_options( | ||
| rep_delay=rep_delay, | ||
| init_qubits=False, | ||
| memory=True, | ||
| meas_level=2, | ||
| use_measure_esp=False, | ||
| ) | ||
| if hasattr(self.analysis.options, "data_processor"): | ||
| self.analysis.set_options(data_processor=self._get_restless_processor()) | ||
| else: | ||
| raise DataProcessorError( | ||
| "The restless data processor can not be set since the experiment analysis" | ||
| "does not have the data_processor option." | ||
| ) | ||
| else: | ||
| if not override_processor_by_restless: | ||
| self.set_run_options( | ||
| rep_delay=rep_delay, | ||
| init_qubits=False, | ||
| memory=True, | ||
| meas_level=2, | ||
| use_measure_esp=False, | ||
| ) | ||
| else: | ||
| raise DataProcessorError( | ||
| "Cannot enable restless. Data processor has already been set and " | ||
| "override_processor_by_restless is True." | ||
| ) | ||
| else: | ||
| raise DataProcessorError( | ||
| f"The specified repetition delay {rep_delay} is equal to or greater " | ||
| f"than the T1 time of one of the physical qubits" | ||
| f"{self._physical_qubits} in the experiment. Consider choosing " | ||
| f"a smaller repetition delay for the restless experiment." | ||
| ) | ||
|
|
||
| def _get_restless_processor(self) -> DataProcessor: | ||
| """Returns the restless experiments data processor. | ||
|
|
||
| Notes: | ||
| Sub-classes can override this method if they need more complex data processing. | ||
| """ | ||
| outcome = self.analysis.options.get("outcome", "1" * self._num_qubits) | ||
| return DataProcessor( | ||
| "memory", | ||
| [ | ||
| nodes.RestlessToCounts(self._num_qubits), | ||
| nodes.Probability(outcome), | ||
| ], | ||
| ) | ||
|
|
||
| def _t1_check(self, rep_delay: float) -> bool: | ||
| """Check that repetition delay < T1 of the physical qubits in the experiment. | ||
|
|
||
| Args: | ||
| rep_delay: The repetition delay. This is the delay between a measurement | ||
| and the subsequent quantum circuit. | ||
|
|
||
| Returns: | ||
| True if the repetition delay is smaller than the qubit T1 times. | ||
|
|
||
| Raises: | ||
| DataProcessorError: if the T1 values are not defined for the qubits of | ||
| the used backend. | ||
| """ | ||
|
|
||
| try: | ||
| t1_values = [ | ||
| self.backend.properties().qubit_property(physical_qubit)["T1"][0] | ||
| for physical_qubit in self._physical_qubits | ||
| ] | ||
|
|
||
| if all(rep_delay / t1_value < 1.0 for t1_value in t1_values): | ||
| return True | ||
| except AttributeError as error: | ||
| raise DataProcessorError( | ||
| "The restless experiment can not be enabled since " | ||
| "T1 values are not defined for the qubits of the used backend." | ||
| ) from error | ||
|
|
||
| return False | ||
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
Oops, something went wrong.
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.