-
Notifications
You must be signed in to change notification settings - Fork 134
Ramsey refactor. #485
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
Ramsey refactor. #485
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
971dd8e
* Moved RamseyXY to characterization.
eggerdj 34970b9
* refactored RamseyXY.
eggerdj 9f44a4d
Merge branch 'main' into ramsey_refactor
eggerdj 2b3e23a
* Test config.
eggerdj 1260f0d
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj bffaff0
Merge branch 'main' into ramsey_refactor
eggerdj d3bf230
* Arg order in init.
eggerdj 9cf4648
Merge branch 'ramsey_refactor' of github.com:eggerdj/qiskit-experimen…
eggerdj 88f6698
* Removed updated and fixed tests.
eggerdj 99eea33
Merge branch 'main' into ramsey_refactor
eggerdj 92bbf19
Merge branch 'main' into ramsey_refactor
eggerdj 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
110 changes: 110 additions & 0 deletions
110
qiskit_experiments/library/calibration/frequency_cal.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,110 @@ | ||
| # 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. | ||
|
|
||
| """Ramsey XY frequency calibration experiment.""" | ||
|
|
||
| from typing import List, Optional | ||
|
|
||
| from qiskit import QuantumCircuit | ||
| from qiskit.providers.backend import Backend | ||
|
|
||
| from qiskit_experiments.framework import ExperimentData, fix_class_docs | ||
| from qiskit_experiments.library.characterization.ramsey_xy import RamseyXY | ||
| from qiskit_experiments.calibration_management.backend_calibrations import BackendCalibrations | ||
| from qiskit_experiments.calibration_management.update_library import BaseUpdater | ||
| from qiskit_experiments.calibration_management.base_calibration_experiment import ( | ||
| BaseCalibrationExperiment, | ||
| ) | ||
|
|
||
|
|
||
| @fix_class_docs | ||
| class FrequencyCal(BaseCalibrationExperiment, RamseyXY): | ||
| """A qubit frequency calibration experiment based on the Ramsey XY experiment. | ||
|
|
||
| # section: see_also | ||
| qiskit_experiments.library.characterization.ramsey_xy.RamseyXY | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| qubit: int, | ||
| calibrations: BackendCalibrations, | ||
| backend: Optional[Backend] = None, | ||
| delays: Optional[List] = None, | ||
| unit: str = "s", | ||
| osc_freq: float = 2e6, | ||
| auto_update: bool = True, | ||
| ): | ||
| """ | ||
| Args: | ||
| qubit: The qubit on which to run the frequency calibration. | ||
| calibrations: The calibrations instance with the schedules. | ||
| backend: Optional, the backend to run the experiment on. | ||
| delays: The list of delays that will be scanned in the experiment. | ||
| unit: The unit of the delays. Accepted values are dt, i.e. the | ||
| duration of a single sample on the backend, seconds, and sub-units, | ||
| e.g. ms, us, ns. | ||
| osc_freq: A frequency shift in Hz that will be applied by means of | ||
| a virtual Z rotation to increase the frequency of the measured oscillation. | ||
| auto_update: If set to True, which is the default, then the experiment will | ||
| automatically update the frequency in the calibrations. | ||
| """ | ||
| super().__init__( | ||
| calibrations, | ||
| qubit, | ||
| backend=backend, | ||
| delays=delays, | ||
| unit=unit, | ||
| osc_freq=osc_freq, | ||
| cal_parameter_name="qubit_lo_freq", | ||
| auto_update=auto_update, | ||
| ) | ||
|
|
||
| # Instruction schedule map to bring in the calibrations for the sx gate. | ||
| self.set_transpile_options(inst_map=calibrations.default_inst_map) | ||
|
|
||
| def _add_cal_metadata(self, circuits: List[QuantumCircuit]): | ||
| """Add the oscillation frequency of the experiment to the metadata.""" | ||
|
|
||
| param_val = self._cals.get_parameter_value( | ||
| self._param_name, | ||
| self.physical_qubits, | ||
| group=self.experiment_options.group, | ||
| ) | ||
|
|
||
| for circuit in circuits: | ||
| circuit.metadata["cal_param_value"] = param_val | ||
| circuit.metadata["cal_group"] = self.experiment_options.group | ||
| circuit.metadata["osc_freq"] = self.experiment_options.osc_freq | ||
|
|
||
| def update_calibrations(self, experiment_data: ExperimentData): | ||
| """Update the frequency using the reported frequency less the imparted oscillation.""" | ||
|
|
||
| data = experiment_data.data() | ||
|
|
||
| # No data -> no update | ||
| if len(data) > 0: | ||
| result_index = self.experiment_options.result_index | ||
| osc_freq = data[0]["metadata"]["osc_freq"] | ||
| group = data[0]["metadata"]["cal_group"] | ||
| old_freq = data[0]["metadata"]["cal_param_value"] | ||
|
|
||
| fit_freq = BaseUpdater.get_value(experiment_data, "freq", result_index) | ||
| new_freq = old_freq + fit_freq - osc_freq | ||
|
nkanazawa1989 marked this conversation as resolved.
|
||
|
|
||
| BaseUpdater.add_parameter_value( | ||
| self._cals, | ||
| experiment_data, | ||
| new_freq, | ||
| self._param_name, | ||
| group=group, | ||
| ) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the analysis_callback, are there still cases where data is empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure. In any case its good to protect against empty data to avoid things like
IndexErrors.