1
$\begingroup$

I want to compare the theoretical output of a circuit measurement with the actual output from a real quantum computer. I can approximate the ideal output by running the circuit on a simulator. However when you're measuring a state in superposition, the results you get from a simulator are still nondeterministic, making them not ideal for comparison.

For instance, when measuring a single qubit in even superposition (the state $\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)$, the ideal result would be that you measure $|0\rangle$ with probability $0.5$ and $|1\rangle$ with probability $0.5$. However, when running on a simulator, you might naturally get $|0\rangle$ with probability $0.501$ and $|1\rangle$ with probability $0.499$:

enter image description here

In other words, knowing that the theoretical probability of obtaining state $|\phi\rangle$ when measuring a state $|\psi\rangle$ is $\langle\phi|\psi\rangle$, is there a function in Qiskit to calculate this value from a circuit or state, or to get the ideal probability distribution that I can compare my actual distribution against?

$\endgroup$
1
$\begingroup$

You can use the statevector_simulator to return the statevector of your system. From this statevector, you can see the theoretical probability of obtaining each possible state for your system. For example:

qc = QuantumCircuit(2)
qc.x(0)

sim = Aer.get_backend('statevector_simulator')

job = execute(qc, sim)

print(job.result().get_statevector(qc))

will print out [0.+0.j 1.+0.j 0.+0.j 0.+0.j]. Each element refers to a possible 2-qubit state. The 0th element would refer to state 00, the 1st refers to 01, the 2nd to 10, and the 3rd to 11.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks for the answer. Sure, I can do a bit of processing to find the probabilities this way - I was wondering if there was any faster way to do this. If not, I can do it this way. $\endgroup$ – Connor Howington Feb 7 at 19:48
1
$\begingroup$

You can use the probabilities snapshot. Enter a snapshot as a circuit instruction:

circuit.snapshot_probabilities(label, qubits)

Then after execution get the probabilities from the result, see the documentation of Result.data.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Note that this requires something like: ``` from qiskit.providers.aer.extensions.snapshot_probabilities import * ``` $\endgroup$ – Yael Ben-Haim Feb 10 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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