Skip to content

Commit

Permalink
Fix to follow changes in what CurveAnalysis._run_analysis returns
Browse files Browse the repository at this point in the history
  • Loading branch information
itoko committed Feb 14, 2024
1 parent 2a3caf4 commit 1ba4a75
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import qiskit_experiments.database_service.device_component as device
from qiskit_experiments.exceptions import AnalysisError
from qiskit_experiments.framework import CompositeAnalysis, AnalysisResultData, ExperimentData
from qiskit_experiments.framework.containers import FigureType, ArtifactData

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -160,7 +161,7 @@ def _create_analysis_results(

def _run_analysis(
self, experiment_data: ExperimentData
) -> Tuple[List[AnalysisResultData], List["matplotlib.figure.Figure"]]:
) -> Tuple[List[Union[AnalysisResultData, ArtifactData]], List[FigureType]]:
try:
return super()._run_analysis(experiment_data)
except Exception: # pylint: disable=broad-except
Expand Down Expand Up @@ -235,16 +236,15 @@ def __init__(self, layer, analyses=None):

def _run_analysis(
self, experiment_data: ExperimentData
) -> Tuple[List[AnalysisResultData], List["matplotlib.figure.Figure"]]:
) -> Tuple[List[Union[AnalysisResultData, ArtifactData]], List[FigureType]]:
try:
# Run composite analysis and extract sub-experiments results
analysis_results, figures = super()._run_analysis(experiment_data)
# Calculate single layer fidelity from process fidelities of subsystems
pfs = [res.value for res in analysis_results if res.name == "ProcessFidelity"]
pf_results = [res for res in analysis_results if res.name == "ProcessFidelity"]
pfs = [res.value for res in pf_results]
slf = np.prod(pfs)
quality_slf = (
"good" if all(sub.quality == "good" for sub in analysis_results) else "bad"
)
quality_slf = "good" if all(sub.quality == "good" for sub in pf_results) else "bad"
slf_result = AnalysisResultData(
name="SingleLF",
value=slf,
Expand Down Expand Up @@ -292,7 +292,7 @@ def __init__(self, layers, analyses=None):

def _run_analysis(
self, experiment_data: ExperimentData
) -> Tuple[List[AnalysisResultData], List["matplotlib.figure.Figure"]]:
) -> Tuple[List[Union[AnalysisResultData, ArtifactData]], List[FigureType]]:
r"""Run analysis for Layer Fidelity experiment.
It invokes :meth:`CompositeAnalysis._run_analysis` that will invoke
Expand All @@ -314,9 +314,10 @@ def _run_analysis(
# Run composite analysis and extract sub-experiments results
analysis_results, figures = super()._run_analysis(experiment_data)
# Calculate full layer fidelity from single layer fidelities
slfs = [res.value for res in analysis_results if res.name == "SingleLF"]
slf_results = [res for res in analysis_results if res.name == "SingleLF"]
slfs = [res.value for res in slf_results]
lf = np.prod(slfs)
quality_lf = "good" if all(sub.quality == "good" for sub in analysis_results) else "bad"
quality_lf = "good" if all(sub.quality == "good" for sub in slf_results) else "bad"
lf_result = AnalysisResultData(
name="LF",
value=lf,
Expand Down

0 comments on commit 1ba4a75

Please sign in to comment.