Skip to main content

qbraid-algorithms

CI PyPI version PyPI version License Discord

Python package for building, simulating, and benchmarking hybrid quantum-classical algorithms.

Installation

qbraid-algorithms requires Python 3.11 or greater, and can be installed with pip as follows:

pip install qbraid-algorithms

[!WARNING] This project is "pre-alpha", and is not yet stable or fully realized. Use with caution, as the API and functionality are subject to significant changes.

Install from source

You can also install from source by cloning this repository and running a pip install command in the root directory of the repository:

git clone https://github.com/qBraid/qbraid-algorithms.git
cd qbraid-algorithms
pip3 install .

Check version

You can view the version of qbraid-algorithms you have installed within a Python shell as follows:

import qbraid_algorithms

qbraid_algorithms.__version__

Key Features: Load algorithms as PyQASM modules and QASM files

qBraid Algorithms provides a collection of quantum algorithms that can be loaded as PyQASM modules, or you can generate .qasm files to use them as subroutines in your own circuits.

Loading Algorithms as PyQASM Modules

To load an algorithm as a PyQASM module, use the generate_program function from the qbraid_algorithms package, passing algorithm-specific parameters. For example, to load the Quantum Fourier Transform (QFT) algorithm:

from qbraid_algorithms import qft

qft_module = qft.generate_program(3) # Load QFT for 3 qubits

Now, you can perform operations with the PyQASM module, such as unrolling, and converting back to a QASM string:

qft_module.unroll()
qasm_str = pyqasm.dumps(qft_module)

Loading Algorithms as .qasm Files

In order to utilize algorithms as subroutines in your own circuits, use the save_to_qasm function for your desired algorithm. By passing algorithm-specific parameters, and optionally a desired output path, you can generate a .qasm file containing a subroutine for the paramterized circuit. For example, to generate a QFT subroutine for 4 qubits:

from qbraid_algorithms import qft, iqft
path = "path/to/output" # Specify your desired output path
qft.save_to_qasm(4) # Generate 4-qubit QFT in the current directory
iqft.save_to_qasm(4, path=path) # Generate 4-qubit IQFT in specified path

To utilize the generated subroutine in your own circuit, include the generated .qasm file, and call the subroutine on an qubit register of the size specified when generating the subroutine. For example, after running

qft.save_to_qasm(4)

you can append include "qft.qasm"; to your OpenQASM file, and call the subroutine. For example:

OPENQASM 3.0;
include "qft.qasm";

qubit[4] q;
bit[4] c;

qft(q);
measure q -> c;

CLI Usage

qBraid Algorithms includes a command-line interface (CLI) for generating quantum algorithm subroutines.

Installation

To use the CLI, install with CLI dependencies:

pip install "qbraid-algorithms[cli]"

Or install from source:

pip install -e ".[cli]"

Generate Subroutines

Generate quantum algorithm subroutines that can be included in other circuits:

# Generate QFT subroutine for 4 qubits
qbraid-algorithms generate qft --qubits 4

# Generate IQFT subroutine for 3 qubits with custom name and show the circuit
qbraid-algorithms generate iqft -q 3 -o my_iqft.qasm --gate-name my_iqft --show

# Generate Bernstein-Vazirani circuit for secret "101" and display it
qbraid-algorithms generate bernvaz --secret "101" --show

# Generate only the oracle for Bernstein-Vazirani
qbraid-algorithms generate bernvaz -s "1001" --oracle-only --show

# Generate QPE subroutine for 4 qubits with a custom unitary gate
qbraid-algorithms generate qpe --unitary-file my_gate.qasm --qubits 4

# Generate QPE with custom output and show the circuit
qbraid-algorithms generate qpe -u gate.qasm -q 3 -o my_qpe.qasm --show

Help

Get help for any command:

qbraid-algorithms --help
qbraid-algorithms generate --help
qbraid-algorithms generate qft --help
qbraid-algorithms generate iqft --help
qbraid-algorithms generate bernvaz --help
qbraid-algorithms generate qpe --help
qbraid-algorithms generate bernvaz --help

Examples

Complete Workflow

  1. Generate a QFT subroutine:

    qbraid-algorithms generate qft --qubits 3
    
  2. Generate a Bernstein-Vazirani oracle and view it:

    qbraid-algorithms generate bernvaz --secret "101" --oracle-only --show
    
  3. Generate an IQFT circuit with custom output:

    qbraid-algorithms generate iqft --qubits 4 --output my_iqft_4.qasm --show
    
  4. Generate a QPE subroutine for phase estimation:

    qbraid-algorithms generate qpe --unitary-file t_gate.qasm --qubits 3 --show
    

Community

We are actively looking for new contributors!

License

Apache-2.0 License

Metadata

Release files for qbraid-algorithms 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qbraid-algorithms 0.1.3
File Size Uploaded
qbraid_algorithms-0.1.3.tar.gz 247.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qbraid-algorithms 0.1.3
File Interpreter ABI Platform
qbraid_algorithms-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 338.0 kB

Release files / qbraid_algorithms-0.1.3.tar.gz

Download URL qbraid_algorithms-0.1.3.tar.gz
Size 247.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5c01a5a1403a9003e242298d2513d7fe8cea5341545fa616b9249d4d46d47893
BLAKE2b-256 checksum
How to use checksums
4d65a34969adc79f5d7e6836b71147d77209bf7646f682044d511e129e172a35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.

Transparency log

Release files / qbraid_algorithms-0.1.3-py3-none-any.whl

Download URL qbraid_algorithms-0.1.3-py3-none-any.whl
Size 90.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e08beef27fa6e097a4b4729ce3de21c79bf02c40faf3cb89ddc572f6548a855
BLAKE2b-256 checksum
How to use checksums
6aa4950023e8b69d680f7cfbf3720432a53d509113c4baefec5ee15d5cc6dbde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page