TransWikia.com

Simple Hadamard Circuit gives incorrect results?

Quantum Computing Asked on March 3, 2021

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 $|0rangle$, 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}})(|0rangle + |1rangle)$?
enter image description here

3 Answers

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

Answered by Zhaoyi Zhou on March 3, 2021

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}}(|0rangle + |1rangle)$. Note that you do not have to use reset gate as the qubit is initially in state $|0rangle$.

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.

Answered by Martin Vesely on March 3, 2021

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

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

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 $|0rangle$ or $|1rangle$. Then the post measurement state will be either $|0rangle$ or $|1rangle$ with 100% probability. However, this doesn't seems to happen within the circuit composer. That is the state will always collapse to the state $|0rangle$ by default. That is, the following circuit will always seem to collapse to the state $|0rangle$ by default.

enter image description here

And if you reset the qubit after the measurement to the state $|0rangle$ again then apply the Hadamard gate then measure, it will always collapse to the state $|1rangle$ 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.

Answered by KAJ226 on March 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP