I am new to qiskit and I have to simulate a quantum circuit. I read this documentation https://qiskit.org/textbook/ch-states/single-qubit-gates.html where it is left as an exercise to the reader to write a function to measure in the $|+i\rangle$ and $|-i\rangle$ or the y-basis. I want to know if I've done it correctly or not.

I need to measure a state in the y-basis after preparing it in an equal superposition the $|0\rangle$ and $|1\rangle$ states. To do this, I first applied the Hadamard gate which does the first part and takes the $|0\rangle$ state to the $|+\rangle$ state. Now comes the measurement part. To do this I applied an $S^\dagger$ and then the $H$ gate again.

Now I simply measure the state

def Y_measurement(qc,qubit,cbit):
    return qc

circuit = QuantumCircuit(1,1)

Y_measurement(circuit, 0, 0)


enter image description here

Is this correct?


1 Answer 1


Yes, your solution is correct.

Please find here circuits for measurement in z (computational), y (circular) and x (Hadamard) bases:

enter image description here

Source: Quantum Algorithm Implementations for Beginners, pg. 68.

Note that the blue Hadamard gate is used for preparing state $|+\rangle$ which is then measured. Pink gates are those needed for measuring in different basis. So, measurement in z basis needs no additional gate (left circuit), measuring in y basis needs $S^\dagger$ and $H$ additional gates (middle circuit) and measuring in x basis needs additional $H$ gate (right circuit).

  • 2
    $\begingroup$ The blue Hadamard gate is a part of the circuit because the question asked about the measurement of the $\vert+\rangle$ state in the Y-basis. The gates in pink are the ones that correspond to making the measurement - Just wanted to put this out there in case somebody looks at the first circuit and thinks it's performing a Hadamard basis measurement instead of a computational basis measurement. $\endgroup$
    – agiri
    Sep 7, 2020 at 5:34
  • 1
    $\begingroup$ @AdityaGiridharan: Thanks for your comment. Based on it, I made my answer clearer. $\endgroup$ Sep 7, 2020 at 6:46
  • $\begingroup$ Please can you share the post measurement values in each of the three cases? $\endgroup$
    – Kittu A
    Nov 26, 2021 at 18:48
  • 1
    $\begingroup$ @KittuA: In the first case, the probability of both $|0\rangle$ and $|1\rangle$ is 50% as Hadamard gate prepares state $\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)$. The second case is the same as the first case since $HS^\dagger|+\rangle =\frac{1}{2}(1 - i, 1 + i)^T$ and $[(1/2)|1-i|]^2=[(1/2)|1-i|]^2 = 0.5$ (you can verify this with direct calculation). In the third case, the resulting state is $|0\rangle$ with 100% probablity as $H^2 = I$. $\endgroup$ Nov 26, 2021 at 22:46

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