1
$\begingroup$

I would like to use the analysis capabilities of qiskit, i.e. StateTomographyAnalysis of qiskit_experiments on data that were previously measured on a system not using Qiskit.

So what I have is a quantum state with an unknown state preparation (I know the goal, but not what actually happened) and can therefore not model a circuit to prepare the state.

After receiving that state, I measured, using different rotations, to get a measurement in all Pauli bases.

So the circuits would look like this:

cZ = QuantumCircuit(1)
# unknown part here
cZ.save_statevector()
cZ.measure_all()

cX = QuantumCircuit(1)
# unknown part here
cX.save_statevector()
cX.ry(-np.pi/2,0)
cX.measure_all()

cY = QuantumCircuit(1)
# unknown part here
cY.save_statevector()
cY.rx(np.pi/2,0)
cY.measure_all()

The 'unknown part' is the same in all circuits, the save_statevector() is where I would like to reconstruct the density matrix.

Now these circuits were actually measured on a real quantum computer that does not use qiskit and all i am left with is the final data, like this:

Shots: 1k

Basis 0 1
$\sigma_Z$ 0.49 0.51
$\sigma_X$ 0.98 0.02
$\sigma_Y$ 0.51 0.49

On these sample data I can immediately see that this must be close to $|+\rangle$, the real world example is a bit more complicated (and involves 2 qubits).

I would like to use the StateTomographyAnalysis to fit a density matrix to the given results and further process the data, and tried this approach:

from qiskit_experiments.library.tomography import StateTomographyAnalysis
from qiskit_experiments.framework.experiment_data import ExperimentData

outcomes = {
    'X': {'0':0.98, '1':0.02},
    'Y': {'0':0.51, '1':0.49},
    'Z': {'0':0.49, '1':0.51},
}

exData = ExperimentData().add_data(outcomes)

tomo = StateTomographyAnalysis().run(exData)

This gives an error about 'NoneType' object has no attribute '_created_in_db', but also found the documentation hard to understand.

How could I do this? I guess adding the data to an ExperimentData object is not as simple as I tried it....

I'm using qiskit-experiments-0.5.1.

$\endgroup$

1 Answer 1

0
$\begingroup$

Took me a while to figure out:

from qiskit.result import Result
from qiskit import QuantumCircuit
from qiskit_experiments.framework import ExperimentData
from qiskit_experiments.library import StateTomography
from qiskit_experiments.library.tomography import StateTomographyAnalysis

# counts like {'0x1': 225, '0x0': 280, '0x2': 249, '0x3': 270}
# m_idx is list of pauli basis indices, e.g. [0,1] for ZX
def getSingleResDict(shots, counts, bits, m_idx):
    return {
        'shots': shots,
        'success': True,
        'data': {'counts': counts},
        'header': {
            'creg_sizes': [['c_tomo', bits]],
            'memory_slots': bits,
            'metadata': {'clbits': list(range(bits)), 'cond_clbits': None, 'm_idx': m_idx}
        },
    }

def getResDict(results):
    return {
        'backend_name': '',
        'backend_version': '',
        'qobj_id': '',
        'job_id': '',
        'success': True,
        'results': results
        }

dct = getResDict(
    [
        getSingleResDict(
            100,
            {'0x0':49, '0x1':51},
            1,
            [0]
            ),
        getSingleResDict(
            100,
            {'0x0':98, '0x1':2},
            1,
            [1]
            ),
        getSingleResDict(
            100,
            {'0x0':51, '0x1':49},
            1,
            [2]
            ),
    ]
)

result = Result.from_dict(dct)

circ = QuantumCircuit(1)

# QST Experiment
tomo = StateTomography(circ)
exdata = ExperimentData(tomo)
exdata.add_data(result)
StateTomographyAnalysis().run(exdata)
exdata.analysis_results()

Versions used:

  • Python 3.11
  • qiskit 0.44.0
  • qiskit-experiments 0.5.1
  • qiskit-aer 0.13.1 (probably not relevant)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.