4
$\begingroup$

I am running the simplest Hadamard circuit possible - one qubit, initialised to 0, apply H gate, measure in Z basis. When I run the circuit on the simulator I obtain the expected result (50% in 0, 50% in 1) but the "measurement probability" and "state vector" from the IBM Circuit Composer indicate I am in the state $|0\rangle$, with 100% probability to measure 0. Am I understanding this visualisation wrong? Why don't I see the 50%/50% measurement probabilities and the state vector to be $(\frac{1}{\sqrt{2}})(|0\rangle + |1\rangle)$? enter image description here

$\endgroup$
3
$\begingroup$

Just to a little bit expand answer provided by Zhaoyi Zhou.

First, try to put only reset gate and Hadamard gate on the qubit. In this case, you will see probability of measuring 0 and 1 equal to 50 % and state vector will be $\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)$. Note that you do not have to use reset gate as the qubit is initially in state $|0\rangle$.

Now, add the measurement gate. When you do so, the state collapses to 0 or 1 which is indicated by 100 % probability in the histogram.

Overall, the visualization shows state vector of the circuit only in case, there is no measurement gates.

$\endgroup$
2
$\begingroup$

You use the measurement operator, which means the state will collapse.

$\endgroup$
1
  • 1
    $\begingroup$ So with "measurement probability" they mean after the first measurement is made, where they have decided for me that "0" was measured. (Since with the circuit composer I never obtain 100% probability to measure "1" after the first measurement which should happen 50% of the time, using the H gate in the circuit). Why does the circuit composer seem to default to measuring "0"? This seems needlessly unintuitive to me, especially since when you run this circuit in the simulator they give you the result of the first measurement and not this second measurement after the collapse... $\endgroup$ – Catherine Jan 1 at 17:11
1
$\begingroup$

IBM Quantum Composer shows the measurement probability after the gate have been applied.

Hence, if you apply the Hadamard gate to the state $|0\rangle$

enter image description here

then you will see the probability as:

enter image description here

But now, if you add the measurement to the circuit, then Qiskit will collapse your state to either $|0\rangle$ or $|1\rangle$. Then the post measurement state will be either $|0\rangle$ or $|1\rangle$ with 100% probability. However, this doesn't seems to happen within the circuit composer. That is the state will always collapse to the state $|0\rangle$ by default. That is, the following circuit will always seem to collapse to the state $|0\rangle$ by default.

enter image description here

And if you reset the qubit after the measurement to the state $|0\rangle$ again then apply the Hadamard gate then measure, it will always collapse to the state $|1\rangle$ by default, interestingly.

enter image description here




For this reason, my proposal solution would just to run your circuit in Qiskit through the Jupyter notebook setting in QuantumLab environment and use the qasm_simulator. This will fix this issue. So you can compose your circuit in the Quantum Composer as normal, then just get the generated Qiskit code:

enter image description here

then you can run this Qiskit code in the Jupyter notebook within the QuantumLab for better visualization. You can do this simply by adding the code below additional to the code you got earlier.

from qiskit import BasicAer, execute
from qiskit.visualization import plot_histogram
%matplotlib inline
backend = BasicAer.get_backend('qasm_simulator')
job = execute(circuit, backend, shots = 1000)
plot_histogram(job.result().get_counts(), color='black', title="Result")

enter image description here

You could actually execute your circuit through the quantum composer and selectibmq_qasm_simulator as your backend but I think it is faster and more flexible if you just migrate your circuit to Qiskit code and execute it through the Jupyter notebook in quantum lab.

$\endgroup$
4
  • $\begingroup$ Thanks for the response... Interesting (strange?) that there are "default" measurement results...still seems counterintuitive to me (especially since, as you said, the default result changes - deterministically - between 0 and 1!) I'd be curious to here why this was programmed this way. In any case, thanks for the tip about just switching the backend on jupyter. $\endgroup$ – Catherine Jan 1 at 19:27
  • $\begingroup$ You can seed the randomness of the measurement by changing the value in the Simulator seed box, on the top bar. If you change this value, you will notice that you will have half of the times a 0, and half of the time a 1. The reason for that is because the simulator makes a single shot, so a you obtain a single result at the time. $\endgroup$ – luciano Jan 1 at 20:21
  • $\begingroup$ Ah ok, that makes sense, thanks! $\endgroup$ – Catherine Jan 4 at 12:17
  • $\begingroup$ In the IBMQ Composer, selecting the system ibmq_qasm_simlator seems to have the same funny behavior. $\endgroup$ – ZxJx Feb 24 at 15:46

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.