1
$\begingroup$

I have given this circuit:

enter image description here

The question goes as follows:

What is a code of the above circuit if the barrier is removed?

Now I have a code fragment, which is this:

qc = QuantumCircuit(1,1)
qc.h(0)
qc.t(0)
qc.t(0)
qc.sdg(0)
qc.h(0)
qc.measure(0,0)

Is my code right?

$\endgroup$
1

2 Answers 2

3
$\begingroup$

First, it holds $TT=T^2=S$. Then we have gate $S$ and its transpose conjugate $S^\dagger$ next to each other. These gates are inverse of each other (because the gates are unitary matrices), so we have an identity surrounded by two Hadamards. We can neglect the identity. Since it holds that Hadamard is inverse of itself, we came to $HH =I$.

Overall, once the barrier is removed, the circuit is complied as identity $I$ and only code you need is this:

qc = QuantumCircuit(1,1)
qc.id(0)
qc.measure(0,0)

This code can be followed of course by drawing the circuit, simulation, printing results etc. as shown in the other answer.

$\endgroup$
3
$\begingroup$

Here's the full code

First make sure you have all libraries installed, like qiskit, matplotlib, pylatexenc

from qiskit import QuantumCircuit
qc = QuantumCircuit(1,1)
qc.h(0)
qc.t(0)
qc.t(0)
qc.barrier()
qc.sdg(0)
qc.h(0)
qc.measure(0,0)
qc.draw('mpl')

If you don't want barrier, remove the qc.barrier() line.

TBH it is a poorly framed question. At first, the question asked that they wanted to recreate the circuit image, then it changed to "What goes above this code?". Now going as per the link in the comments, there are multiple correct answers for this, as explained in the second answer.

qc = QuantumCircuit(1,1)
qc.measure(0,0)
$\endgroup$
0

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.