Qiskit: Difference between revisions
From wikiluntti
Line 69: | Line 69: | ||
qc = QuantumCircuit(1) | qc = QuantumCircuit(1) | ||
qc.x(0) | qc.x(0) | ||
#qc.y(0) # Y-gate on qubit 0 | |||
#qc.z(0) # Z-gate on qubit 0 | |||
qc.draw('mpl') | qc.draw('mpl') | ||
# Let's see the result | # Let's see the result |
Revision as of 11:51, 21 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
Theory
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]
Setting Up Qiskit
https://qiskit.org/textbook/ch-states/representing-qubit-states.html
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)
result = execute(qc,backend).result() # Do the simulation, returning the result
out_state = result.get_statevector()
print(out_state) # Display the output state 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
Quantum Gates
Pauli X gate.
Pauli Y gate
Pauli Z gate
qc = QuantumCircuit(1)
qc.x(0)
#qc.y(0) # Y-gate on qubit 0
#qc.z(0) # Z-gate on qubit 0
qc.draw('mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
plot_bloch_multivector(out)
Exercises
Week 1
Week 2
Week 3