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?


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).

| improve this answer | |
  • 1
    $\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$ – Aditya Giridharan Sep 7 at 5:34
  • 1
    $\begingroup$ @AdityaGiridharan: Thanks for your comment. Based on it, I made my answer clearer. $\endgroup$ – Martin Vesely Sep 7 at 6: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.