Interested in learning how to program quantum computers? Then check out our Qiskit textbook Introduction to Quantum Computing with Qiskit.
Introduction
In this tutorial we will explore how to implement the RY gate on IBM’s Quantum Computers with Qiskit.
The RY gate is a rotational gate that does a rotation around the Y-axis by a specified amount which is normally denoted by θ.
The operation of the RY gate can be described using the following matrix:
Using the matrix multiplication we can see how the RY gate operates on the qubits state. For our first example lets initialise the qubits state to |0〉and set θ to be π. This should flip the qubits state from |0〉to |1〉
The associated column vector for |0〉is:
Then multiply the column vector by the RY matrix:
Which has flipped the qubits state from |0〉to |1〉. If we instead initialise the qubit to |1〉and apply the RY gate:
Which has changed the qubits state from |1〉to -|0〉
Implementation
In Qiskit we can implement an RY gate very easily using the following function:
circuit.ry(pi,q[0])
Where pi is the rotation amount and q[0] is the qubit we want to apply the RY gate to.
Go to the code section for the full code example.
How to run the program
Copy and paste the code below in to a python file
Enter your API token in the IBMQ.enable_account('Insert API token here') part
Save and run
Code
from qiskit import QuantumRegister, ClassicalRegister from qiskit import QuantumCircuit, execute,IBMQ from qiskit.tools.monitor import job_monitor import numpy as np IBMQ.enable_account('ENTER API KEY HERE') provider = IBMQ.get_provider(hub='ibm-q') backend = provider.get_backend('ibmq_qasm_simulator') pi = np.pi q = QuantumRegister(1,'q') c = ClassicalRegister(1,'c') circuit = QuantumCircuit(q,c) circuit.ry(pi,q[0]) circuit.measure(q,c) print(circuit) job = execute(circuit, backend, shots=8192) job_monitor(job) counts = job.result().get_counts() print(counts)