Skip to content

General-purpose SDKs

qcircuits

Maintained by grey-area

QCircuits is a Python package for the simulation and study of quantum computers based on the quantum circuit model <https://en.wikipedia.org/wiki/Quantum_circuit>_.

PythonMIT
qcircuits illustration

Resource snapshot

Category

General-purpose SDKs

Stars

59

Last pushed

Jul 8, 2022Updated 4y ago

Open issues

3

What it is

qcircuits is maintained by grey-area and sits in the General-purpose SDKs lane of the open-source quantum map.

QCircuits is a Python package for the simulation and study of quantum computers based on the quantum circuit model <https://en.wikipedia.org/wiki/Quantum_circuit>_.

Last verified by Qtangl generator on May 27, 2026

Who it's for

Developers who want a broad entry point for building circuits, experimenting with algorithms, and integrating quantum workflows into larger applications.

What you can build or learn

  • Prototype end-to-end circuit workflows without committing to a niche backend too early.
  • Learn how the project represents circuits, gates, jobs, and results.
  • Compare how a major ecosystem frames practical quantum development.

Code samples

Examples from the repository.

Deutsch Algorithm (examples/deutsch_algorithm.py)
import qcircuits as qc
import numpy as np
# Deutsch's Algorithhm:
# We use interference to determine if f(0) = f(1) using a single function evaluation.
# Construct a Boolean function that is constant or balanced
def construct_problem():
    answers = np.random.randint(0, 2, size=2)
    def f(bit):
        return answers[bit]
    return f
def deutsch_algorithm(f):
    U_f = qc.U_f(f, d=2)
    H = qc.Hadamard()
    phi = H(qc.zeros()) * H(qc.ones())
    phi = U_f(phi)
    phi = H(phi, qubit_indices=[0])
    measurement = phi.measure(qubit_indices=0)
    return measurement
if __name__ == '__main__':
    f = construct_problem()
    parity = f(0) == f(1)
    measurement = deutsch_algorithm(f)
    print('f(0): {}, f(1): {}'.format(f(0), f(1)))
    print('f(0) == f(1): {}'.format(parity))
    print('Measurement: {}'.format(measurement))
Deutsch Jozsa Algorithm (examples/deutsch_jozsa_algorithm.py)
import qcircuits as qc
import numpy as np
import random
# Deutsch-Jozsa Algorithhm:
# We are presented with a Boolean function that is either constant or
# balanced (i.e., 0 for half of inputs, 1 for the other half).
# We make use of interference to determine whether the function is constant
# or balanced in a single function evaluation.
# Construct a Boolean function that is constant or balanced
def construct_problem(d=1, problem_type='constant'):
    num_inputs = 2**d
    answers = np.zeros(num_inputs, dtype=np.int32)
    if problem_type == 'constant':
        answers[:] = int(np.random.random() < 0.5)
    else: # function is balanced
        indices = np.random.choice(num_inputs, size=num_inputs//2, replace=False)
        answers[indices] = 1
    def f(*bits):
        index = sum(v * 2**i for i, v in enumerate(bits))
        return answers[index]
    return f
def deutsch_jozsa_algorithm(d, f):
    # The operators we will need
    U_f = qc.U_f(f, d=d+1)
    H_d = qc.Hadamard(d)
    H = qc.Hadamard()
    state = qc.zeros(d) * qc.ones(1)
    state = (H_d * H)(state)
    state = U_f(state)
    state = H_d(state, qubit_indices=range(d))
    measurements = state.measure(qubit_indices=range(d))
    return measurements
if __name__ == '__main__':
    d = 10
    problem_type = random.choice(['constant', 'balanced'])
    f = construct_problem(d, problem_type)
    measurements = deutsch_jozsa_algorithm(d, f)
    print('Problem type: {}'.format(problem_type))
    print('Measurement: {}'.format(measurements))
    print('Observed all zeros: {}'.format(not any(measurements)))
Grover Algorithm (examples/grover_algorithm.py)
import qcircuits as qc
import numpy as np
import random
# Grover's algorithm (search)
# Given a boolean function f, Grover's algorithm finds an x such that
# f(x) = 1.
# If there are N values of x, and M possible solutions, it requires
# O(sqrt(N/M)) time.
# Here, we construct a search problem with 1 solution amongst 1024
# possible answers, and find the solution with 25 applications of
# the Grover iteration operator.
# Construct a Boolean function that is 1 in exactly one place
def construct_problem(d=10):
    num_inputs = 2**d
    answers = np.zeros(num_inputs, dtype=np.int32)
    answers[np.random.randint(0, num_inputs)] = 1
    def f(*bits):
        index = sum(v * 2**i for i, v in enumerate(bits))
        return answers[index]
    return f
def grover_algorithm(d, f):
    # The operators we will need
    Oracle = qc.U_f(f, d=d+1)
    H_d = qc.Hadamard(d)
    H = qc.Hadamard()
    N = 2**d
    zero_projector = np.zeros((N, N))
    zero_projector[0, 0] = 1
    Inversion = H_d((2 * qc.Operator.from_matrix(zero_projector) - qc.Identity(d))(H_d))
    Grover = Inversion(Oracle, qubit_indices=range(d))
    # Initial state
    state = qc.zeros(d) * qc.ones(1)
    state = (H_d * H)(state)
    # Number of Grover iterations
    angle_to_rotate = np.arccos(np.sqrt(1 / N))
    rotation_angle = 2 * np.arcsin(np.sqrt(1 / N))
    iterations = int(round(angle_to_rotate / rotation_angle))
    for i in range(iterations):
        state = Grover(state)
    measurements = state.measure(qubit_indices=range(d))

License

MIT

SPDX identifier detected from the repository metadata or license files.

Repository README

Preview from the project README.

Rendered as Markdown inside a scrollable preview. Long READMEs stay contained; expand or open on GitHub for the full document.

~265 words · about 1 min readOpen on GitHub

========= QCircuits

Full documentation at www.awebb.info/qcircuits/index.html <http://www.awebb.info/qcircuits/index.html>_.

.. inclusion-marker0-do-not-remove

QCircuits is a Python package for the simulation and study of quantum computers based on the quantum circuit model <https://en.wikipedia.org/wiki/Quantum_circuit>_. It has been designed to have a simple, lightweight interface and to be easy to use, particularly for those new to quantum computing.

.. inclusion-marker1-do-not-remove

Installation

Install with pip:

pip install qcircuits

.. inclusion-marker15-do-not-remove

or from the source available here.

.. inclusion-marker16-do-not-remove

Example usage: quantum teleportation

.. inclusion-marker2-do-not-remove

Quantum circuit:

.. image:: http://www.awebb.info/qcircuits/_images/teleport.png :scale: 40%

Code::

import qcircuits as qc

# Instantiating the operators we will need
CNOT = qc.CNOT()
H = qc.Hadamard()
X = qc.PauliX()
Z = qc.PauliZ()

# Alice's hidden state, that she wishes to transport to Bob.
alice = qc.qubit(theta=1, phi=1, global_phase=0.2)

# A previously prepared Bell state, with one qubit owned by
# alice, and another by Bob, now physically separated.
bell_state = qc.bell_state(0, 0)

# The state vector for the whole system.
phi = alice * bell_state

# Alice applies a CNOT gate to her two qubit, and then
# a Hadamard gate to her private qubit.
phi = CNOT(phi, qubit_indices=[0, 1])
phi = H(phi, qubit_indices=[0])

# Alice measures the first two bits, and transmits the classical
# bits to Bob.
# The only uncollapsed part of the state vector is Bob's.
M1, M2 = phi.measure(qubit_indices=[0, 1], remove=True)

# Apply X and/or Z gates to third qubit depending on measurements
if M2:
    print('First bit 1, applying X\n')
    phi = X(phi)
if M1:
    print('Second bit 1, applying Z\n')
    phi = Z(phi)

print('Original state:', alice)
print('\nTeleported state:', phi)

.. inclusion-marker3-do-not-remove

Read on GitHub

Activity

Latest release

—

Watchers

2

Python support

—

Learn digest

Get monthly updates when library entries change.

Monthly digest: new library entries, updated flagships, and one editorial pick.

Related resources

Keep exploring nearby tools.

quantumlib

Cirq

Python framework for creating, editing, and running Noisy Intermediate-Scale Quantum (NISQ) circuits.

PythonApache-2.0Flagship

4,971 stars · Updated 3mo ago

XanaduAI

pennylane

PennyLane is an open-source quantum software platform for quantum computing, quantum machine learning, and quantum chemistry.

PythonApache-2.0FlagshipQtangl relevant

3,229 stars · Updated 3mo ago

QISKit

qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

PythonApache-2.0FlagshipQtangl relevant

7,412 stars · Updated 3mo ago

Qiskit

qiskit-terra

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

PythonApache-2.0

7,412 stars · Updated 3mo ago

Microsoft

QuantumKatas

Tutorials and programming exercises for learning Q# and quantum computing

Jupyter NotebookMITFlagshipArchive

4,862 stars · Updated 2y ago

QuantumBFS

Yao.jl

Extensible, Efficient Quantum Algorithm Design for Humans.

JuliaApache-2.0Flagship

1,032 stars · Updated 3mo ago