Important commands for Qiskit

H Hannan

Updated on:

important commands for Qiskit
Back to The Qiskit Home Page

Importing Qiskit:

Import the necessary modules to start working with Qiskit:

from qiskit import *

Creating Quantum Circuits:

Quantum circuits in Qiskit are built using the QuantumCircuit class. You can add gates to the circuit to create quantum operations.pythonCopy code

# Create a quantum circuit with 2 qubits circuit = QuantumCircuit(2)

# Add gates to the circuit circuit.h(0)

# Apply Hadamard gate to qubit 0 circuit.cx(0, 1)

# Apply CNOT gate from qubit 0 to qubit 1

Simulating Circuits:

You can use Qiskit’s built-in simulators to simulate the behaviour of your quantum circuits. Aer provides various backends for simulation.python

simulator = Aer.get_backend('qasm_simulator')

result = execute(circuit, simulator).result()

from qiskit.tools.visualization import plot_histogram

plot_histogram(result.get_counts(circuit))

The Aer simulator is not always installed with qiskit. To get around this, use pip install qiskit-aer in your terminal. It is also important after this to shut down your jupyter notebook and reload it.

The results of this code should look like this:

Find out more here.

Leave a Comment