Qiskit: Difference between revisions
(→Theory) |
|||
(39 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
https://quantum-computing.ibm.com/jupyter/user/IBMQuantumChallenge2020/week-1/ex_1a_en.ipynb | https://quantum-computing.ibm.com/jupyter/user/IBMQuantumChallenge2020/week-1/ex_1a_en.ipynb | ||
=== Installation === | === Installation === | ||
Line 16: | Line 14: | ||
conda create -n qiskit python=3 | conda create -n qiskit python=3 | ||
conda activate qiskit | conda activate qiskit | ||
pip install qiskit _OR_ pip install qiskit[visualization] | pip install qiskit /////_OR_////// pip install qiskit[visualization] | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Did not work using Python 3.9. Instead, downgrade to Python 3.8.3 in your virtual environment. | |||
<syntaxhighlight> | |||
conda create -n qiskit python=3 | |||
conda activate qiskit | |||
conda install python=3.8.3 | |||
pip install qiskit ///////_OR_////// pip install qiskit[visualization] | |||
</syntaxhighlight> | |||
Set up the Spyder IDE https://stackoverflow.com/questions/30170468/how-to-run-spyder-in-virtual-environment#47615445 | |||
=== Setting Up Qiskit === | === Setting Up Qiskit === | ||
Line 24: | Line 33: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
from qiskit import QuantumCircuit, execute, Aer | |||
qc = QuantumCircuit(1) # Create a quantum circuit with one qubit | qc = QuantumCircuit(1) # Create a quantum circuit with one qubit | ||
initial_state = [0,1] # Define initial_state as |1> | initial_state = [0,1] # Define initial_state as |1> | ||
qc.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit | qc.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit | ||
qc.draw('text') # Let's view our circuit (text drawing is required for the 'Initialize' gate due to a known bug in qiskit) | qc.draw('text') # Let's view our circuit (text drawing is required for the 'Initialize' gate due to a known bug in qiskit) | ||
backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit | |||
result = execute(qc,backend).result() # Do the simulation, returning the result | result = execute(qc,backend).result() # Do the simulation, returning the result | ||
out_state = result.get_statevector() | out_state = result.get_statevector() | ||
Line 34: | Line 47: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
from qiskit.visualization import plot_histogram, plot_bloch_vector | |||
qc.measure_all() | qc.measure_all() | ||
qc.draw() | qc.draw() | ||
Line 55: | Line 70: | ||
Qiskit allows measuring in the Z-basis, only. | Qiskit allows measuring in the Z-basis, only. | ||
=== | == Theory == | ||
Quantum operations are reversible, thus the reversible computing. That makes some ''complications'' to the gate design. | |||
[https://www.cod3v.info/index.php?title=Quantum_Gates Quantum Gates ] | |||
Clifford Gates | |||
[[Grover's Algorithm]] | |||
[[qRAM]] | |||
== Exercises == | == Exercises == |
Latest revision as of 16:16, 27 November 2020
Introduction
https://quantum-computing.ibm.com/
https://quantum-computing.ibm.com/challenges/fall-2020
https://quantum-computing.ibm.com/jupyter/user/IBMQuantumChallenge2020/week-1/ex_1a_en.ipynb
Installation
Installation https://qiskit.org/documentation/install.html
conda create -n qiskit python=3
conda activate qiskit
pip install qiskit /////_OR_////// pip install qiskit[visualization]
Did not work using Python 3.9. Instead, downgrade to Python 3.8.3 in your virtual environment.
conda create -n qiskit python=3
conda activate qiskit
conda install python=3.8.3
pip install qiskit ///////_OR_////// pip install qiskit[visualization]
Set up the Spyder IDE https://stackoverflow.com/questions/30170468/how-to-run-spyder-in-virtual-environment#47615445
Setting Up Qiskit
https://qiskit.org/textbook/ch-states/representing-qubit-states.html
from qiskit import QuantumCircuit, execute, Aer
qc = QuantumCircuit(1) # Create a quantum circuit with one qubit
initial_state = [0,1] # Define initial_state as |1>
qc.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit
qc.draw('text') # Let's view our circuit (text drawing is required for the 'Initialize' gate due to a known bug in qiskit)
backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit
result = execute(qc,backend).result() # Do the simulation, returning the result
out_state = result.get_statevector()
print(out_state) # Display the output state vector
from qiskit.visualization import plot_histogram, plot_bloch_vector
qc.measure_all()
qc.draw()
result = execute(qc,backend).result()
counts = result.get_counts()
plot_histogram(counts)
Take superposition as initial state
initial_state = [1/sqrt(2), 1j/sqrt(2)] # Define state |q>
The Bloch Sphere
from qiskit_textbook.widgets import plot_bloch_vector_spherical
coords = [pi/2,0,1] # [Theta, Phi, Radius]
plot_bloch_vector_spherical(coords) # Bloch Vector with spherical coordinates
Qiskit allows measuring in the Z-basis, only.
Theory
Quantum operations are reversible, thus the reversible computing. That makes some complications to the gate design.
Clifford Gates
Exercises
Week 1
Week 2
Week 3