qiskit-community / qiskit-experiments

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

`ProcessTomography` analysis step errors #302

Closed samanthavbarron closed 3 years ago

samanthavbarron commented 3 years ago

Informations

MacOS Big Sur

qiskit-experiments: 0.1.0

qiskit-terra: 0.18.1
qiskit-aer: 0.8.2
qiskit-ignis: 0.6.0
qiskit-ibmq-provider: 0.16.0
qiskit-aqua: 0.9.4
qiskit: 0.29.0
qiskit-nature: None
qiskit-finance: None
qiskit-optimization: None
qiskit-machine-learning: None

What is the current behavior?

The analysis step of the process tomography experiment raises an error without completing.

Steps to reproduce the problem

The following script produces the error below.

from qiskit import QuantumCircuit
import qiskit_experiments
from qiskit_experiments.library import ProcessTomography
from qiskit_experiments.library.tomography.basis.pauli_basis import (
    Pauli6PreparationBasis,
    PauliMeasurementBasis,
    PauliPreparationBasis
)

from qiskit.providers.aer import AerSimulator
from qiskit.test.mock import FakeParis
from qiskit_experiments.framework import ExperimentData

backend = AerSimulator.from_backend(FakeParis())

circ = QuantumCircuit(1,1)
circ.x(0)

tomo = ProcessTomography(
    circuit=circ,
    measurement_basis=PauliMeasurementBasis(),
    measurement_qubits=None,
    preparation_basis=PauliMeasurementBasis(),
    preparation_qubits=None,
    basis_indices=None,
    qubits=None
)

print(f"There are {len(tomo.circuits())} circuits to run")

# This works
experiment = tomo.run(analysis=False, backend=backend).block_for_results()

# This doesn't
experiment = tomo.run(analysis=True, backend=backend).block_for_results()
Post processing function failed:
Traceback (most recent call last):
  File "/opt/miniconda3/envs/qiskit-stable/lib/python3.8/site-packages/qiskit_experiments/database_service/db_experiment_data.py", line 299, in _wait_for_job
    job_done_callback(self, **kwargs)
  File "/opt/miniconda3/envs/qiskit-stable/lib/python3.8/site-packages/qiskit_experiments/framework/base_experiment.py", line 192, in run_analysis
    analysis.run(experiment_data, **analysis_options)
  File "/opt/miniconda3/envs/qiskit-stable/lib/python3.8/site-packages/qiskit_experiments/framework/base_analysis.py", line 89, in run
    results, figures = self._run_analysis(experiment_data, **analysis_options)
  File "/opt/miniconda3/envs/qiskit-stable/lib/python3.8/site-packages/qiskit_experiments/library/tomography/tomography_analysis.py", line 93, in _run_analysis
    state, fitter_metadata = fitter(
  File "/opt/miniconda3/envs/qiskit-stable/lib/python3.8/site-packages/qiskit_experiments/library/tomography/fitters/lininv.py", line 96, in linear_inversion
    prep_dual_basis = dual_preparation_basis(preparation_basis)
  File "/opt/miniconda3/envs/qiskit-stable/lib/python3.8/site-packages/qiskit_experiments/library/tomography/fitters/lininv.py", line 126, in dual_preparation_basis
    return FitterPreparationBasis(fitter_utils.dual_states(basis._mats), name=f"Dual_{basis.name}")
AttributeError: 'PauliMeasurementBasis' object has no attribute '_mats'

What is the expected behavior?

The tomography experiment should run.

Suggested solutions

Not sure! I'm not familiar with the internals of qiskit-experiments yet.

chriseclectic commented 3 years ago

You are passing a measurement basis as a preparation basis which is the cause of this error. Doing

tomo = ProcessTomography(
    circuit=circ,
    measurement_basis=PauliMeasurementBasis(),
    measurement_qubits=None,
    preparation_basis=PauliPreparationBasis(),
    preparation_qubits=None,
    basis_indices=None,
    qubits=None
)

or just the following since you are using default args for everything

tomo = ProcessTomography(circuit=circ)

should work.

samanthavbarron commented 3 years ago

Oh, thanks! I guess I forgot to change the line when I copied it.