Skip to content
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
ff5e9d7
Beginning implementation of T_phi
merav-aharoni Jul 22, 2021
c0f64c4
Added init files
merav-aharoni Jul 30, 2021
fef446b
Built circuits for T_phi
merav-aharoni Aug 18, 2021
1f2867c
Merge branch 'main' into t_phi
merav-aharoni Aug 18, 2021
8582ada
Defined class T_phi
merav-aharoni Aug 18, 2021
94a0408
Added run method to class Tphi
merav-aharoni Sep 9, 2021
5b742fd
Merged with main
merav-aharoni Sep 9, 2021
68ad6f8
First stage of Tphi - up to run
merav-aharoni Sep 22, 2021
0c063b1
Merge with main
merav-aharoni Oct 6, 2021
f0c0f84
Merged with main
merav-aharoni Jan 6, 2022
1b328e7
Added test for Tphi. Added backend for testing, based on T1 and T2Ram…
merav-aharoni Jan 6, 2022
8fa6dbb
black
merav-aharoni Jan 6, 2022
fdea969
Merged with main
merav-aharoni Jan 6, 2022
049a13f
Fixed return FakeJob from TphiBackend.run
merav-aharoni Jan 13, 2022
9db05c0
Merge branch 'main' of github.com:merav-aharoni/qiskit-experiments in…
merav-aharoni Jan 13, 2022
12292de
Merge branch 'main' into t_phi
merav-aharoni Jan 16, 2022
f2b6e03
Merged with main
merav-aharoni Jan 16, 2022
d0bc161
Get sub-experiment analysis results from expdata.child_data
merav-aharoni Jan 16, 2022
b1a0b9a
Added _run_analysis for TphiAnalysis. Added parameter to BatchExperi…
merav-aharoni Jan 16, 2022
ea8e5f1
Cleaned up return value for Tphi analysis results. Computed the final…
merav-aharoni Jan 18, 2022
7c79f02
black and lint
merav-aharoni Jan 18, 2022
c7b8728
Removed usage of 'units' in Tphi. Added usage of set_experiment_optio…
merav-aharoni Jan 18, 2022
f79d8a3
Removed unnecessary variable 'unit' and unnecessary imports.
merav-aharoni Jan 18, 2022
026b5e8
Added missing 'TphiAnalysis in __init__
merav-aharoni Jan 18, 2022
151f337
Added documentation for Tphi
merav-aharoni Jan 19, 2022
b0f710d
Added 'analysis' parameter to BatchExperiment and to CompositeExperiment
merav-aharoni Jan 20, 2022
b7395c5
Added title and section to tphi tutorial
merav-aharoni Jan 20, 2022
1ff54e4
Merge branch 'main' into t_phi
merav-aharoni Jan 20, 2022
2e5422a
Fixed Tphi computation. Wrote tutorial. Added computation with uncert…
merav-aharoni Jan 20, 2022
f970a68
black and lint
merav-aharoni Jan 20, 2022
28b9976
Merge branch 'main' into t_phi
merav-aharoni Jan 20, 2022
ca2ef67
Fixed title of tutorial
merav-aharoni Jan 23, 2022
e522c09
Merge branch 't_phi' of github.com:merav-aharoni/qiskit-experiments i…
merav-aharoni Jan 23, 2022
82f16f4
Removed unnecessary prints and empty lines
merav-aharoni Jan 23, 2022
13262ce
Merge branch 'main' into t_phi
merav-aharoni Jan 23, 2022
719e697
lint and black
merav-aharoni Jan 23, 2022
6ebcd23
Merge branch 't_phi' of github.com:merav-aharoni/qiskit-experiments i…
merav-aharoni Jan 23, 2022
1124684
Change of parameter merged from main
merav-aharoni Jan 23, 2022
6170765
lint
merav-aharoni Jan 23, 2022
77c9ff2
Added references for Tphi
merav-aharoni Jan 23, 2022
3cafd78
Updated copyright to 2022. Added _set_backend to Tphi
merav-aharoni Jan 24, 2022
28d9c32
black and lint
merav-aharoni Jan 24, 2022
0fd6120
Merge branch 'main' into t_phi
merav-aharoni Jan 25, 2022
9ecb257
Bug fix: parameter 'backend' was missing in calls to T1 and T2Ramsey
merav-aharoni Jan 26, 2022
9189c00
Cleaned up Tphi tutorial
merav-aharoni Jan 26, 2022
bdb4b9d
Merge branch 't_phi' of github.com:merav-aharoni/qiskit-experiments i…
merav-aharoni Jan 26, 2022
0f609a3
black
merav-aharoni Jan 26, 2022
a37d38c
Removed dataProcessor from default_options because it was causing a w…
merav-aharoni Jan 26, 2022
bcaacff
Merge branch 'main' into t_phi
merav-aharoni Jan 27, 2022
ccbba12
black and lint
merav-aharoni Jan 27, 2022
208e462
Added release notes for tphi
merav-aharoni Jan 27, 2022
97ebb23
Syntax changes resulting from code review
merav-aharoni Jan 27, 2022
e129cf7
Update qiskit_experiments/library/characterization/tphi.py
merav-aharoni Jan 27, 2022
031019a
Update qiskit_experiments/library/characterization/tphi.py
merav-aharoni Jan 27, 2022
dc7dc50
Removed two unnecessary methods, and did some cleaning following sugg…
merav-aharoni Jan 27, 2022
e6d9ca1
Added class documentation. Removed overriding of shots
merav-aharoni Jan 27, 2022
188d220
Removed unnecessary parameter that I previously added to BatchExperi…
merav-aharoni Jan 27, 2022
71c70c4
Merge branch 't_phi' of github.com:merav-aharoni/qiskit-experiments i…
merav-aharoni Jan 27, 2022
aca48fc
Removed setting of shots in backend options. Changed 'block_for_resul…
merav-aharoni Jan 30, 2022
e76c7f0
Merge branch 'main' into t_phi
merav-aharoni Jan 30, 2022
540a945
black
merav-aharoni Jan 30, 2022
c69f716
Syntax changes in tutorial
merav-aharoni Jan 30, 2022
993cde9
black
merav-aharoni Jan 30, 2022
45284b2
Fixed problems in math font in tutorial text
merav-aharoni Jan 30, 2022
23fbff3
Syntax changes in tutorial
merav-aharoni Jan 30, 2022
714d19e
Improved documentation in tutorial and in TphiExperiment class
merav-aharoni Jan 30, 2022
7080654
Removed 'name' that was added previously to t1 and t2ramsey. Instead,…
merav-aharoni Jan 30, 2022
6dddddf
Fixed setting of default options in Tphi
merav-aharoni Jan 31, 2022
15602b8
Added links to classes in the release notes
merav-aharoni Jan 31, 2022
cabd8d8
Merged with main
merav-aharoni Jan 31, 2022
1d00174
Added info on the tphi experiment to the release notes
merav-aharoni Feb 1, 2022
9ebb855
Implemented a set_experiment_options for tphi, that sets the options …
merav-aharoni Feb 1, 2022
5ab5b4c
Added test to check that circtuis are modified correctly when using s…
merav-aharoni Feb 1, 2022
0514857
Merge branch 'main' into t_phi
merav-aharoni Feb 2, 2022
a2e56c3
Added component analysis classes to the constructor of TphiAnalysis()…
merav-aharoni Feb 3, 2022
cff6af6
Merge branch 'main' into t_phi
merav-aharoni Feb 3, 2022
cb4fb0d
black
merav-aharoni Feb 3, 2022
feb4342
Merge branch 't_phi' of github.com:merav-aharoni/qiskit-experiments i…
merav-aharoni Feb 3, 2022
d5fafc3
Merge branch 'main' into t_phi
merav-aharoni Feb 3, 2022
b52dd6f
Added setting of osc_freq to set_experiment_options. Added a respecti…
merav-aharoni Feb 3, 2022
42e0139
Merge branch 't_phi' of github.com:merav-aharoni/qiskit-experiments i…
merav-aharoni Feb 3, 2022
66333e8
Merge branch 'main' into t_phi
merav-aharoni Feb 6, 2022
b20d38b
Merge branch 'main' into t_phi
merav-aharoni Feb 6, 2022
bafdcc3
Changed variable name
merav-aharoni Feb 7, 2022
e6563ce
Merge branch 'main' into t_phi
merav-aharoni Feb 8, 2022
9db90d8
Added to tests 'assertExperimentDone'
merav-aharoni Feb 8, 2022
bdb0828
Merge branch 't_phi' of github.com:merav-aharoni/qiskit-experiments i…
merav-aharoni Feb 8, 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
253 changes: 253 additions & 0 deletions docs/tutorials/tphi_characterization.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion qiskit_experiments/database_service/db_experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def add_analysis_callback(self, callback: Callable, **kwargs: Any):
"""Add analysis callback for running after experiment data jobs are finished.

This method adds the `callback` function to a queue to be run
asynchronously after complition of any running jobs, or immediately
asynchronously after completion of any running jobs, or immediately
if no running jobs. If this method is called multiple times the
callback functions will be executed in the order they were
added.
Expand Down
2 changes: 1 addition & 1 deletion qiskit_experiments/framework/base_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(
self.analysis = analysis_cls() # pylint: disable = not-callable

# Set backend
# This should be called last incase `_set_backend` access any of the
# This should be called last in case `_set_backend` access any of the
# attributes created during initialization
self._backend = None
if isinstance(backend, (Backend, BaseBackend)):
Expand Down
4 changes: 2 additions & 2 deletions qiskit_experiments/framework/composite/composite_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CompositeAnalysis(BaseAnalysis):

.. note::

The the child :class:`ExperimentData` for each component experiment
If the child :class:`ExperimentData` for each component experiment
does not already exist in the experiment data they will be initialized
and added to the experiment data when :meth:`run` is called on the
composite :class:`ExperimentData`.
Expand Down Expand Up @@ -91,7 +91,7 @@ def _component_experiment_data(self, experiment_data: ExperimentData) -> List[Ex
)

# Extract job metadata for the component experiments so it can be added
# to the child experiment data incase it is required by the child experiments
# to the child experiment data in case it is required by the child experiments
# analysis classes
component_metadata = experiment_data.metadata.get(
"component_metadata", [{}] * len(component_ids)
Expand Down
2 changes: 2 additions & 0 deletions qiskit_experiments/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

~characterization.T1
~characterization.T2Ramsey
~characterization.Tphi
~characterization.QubitSpectroscopy
~characterization.EFSpectroscopy
~characterization.CrossResonanceHamiltonian
Expand Down Expand Up @@ -121,6 +122,7 @@ class instance to manage parameters and pulse schedules.
from .characterization import (
T1,
T2Ramsey,
Tphi,
QubitSpectroscopy,
EFSpectroscopy,
CrossResonanceHamiltonian,
Expand Down
4 changes: 4 additions & 0 deletions qiskit_experiments/library/characterization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
T1
T2Ramsey
T2Hahn
Tphi
QubitSpectroscopy
CrossResonanceHamiltonian
EchoedCrossResonanceHamiltonian
Expand Down Expand Up @@ -54,6 +55,7 @@
T1Analysis
T2RamseyAnalysis
T2HahnAnalysis
TphiAnalysis
CrossResonanceHamiltonianAnalysis
DragCalAnalysis
FineHalfAngleAnalysis
Expand All @@ -72,6 +74,7 @@
T2RamseyAnalysis,
T1Analysis,
T2HahnAnalysis,
TphiAnalysis,
CrossResonanceHamiltonianAnalysis,
ReadoutAngleAnalysis,
)
Expand All @@ -81,6 +84,7 @@
from .ef_spectroscopy import EFSpectroscopy
from .t2ramsey import T2Ramsey
from .t2hahn import T2Hahn
from .tphi import Tphi
from .cr_hamiltonian import CrossResonanceHamiltonian, EchoedCrossResonanceHamiltonian
from .rabi import Rabi, EFRabi
from .half_angle import HalfAngle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
from .t2ramsey_analysis import T2RamseyAnalysis
from .t2hahn_analysis import T2HahnAnalysis
from .t1_analysis import T1Analysis
from .tphi_analysis import TphiAnalysis
from .cr_hamiltonian_analysis import CrossResonanceHamiltonianAnalysis
from .readout_angle_analysis import ReadoutAngleAnalysis
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
T2Ramsey Experiment class.
"""
from typing import Union

from qiskit_experiments.data_processing import DataProcessor, Probability
import qiskit_experiments.curve_analysis as curve


from qiskit_experiments.framework import Options


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
#
# 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.
"""
Tphi Analysis class.
"""

from typing import List, Tuple
from uncertainties import ufloat

from qiskit_experiments.framework import (
ExperimentData,
AnalysisResultData,
FitVal,
)
from qiskit_experiments.framework.composite.composite_analysis import CompositeAnalysis


class TphiAnalysis(CompositeAnalysis):

r"""
Tphi result analysis class.
A class to analyze :math:`T_\phi` experiments.
"""

def _run_analysis(
self, experiment_data: ExperimentData, **options
) -> Tuple[List[AnalysisResultData], List["matplotlib.figure.Figure"]]:
r"""Run analysis for :math:`T_\phi` experiment.
It invokes CompositeAnalysis._run_analysis that will invoke
_run_analysis for the two sub-experiments.
Based on the results, it computes the result for :math:`T_phi`.
"""
_, _ = super()._run_analysis(experiment_data, **options)

t1_result = experiment_data.child_data(0).analysis_results("T1")
t2star_result = experiment_data.child_data(1).analysis_results("T2star")
# we use the 'ucert' prefix to denote values that include
# uncertainty using the `uncertainties` package
uncert_t1_res = ufloat(t1_result.value.value, t1_result.value.stderr)
uncert_t2star_res = ufloat(t2star_result.value.value, t2star_result.value.stderr)
uncert_reciprocal = (1 / uncert_t2star_res) - (1 / (2 * uncert_t1_res))
uncert_tphi = 1 / uncert_reciprocal

quality_tphi = (
"good" if (t1_result.quality == "good" and t2star_result.quality == "good") else "bad"
)

analysis_results = []
analysis_results.append(
AnalysisResultData(
name="T_phi",
value=FitVal(uncert_tphi.nominal_value, uncert_tphi.std_dev),
chisq=None,
quality=quality_tphi,
extra={},
)
)
return analysis_results, []
119 changes: 119 additions & 0 deletions qiskit_experiments/library/characterization/tphi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
#
# 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.
"""
Tphi Experiment class.
"""

from typing import List, Optional, Union
import numpy as np

from qiskit import QiskitError
from qiskit.providers import Backend
from qiskit.test.mock import FakeBackend
from qiskit_experiments.framework.composite.batch_experiment import BatchExperiment
from qiskit_experiments.library.characterization import (
T1,
T2Ramsey,
TphiAnalysis,
T1Analysis,
T2RamseyAnalysis,
)


class Tphi(BatchExperiment):
r"""Tphi Experiment Class

# section: overview

:math:`\Gamma_\varphi` is defined as the rate of pure dephasing
or depolarization in the :math:`x - y` plane.
We compute :math:`\Gamma_\varphi` by computing :math:`\Gamma_2*`, the transverse relaxation rate,
and subtracting :math:`\Gamma_1`, the longitudinal relaxation rate. The pure dephasing time
Comment thread
merav-aharoni marked this conversation as resolved.
is defined by :math:`T_\varphi = 1/\Gamma_\varphi`. Or more precisely,

:math:`1/T_\varphi = 1/T_{2*} - 1/2T_1`.

For more details, see :py:class:`T1` and :py:class:`T2Ramsey`

# section: analysis_ref
:py:class:`TphiAnalysis`

# section: reference
.. ref_arxiv:: 1 1904.06560v5

# section: tutorial
:doc:`/tutorials/tphi_characterization`
"""

def set_experiment_options(self, **fields):
"""Set the experiment options.
Args:
fields: The fields defining the options

Raises:
QiskitError : Error for invalid input option.
"""
# propagate options to the sub-experiments.
for key in fields:
if key == "delays_t1":
self.component_experiment(0).set_experiment_options(delays=fields["delays_t1"])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a subtle point here, and I think what you're doing is the most appropriate.

The experiment options are exposed to the user by the property BaseExperiment.experiment_options. I understand that you wish to mask the internal implementation of a batch experiment consisting of sub-experiments. But a user who'll try tphi_exp.experiment_options.delays_t1 will get an error, because Tphi doesn't really have an option named delays_t1.

You can try to solve this by maintaining options delays_t1 and delays_t2 in Tphi, in addition to the delay options of the sub-experiments. But then what will you do if the user does tphi_exp.experiment_options.delays_t1 = .... You'll face again the issue of having to sync with the delays of the sub-experiment.

You'll keep facing similar issues if you try to override experiment_options. Possibly the only way to obtain full masking is by overriding Options, which is exaggerated. Hence the bottom line (which I already wrote in the upper line) that the current code is the most reasonable one, in my opinion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this were C++, I could have one of the delays_t2 (in Tphi and in T2Ramsey) fields point to the other. But as far as I know, there is no pointer concept in Python, right?

elif key == "delays_t2":
self.component_experiment(1).set_experiment_options(delays=fields["delays_t2"])
else:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

osc_freq is missing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Added it + a test.

raise QiskitError(f"Tphi experiment does not support option {key}")

def __init__(
self,
qubit: int,
delays_t1: List[Union[List[float], np.array]],
delays_t2: List[Union[List[float], np.array]],
osc_freq: float = 0.0,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a later PR, I wonder if there's a nice way to make Tphi modular, for example to allow the user to choose between T2Ramsey and T2Hahn

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future. Or else, simply add another experiment.

backend: Optional[Backend] = None,
):
"""Initialize the experiment object.

Args:
qubit: the qubit under test
delays_t1: delay times of the T1 experiment
delays_t2: delay times of the T2* experiment
osc_freq: the oscillation frequency induced using by the user for T2Ramsey
backend: Optional, the backend on which to run the experiment
"""

exp_t1 = T1(qubit=qubit, delays=delays_t1, backend=backend)
exp_t2 = T2Ramsey(
qubit=qubit,
delays=delays_t2,
backend=backend,
osc_freq=osc_freq,
)
self.exps = [exp_t1, exp_t2]

# Create batch experiment
super().__init__(experiments=self.exps, backend=backend)

self.set_experiment_options(delays_t1=delays_t1, delays_t2=delays_t2)
# CompositeAnalysis accept the component analysis classes in its constructor
self.analysis = TphiAnalysis(analyses=[T1Analysis(), T2RamseyAnalysis()])

def _set_backend(self, backend: Backend):
super()._set_backend(backend)

# Scheduling parameters
if not self._backend.configuration().simulator and not isinstance(backend, FakeBackend):
timing_constraints = getattr(self.transpile_options, "timing_constraints", {})
if "acquire_alignment" not in timing_constraints:
timing_constraints["acquire_alignment"] = 16
scheduling_method = getattr(self.transpile_options, "scheduling_method", "alap")
self.set_transpile_options(
timing_constraints=timing_constraints, scheduling_method=scheduling_method
)
1 change: 0 additions & 1 deletion qiskit_experiments/test/t1_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,4 @@ def run(self, run_input, **options):
"data": {"counts": counts},
}
)

return FakeJob(backend=self, result=Result.from_dict(result))
Loading