Source code for qiskit_experiments.library.tomography.mit_tomography_analysis
# This code is part of Qiskit.## (C) Copyright IBM 2023.## 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."""Readout error mitigated tomography analysis"""fromqiskit_experiments.frameworkimportCompositeAnalysisfromqiskit_experiments.library.characterizationimportLocalReadoutErrorAnalysisfrom.tomography_analysisimportTomographyAnalysisfrom.basis.pauli_basisimportPauliMeasurementBasis
[docs]classMitigatedTomographyAnalysis(CompositeAnalysis):"""Analysis for readout error mitigated tomography experiments. Analysis is performed as a :class:`.CompositeAnalysis` consisting of :class:`.LocalReadoutErrorAnalysis` to determine the local assignment matrices describing single qubit Z-basis readout errors, and then these matrices are used to automatically construct a noisy :class:`~.PauliMeasurementBasis` for use during tomographic fitting with the tomography analysis. """def__init__(self,roerror_analysis="default",tomography_analysis="default"):"""Initialize mitigated tomography analysis"""ifroerror_analysis=="default":roerror_analysis=LocalReadoutErrorAnalysis()iftomography_analysis=="default":tomography_analysis=TomographyAnalysis()super().__init__([roerror_analysis,tomography_analysis],flatten_results=True)@classmethoddef_default_options(cls):"""Default analysis options Analysis Options: fitter (str or Callable): The fitter function to use for reconstruction. This can be a string to select one of the built-in fitters, or a callable to supply a custom fitter function. See the `Fitter Functions` section for additional information. fitter_options (dict): Any addition kwarg options to be supplied to the fitter function. For documentation of available kwargs refer to the fitter function documentation. rescale_positive (bool): If True rescale the state returned by the fitter to be positive-semidefinite. See the `PSD Rescaling` section for additional information (Default: True). rescale_trace (bool): If True rescale the state returned by the fitter have either trace 1 for :class:`~qiskit.quantum_info.DensityMatrix`, or trace dim for :class:`~qiskit.quantum_info.Choi` matrices (Default: True). measurement_qubits (Sequence[int]): Optional, the physical qubits with tomographic measurements. If not specified will be set to ``[0, ..., N-1]`` for N-qubit tomographic measurements. preparation_qubits (Sequence[int]): Optional, the physical qubits with tomographic preparations. If not specified will be set to ``[0, ..., N-1]`` for N-qubit tomographic preparations. unmitigated_fit (bool): If True also run tomography fit without readout error mitigation and include both mitigated and unmitigated analysis results. If False only compute mitigated results (Default: False) target (Any): Optional, target object for fidelity comparison of the fit (Default: None). """# Override options to be tomography options minus basesoptions=super()._default_options()options.fitter="linear_inversion"options.fitter_options={}options.rescale_positive=Trueoptions.rescale_trace=Trueoptions.measurement_qubits=Noneoptions.preparation_qubits=Noneoptions.unmitigated_fit=Falseoptions.target=Nonereturnoptions
def_run_analysis(self,experiment_data):# Return list of experiment data containers for each component experiment# containing the marginalized data from the composite experimentroerror_analysis,tomo_analysis=self._analysesroerror_data,tomo_data=self._component_experiment_data(experiment_data)# Run readout error analysisroerror_analysis.run(roerror_data,replace_results=True).block_for_results()# Construct noisy measurement basismitigator=roerror_data.analysis_results("Local Readout Mitigator").value# Run mitigated tomography analysis with noisy mitigated basis# Tomo analysis instance is internally copied by setting option with run.tomo_analysis.run(tomo_data,replace_results=True,measurement_basis=PauliMeasurementBasis(mitigator=mitigator),extra={"mitigated":True},).block_for_results()# Combine results so that tomography results are ordered firstcombined_data=[tomo_data,roerror_data]# Run unmitigated tomography analysisifself.options.unmitigated_fit:nomit_data=tomo_analysis.run(tomo_data,replace_results=False,measurement_basis=PauliMeasurementBasis(),extra={"mitigated":False},).block_for_results()combined_data.append(nomit_data)ifself._flatten_results:returnself._combine_results(combined_data)return[],[]