1
$\begingroup$

quite new to quantum computing and I have to do a small presentation on quantum gates using python code(notebook).Also, please review the small code I have written for its correctness. I have some questions also as below:

import matplotlib.pyplot as plt
import numpy as np
from math import pi
from qiskit.quantum_info import Statevector
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, transpile
from qiskit.tools.visualization import circuit_drawer
from qiskit.quantum_info import state_fidelity
from qiskit import BasicAer
from qiskit.visualization import plot_bloch_multivector

backend = BasicAer.get_backend('unitary_simulator')
qc = QuantumCircuit(q)
qc.u(pi/2,pi/4,pi/8,q)            
qc.draw(output='mpl')

enter image description here

U gate has a lambda argument. What does it mean by lambda and what effect it have on the bloch sphere?

state = Statevector(qc)
plot_bloch_multivector(state) # argument is a statevector

What is this Statevector function? I am not getting it at all. Also, is the bloch sphere showing the effect different angles applied to the gate and state achieved due to effect of lambda, theta and phi? How to know the effect of lambda?

enter image description here

transpiled_circuit= transpile(qc, backend)
transpiled_circuit.draw(output= "mpl")

enter image description here What is the effect of transpile function? Does it break the gate into its individual components? Not able to understand its effect?

job = backend.run(transpiled_circuit)
job.result().get_unitary(qc, decimals=3)

enter image description here

What is the function of run? Also, what is the get_unitary giving? Is this get_unitary same as statevector(discussed above)?

Now, I donot know where to put the measure, execute and how to see the histogram and the counts? Also, in this example, I am using "unitary simulator". Is this simulator same as qasm simulator? Thank you in advance for resolving me doubts.

$\endgroup$
1
  • $\begingroup$ Hi and welcome to Quantum Computing SE. In the future, please ask only one question per post. The question should be precisely focused on one problem to allow other to orient easily and also allow search machines return relevant results. Thank you for understanding. $\endgroup$ Sep 23, 2022 at 6:01

1 Answer 1

1
$\begingroup$

So many questions in your question! Not sure I'll be able to answer them all, but I'll hopefully get you started!

1)U gate has a lambda argument. What does it mean by lambda and what effect it have on the bloch sphere? This is a link to the documentation for the gate that you used. From this I can see that the their u gate is the universal gate that uses three sequential rotations (Rz,Ry and Rz) to to change the state. The lamda you are referring to is that final rotation around z. For additional information on the u gate, see this SE post.

2)What is this Statevector function? I am not getting it at all. Also, is the bloch sphere showing the effect different angles applied to the gate and state achieved due to effect of lambda, theta and phi? How to know the effect of lambda? Yes, your Bloch vector should show the resulting state after putting your state, $|0\rangle$, through the u gate with your given rotation angles of $\pi/2$, $\pi/4$, and $\pi/8$. The $\theta$ relates to the rotation around y axis, the $\phi$ and $\lambda$ are around the z axis

As for the statevector function, what it does was it took the output of your circuit and converted it into a statevector which you have then displayed on the Bloch Sphere. You could also display it in Dirac notation using state.draw() in another cell.

3)What is the effect of transpile function? Does it break the gate into its individual components? Not able to understand its effect? Transpile is a function that is used to convert the circuit you have built, to one readable by actual quantum computers at IBMQ. Every time a complex circuit is transpiled it may be done slightly differently. This is not an effect you tend to see, but if you get to the point where you are worried about circuit depth, then the different transpile results become important.

4)What is the function of run? Also, what is the get_unitary giving? Is this get_unitary same as statevector(discussed above)? .run tells the backend to actually run the circuit rather than just looking at it. (You are no longer building it, you want to run it to see the result) Find more information on .run here

get_unitary will output the matrix that evolved your statevector. Click here for the documentation.

5)Now, I do not know where to put the measure, execute and how to see the histogram and the counts? Also, in this example, I am using "unitary simulator". Is this simulator same as qasm simulator? Thank you in advance for resolving me doubts. Measure will go at the end of your circuit. You then use .execute the same way you used .run only you will execute your circuit on a different backend, as the unitary simulator is used for generating unitaries, while the qasm_simulator can simulate the measurement. After you have executed your function you will need to get_counts`` in order to plot_histogram``` I'm deliberately not showing you what this code would look like in full, because I beleive that is probably a part of the assignment, but I will say that if you look at this Qiskit tutorial page, you should be able to find some examples that may help you.

Best of luck!

$\endgroup$
5
  • $\begingroup$ Thank you @PGibbon for this great answer. I feel theta and phi are somewhat similar to what i studied in Electromagnetics, but still not sure what is lambda? $\endgroup$ Sep 23, 2022 at 4:57
  • 1
    $\begingroup$ @ManuChaudhary you can refer to [link](quantumcomputing.stackexchange.com/questions/9668/… ) for the use of lambda argument $\endgroup$
    – qubitybit
    Sep 23, 2022 at 5:20
  • $\begingroup$ @qubitybit Thanks for finding this link that explains the u gate! I'll add it to the answer. $\endgroup$
    – PGibbon
    Sep 23, 2022 at 12:14
  • $\begingroup$ Thank you @qubitybit for great help. $\endgroup$ Sep 23, 2022 at 16:46
  • $\begingroup$ Thank you @PGibbon for great help. $\endgroup$ Sep 23, 2022 at 16:46

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.