-
Notifications
You must be signed in to change notification settings - Fork 135
Resonator spectroscopy #583
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 53 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
117fdb1
* First draft of new resonator spec.
eggerdj b6821f5
* Resonator spectroscopy.
eggerdj 4b00b55
* Added IQ plotting.
eggerdj f568738
* Adding methodology to handle the Classical bit.
eggerdj 660766a
* Switched to a parallelizable methodology for the classical bit.
eggerdj c36d329
* Data processing for the resonator spectroscopy experiment.
eggerdj 6786c83
Merge branch 'main' into resonator_spec
eggerdj 3db95ee
* Added a test for the ToAbs node.
eggerdj e1de77f
* Black and tests for resonator spectroscopy.
eggerdj a807b10
* Reno and lint.
eggerdj d3674a1
* Docs.
eggerdj 7f920fd
* Change the sqrt in ToAbs node to the unp version.
eggerdj 7331ae0
* Refactored processor library.
eggerdj 2c1c124
* processor_library docstring.
eggerdj fb3eaf1
* Add ResSpecAnalysis to tree.
eggerdj a0072d8
Update qiskit_experiments/library/characterization/resonator_spectros…
eggerdj 2355825
* Simplified resonator spectroscopy doc.
eggerdj c42dcf8
Merge branch 'resonator_spec' of github.com:eggerdj/qiskit-experiment…
eggerdj 5515f2d
* Added key word arguments to init for one liner execution.
eggerdj 5a07e94
* Release note text.
eggerdj bde77fb
* Create the Spectroscopy base class for spectroscopy experiments.
eggerdj a2bc3da
* made center_frequency private.
eggerdj 8bdce88
* Center frequency refactor.
eggerdj e9f7ae4
* circuit metadata refactor.
eggerdj dfe3149
* Added acquire delay and set default amplitude to 1 for resonator spec.
eggerdj b5bce85
* Reonator spectroscopy test Lorentzian resonance.
eggerdj 6d487cc
* IQ plot robustness.
eggerdj c438b15
Merge branch 'main' into resonator_spec
eggerdj be7b264
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into reso…
eggerdj 26dfd60
Merge branch 'resonator_spec' of github.com:eggerdj/qiskit-experiment…
eggerdj 0ef184b
* Refactored ResonatorSpectroscopyAnalysis
eggerdj bab4a73
* Test fix.
eggerdj 13d5bb2
* Units, corresponding test fix, and black.
eggerdj cd436f8
* Lint and default frequencies.
eggerdj 58f9535
* Fix factor omission.
eggerdj 256c3f6
* Align tests.
eggerdj 86001af
* Simplified resonator spec options.
eggerdj 67865cd
* Reno.
eggerdj 7c44dd1
* More robust IQ plotting.
eggerdj b8b99d6
* Y-axis label.
eggerdj 26848e3
* Resonator spec doc string.
eggerdj 373dfd3
* Resonator spec doc.
eggerdj 7d7fa8e
* Docstring.
eggerdj a357bf0
* Metadata always has absolute frequencies.
eggerdj 62ce701
* Moved projector type.
eggerdj 7524359
* Refactor resonance analysis to use a Lorentzian and renamed the exi…
eggerdj 8796b32
* Lorentz normalization, small bug fixes, black.
eggerdj 723202c
* Test normalozation.
eggerdj dac1681
* Reno.
eggerdj 4461880
Merge branch 'main' into resonator_spec
eggerdj ead7c55
* Removed center_frequency.
eggerdj a994631
* black.
eggerdj e7ccdf0
* Qubit spec test align.
eggerdj 9dbe059
* Device components.
eggerdj 3e258cb
* Resonator kappa in result.
eggerdj fd97988
Update qiskit_experiments/library/characterization/analysis/resonator…
eggerdj 5d9f0b4
* Resonator spectroscopy kappa and fit function.
eggerdj 4b7715d
* Adapted tests.
eggerdj 73eaa4e
* Update default options.
eggerdj d38558e
Merge branch 'main' into resonator_spec
eggerdj 8eb9d20
* Moved qubit spectroscopy to units of seconds.
eggerdj c09f9bf
Merge branch 'resonator_spec' of github.com:eggerdj/qiskit-experiment…
eggerdj 9a6417f
* set backend
eggerdj 6e7c915
Merge branch 'main' into resonator_spec
eggerdj a999744
* Lint
eggerdj 40dd598
Merge branch 'resonator_spec' of github.com:eggerdj/qiskit-experiment…
eggerdj fac4995
* Square root lorentzian.
eggerdj 9358a2b
* Remove acquire delay and duration.
eggerdj da67d69
* Doc fix.
eggerdj 35e5af4
Update qiskit_experiments/library/characterization/analysis/resonator…
eggerdj 45f6dac
Update test/test_resonator_spectroscopy.py
eggerdj c947b2a
Merge branch 'main' into resonator_spec
eggerdj 83a1b3e
* Docs
eggerdj 9990736
* Reno
eggerdj 77e8fb4
* Added more tests values.
eggerdj 322ed86
* Black
eggerdj 072c40d
Merge branch 'main' into resonator_spec
eggerdj ba5d9ac
* Docs.
eggerdj 30e0898
Merge branch 'resonator_spec' of github.com:eggerdj/qiskit-experiment…
eggerdj 0664a21
* Added warning in resonator spectroscopy docstring.
eggerdj 2904da9
Update qiskit_experiments/library/characterization/resonator_spectros…
eggerdj cd795b3
Merge branch 'main' into resonator_spec
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
156 changes: 156 additions & 0 deletions
156
qiskit_experiments/curve_analysis/standard_analysis/gaussian.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,156 @@ | ||
| # 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. | ||
|
|
||
| """Resonance analysis class based on a Gaussian fit.""" | ||
|
|
||
| from typing import List, Union | ||
|
|
||
| import numpy as np | ||
|
|
||
| import qiskit_experiments.curve_analysis as curve | ||
| from qiskit_experiments.framework import Options | ||
|
|
||
|
|
||
| class GaussianAnalysis(curve.CurveAnalysis): | ||
| r"""A class to analyze a resonance, typically seen as a peak. | ||
|
|
||
| Overview | ||
| This analysis takes only single series. This series is fit by the Gaussian function. | ||
|
|
||
| Fit Model | ||
| The fit is based on the following Gaussian function. | ||
|
|
||
| .. math:: | ||
|
|
||
| F(x) = a \exp(-(x-f)^2/(2\sigma^2)) + b | ||
|
|
||
| Fit Parameters | ||
| - :math:`a`: Peak height. | ||
| - :math:`b`: Base line. | ||
| - :math:`f`: Center frequency. This is the fit parameter of main interest. | ||
| - :math:`\sigma`: Standard deviation of Gaussian function. | ||
|
|
||
| Initial Guesses | ||
| - :math:`a`: Calculated by :func:`~qiskit_experiments.curve_analysis.guess.max_height`. | ||
| - :math:`b`: Calculated by :func:`~qiskit_experiments.curve_analysis.guess.\ | ||
| constant_spectral_offset`. | ||
| - :math:`f`: Frequency at max height position calculated by | ||
| :func:`~qiskit_experiments.curve_analysis.guess.max_height`. | ||
| - :math:`\sigma`: Calculated from FWHM of peak :math:`w` | ||
| such that :math:`w / \sqrt{8} \ln{2}`, where FWHM is calculated by | ||
| :func:`~qiskit_experiments.curve_analysis.guess.full_width_half_max`. | ||
|
|
||
| Bounds | ||
| - :math:`a`: [-2, 2] scaled with maximum signal value. | ||
| - :math:`b`: [-1, 1] scaled with maximum signal value. | ||
| - :math:`f`: [min(x), max(x)] of frequency scan range. | ||
| - :math:`\sigma`: [0, :math:`\Delta x`] where :math:`\Delta x` | ||
| represents frequency scan range. | ||
|
|
||
| """ | ||
|
|
||
| __series__ = [ | ||
| curve.SeriesDef( | ||
| fit_func=lambda x, a, sigma, freq, b: curve.fit_function.gaussian( | ||
| x, amp=a, sigma=sigma, x0=freq, baseline=b | ||
| ), | ||
| plot_color="blue", | ||
| model_description=r"a \exp(-(x-f)^2/(2\sigma^2)) + b", | ||
| ) | ||
| ] | ||
|
|
||
| @classmethod | ||
| def _default_options(cls) -> Options: | ||
| options = super()._default_options() | ||
| options.result_parameters = [curve.ParameterRepr("freq", "f01", "Hz")] | ||
| options.normalization = True | ||
| options.xlabel = "Frequency" | ||
| options.ylabel = "Signal (arb. units)" | ||
| options.xval_unit = "Hz" | ||
| return options | ||
|
|
||
| def _generate_fit_guesses( | ||
| self, user_opt: curve.FitOptions | ||
| ) -> Union[curve.FitOptions, List[curve.FitOptions]]: | ||
| """Compute the initial guesses. | ||
|
|
||
| Args: | ||
| user_opt: Fit options filled with user provided guess and bounds. | ||
|
|
||
| Returns: | ||
| List of fit options that are passed to the fitter function. | ||
| """ | ||
| curve_data = self._data() | ||
| max_abs_y, _ = curve.guess.max_height(curve_data.y, absolute=True) | ||
|
|
||
| user_opt.bounds.set_if_empty( | ||
| a=(-2 * max_abs_y, 2 * max_abs_y), | ||
| sigma=(0, np.ptp(curve_data.x)), | ||
| freq=(min(curve_data.x), max(curve_data.x)), | ||
| b=(-max_abs_y, max_abs_y), | ||
| ) | ||
| user_opt.p0.set_if_empty(b=curve.guess.constant_spectral_offset(curve_data.y)) | ||
|
|
||
| y_ = curve_data.y - user_opt.p0["b"] | ||
|
|
||
| _, peak_idx = curve.guess.max_height(y_, absolute=True) | ||
| fwhm = curve.guess.full_width_half_max(curve_data.x, y_, peak_idx) | ||
|
|
||
| user_opt.p0.set_if_empty( | ||
| a=curve_data.y[peak_idx] - user_opt.p0["b"], | ||
| freq=curve_data.x[peak_idx], | ||
| sigma=fwhm / np.sqrt(8 * np.log(2)), | ||
| ) | ||
|
|
||
| return user_opt | ||
|
|
||
| def _evaluate_quality(self, fit_data: curve.FitData) -> Union[str, None]: | ||
| """Algorithmic criteria for whether the fit is good or bad. | ||
|
|
||
| A good fit has: | ||
| - a reduced chi-squared less than 3, | ||
| - a peak within the scanned frequency range, | ||
| - a standard deviation that is not larger than the scanned frequency range, | ||
| - a standard deviation that is wider than the smallest frequency increment, | ||
| - a signal-to-noise ratio, defined as the amplitude of the peak divided by the | ||
| square root of the median y-value less the fit offset, greater than a | ||
| threshold of two, and | ||
| - a standard error on the sigma of the Gaussian that is smaller than the sigma. | ||
| """ | ||
| curve_data = self._data() | ||
|
|
||
| max_freq = np.max(curve_data.x) | ||
| min_freq = np.min(curve_data.x) | ||
| freq_increment = np.mean(np.diff(curve_data.x)) | ||
|
|
||
| fit_a = fit_data.fitval("a").value | ||
| fit_b = fit_data.fitval("b").value | ||
| fit_freq = fit_data.fitval("freq").value | ||
| fit_sigma = fit_data.fitval("sigma").value | ||
| fit_sigma_err = fit_data.fitval("sigma").stderr | ||
|
|
||
| snr = abs(fit_a) / np.sqrt(abs(np.median(curve_data.y) - fit_b)) | ||
| fit_width_ratio = fit_sigma / (max_freq - min_freq) | ||
|
|
||
| criteria = [ | ||
| min_freq <= fit_freq <= max_freq, | ||
| 1.5 * freq_increment < fit_sigma, | ||
| fit_width_ratio < 0.25, | ||
| fit_data.reduced_chisq < 3, | ||
| (fit_sigma_err is None or fit_sigma_err < fit_sigma), | ||
| snr > 2, | ||
| ] | ||
|
|
||
| if all(criteria): | ||
| return "good" | ||
|
|
||
| return "bad" |
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.