Visualize the results
Qiskit provides many visualizations, including the function plot_histogram, to view your results.
plot_histogram(counts)
The probabilities (relative frequencies) of observing the |00? and |11? states are computed by taking the respective counts and dividing by the total number of shots.
Below is the implementation.
Python3
# python program to create a simple Quantum circuit % matplotlib inline from qiskit import QuantumCircuit, execute, Aer, IBMQ from qiskit.compiler import transpile, assemble from qiskit.tools.jupyter import * from qiskit.visualization import * # Loading your IBM Q account(s) provider = IBMQ.load_account() # Create a Quantum Circuit acting # on the q register circuit = QuantumCircuit( 2 , 2 ) # Add a H gate on qubit 0 circuit.h( 0 ) # Add a CX (CNOT) gate on control # qubit 0 and target qubit 1 circuit.cx( 0 , 1 ) # Map the quantum measurement to the # classical bits circuit.measure([ 0 , 1 ], [ 0 , 1 ]) # Use Aer's qasm_simulator simulator = Aer.get_backend( 'qasm_simulator' ) # Execute the circuit on the qasm # simulator job = execute(circuit, simulator, shots = 1000 ) # Grab results from the job result = job.result() # Return counts counts = result.get_counts(circuit) print ( "\nTotal count for 00 and 11 are:" ,counts) # Draw the circuit circuit.draw() |
Output:
Plot a histogram
Python3
# Plot a histogram plot_histogram(counts) |
Output:
Build a simple Quantum Circuit using IBM Qiskit in Python
Qiskit is an open source framework for quantum computing. It provides tools for creating and manipulating quantum programs and running them on prototype quantum devices on IBM Q Experience or on simulators on a local computer. Let’s see how we can create simple Quantum circuit and test it on a real Quantum computer or simulate in our computer locally. Python is a must prerequisite for understanding Quantum programs as Qiskit itself is developed using Python.
First and foremost part before entering into the subject is installation of Qiskit and Anaconda. Refer to the below articles for step by step guide for anaconda installation.
Installation
To install qiskit follow the below steps:
- Open Anaconda Prompt and type
pip install qiskit
- That’s it, this will install all necessary packages.
- Next, open Jupyter Notebook.
- Import qiskit using the following command.
import qiskit
To get access to IBM Quantum Systems:
- Create a free IBM Quantum Experience Account.
- Navigate to My Account.
- Click on Copy Token to copy the token to the clipboard(Token represents the API to access IBM Quantum devices).
- Run the following commands(Jupyter Notebook) to store your API token locally for later use in a configuration file called qiskitrc. Replace MY_API_TOKEN with the API token.
from qiskit import IBMQ IBMQ.save_account('MY_API_TOKEN')
Contact Us