Source code for qiskit_experiments.library.characterization.analysis.tphi_analysis
# 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."""fromtypingimportList,Tuplefromqiskit_experiments.frameworkimportExperimentData,AnalysisResultDatafromqiskit_experiments.framework.composite.composite_analysisimportCompositeAnalysisfromqiskit_experiments.library.characterization.analysisimport(T1Analysis,T2HahnAnalysis,T2RamseyAnalysis,)fromqiskit_experiments.exceptionsimportQiskitError
[docs]classTphiAnalysis(CompositeAnalysis):r"""A class to analyze :math:`T_\phi` experiments. # section: see_also * :py:class:`qiskit_experiments.library.characterization.analysis.T1Analysis` * :py:class:`qiskit_experiments.library.characterization.analysis.T2HahnAnalysis` * :py:class:`qiskit_experiments.library.characterization.analysis.T2RamseyAnalysis` """def__init__(self,analyses=None):ifanalysesisNone:analyses=[T1Analysis(),T2HahnAnalysis()]# Validate analyses kwargif(len(analyses)!=2ornotisinstance(analyses[0],T1Analysis)ornotisinstance(analyses[1],(T2RamseyAnalysis,T2HahnAnalysis))):raiseQiskitError("Invalid component analyses for Tphi, analyses must be a pair of ""T1Analysis and T2HahnAnalysis or T2RamseyAnalysis instances.")super().__init__(analyses,flatten_results=True)def_run_analysis(self,experiment_data:ExperimentData)->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`. """# Run composite analysis and extract T1 and T2 resultsanalysis_results,figures=super()._run_analysis(experiment_data)t1_result=next(filter(lambdares:res.name=="T1",analysis_results))t2_result=next(filter(lambdares:res.namein{"T2star","T2"},analysis_results))# Calculate Tphi from T1 and T2tphi=1/(1/t2_result.value-1/(2*t1_result.value))quality_tphi=("good"if(t1_result.quality=="good"andt2_result.quality=="good")else"bad")tphi_result=AnalysisResultData(name="T_phi",value=tphi,chisq=None,quality=quality_tphi,extra={"unit":"s"},)# Return combined resultsanalysis_results=[tphi_result]+analysis_resultsreturnanalysis_results,figures