2
$\begingroup$

When using the IBM Composer, in the bottom left of our screen we have access to two histograms. A theoretical probability histogram and a statevector amplitude histogram. I'm looking for ways to create these same visualizations outside of the Composer (So in the Lab or other Jupyter Notebook). I know that for an experimental probability histogram I can measure my qubits using an ideal simulator like the 'aer_simulator' and then use plot_histogram, but I have not found anything that would portray the statevector amplitude histogram.

I assume there is code to generate this, and I'm not asking for anything that has not been released or involves proprietary information, but for it to be a part of their constant visualization, I simply assumed there was code to generate it, but I cannot seem to find it! Thank you for your guidance!

To see which visualization I am referring to scroll down to the Statevector View section of this link.

$\endgroup$

1 Answer 1

0
$\begingroup$

In Qiskit, there are two easy ways to get the state vector of a quantum circuit.

The easiest is just

from qiskit.quantum_info import Statevector
Statevector(mycircuit)

This does not create a histogram of results, but actually keep track of the state vector.

You can also use a simulator, with I think is faster for larger programs.

def get_statevector(circuit):
    sim = Aer.get_backend('aer_simulator')
    circuit.save_statevector()
    result = execute(circuit, sim).result()
    return result.get_statevector()

The simulator keeps track and dumps the actual statevector, not a histogram.

$\endgroup$
1
  • $\begingroup$ This is what I ended up using in the end as an equivilent form. Thanks! @Frank Yellin $\endgroup$
    – PGibbon
    Commented Nov 7, 2022 at 11:47

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.