qiskit-community / qiskit-experiments

Qiskit Experiments
https://qiskit-community.github.io/qiskit-experiments/
Apache License 2.0
159 stars 126 forks source link

Jobs retrieved from hardware do not write "physical_qubits" metadata, causing MitigatedTomographyAnalysis to fail #1435

Closed z3461488 closed 6 months ago

z3461488 commented 7 months ago

Information

What is the current behavior?

MitigatedTomographyAnalysis fails because LocalReadoutErrorAnalysis fails. This is in turn because the "physical_qubits" entry isn't written into the metadata of jobs retrieved from the backend.

Steps to reproduce the problem

I create a MitigatedStateTomography experiment and send it to run on the hardware. After a few hours, I come back and retrieve the hardware job. I then run the following three lines of code to perform the experiment analysis:

image

I get an error saying that the Local Readout Mitigator wasn't found, and an earlier error about a missing key in the metadata dictionary "physical_qubits". Passing in physical_qubits as an argument in the experiment before sending it to the hardware doesn't fix this issue.

What is the expected behavior?

The expected behaviour is that the "physical qubits" data should be written to the experiment result. However this appears not be the case. image

Suggested solutions

Workaround

Basically, go to the source code and reproduce the method line-by-line: https://github.com/Qiskit-Extensions/qiskit-experiments/blob/cf6222de654d227f9aac20e3b13aa7d87f8c36c3/qiskit_experiments/library/tomography/mit_tomography_analysis.py#L92

image

Here you'll find that the data from the backend doesn't say which physical qubits are used in the circuits. So to fix, overwrite this data manually:

image

Now you get no errors and can run the analysis.

image

Suggested Fix

Experiments sent to the hardware should record the physical qubits into the experiment results. Or, at least they should be able to infer them from the circuits.

coruscating commented 7 months ago

To run analysis separately from the initial experiment.run(), you need to instantiate ExperimentData with a copy of the original experiment object, as seen at https://qiskit-extensions.github.io/qiskit-experiments/howtos/rerun_analysis.html, otherwise it won't have the metadata needed to complete the analysis. This was an intentional design choice to use experiment metadata whenever possible and save only absolutely necessary metadata in jobs to reduce payload sizes. Please try the code provided in the how-to guide and report back if it doesn't work.

z3461488 commented 6 months ago

Confirmed. Recreating the experiment data object and adding its metadata to hardware retrieved jobs fixes the issue.