Cqlib is a high-performance quantum computing SDK that provides a unified foundation for building, optimizing, and executing quantum programs. Its core is written in Rust for maximum safety and speed, with first-class language bindings for Python 3.10+ and C 11+.
Designed from the ground up for both research and production use, Cqlib covers the full quantum computing workflow: from circuit construction and parameterization, through multi-level IR transformations, rule-based compilation and optimization passes, to realistic device simulation with built-in noise models and error mitigation techniques such as Zero-Noise Extrapolation (ZNE) and Virtual Distillation. Its module design allows you to use individual components independently or compose them into a complete pipeline, making it equally suitable for quantum algorithm prototyping, education, and integration into larger software stacks.
Learn more at qc.zdxlz.com/cqlib.
Read the Whitepaper — Cqlib's design philosophy, architecture, and technical details in one document.
- Circuit Construction — Intuitive APIs to build, compose, and parameterize quantum circuits
- Intermediate Representation (IR) — A principled IR for quantum programs enabling multi-level optimization
- Compiler Passes — Gate decomposition, layout mapping, routing, and scheduling
- Device Abstraction — Realistic device models with calibration data, noise models, and topology
- Error Mitigation — Built-in support for Zero-Noise Extrapolation (ZNE) and Virtual Distillation
- Visualization — Rich circuit diagrams and result plots (SVG/text)
- Multi-language Support — Native Rust, Python (PyO3), and C (cbindgen) interfaces
pip install cqlib# Bell state circuit
from cqlib import Circuit
qc = Circuit(2)
qc.h(0)
qc.cx(0, 1)
# Inspect the circuit
print(qc.num_qubits) # 2
print(len(qc.operations)) # 2
# Get the unitary matrix
matrix = qc.to_matrix() # 4x4 numpy complex128 ndarrayParameterized circuit:
from cqlib import Circuit, Parameter
theta = Parameter("theta")
qc = Circuit(2)
qc.rx(0, theta)
qc.ry(1, theta)
qc.cx(0, 1)
# Bind symbols to numeric values
bound = qc.assign_parameters({"theta": 0.5})[dependencies]
cqlib-core = "0.1"use cqlib_core::circuit::{Circuit, Qubit};
// Bell state circuit
let mut qc = Circuit::new(2);
qc.h(Qubit::new(0)).unwrap();
qc.cx(Qubit::new(0), Qubit::new(1)).unwrap();
assert_eq!(qc.num_qubits(), 2);
assert_eq!(qc.operations().len(), 2);Parameterized circuit:
use cqlib_core::circuit::{Circuit, Qubit, Parameter};
use std::collections::HashMap;
let theta = Parameter::symbol("θ");
let mut qc = Circuit::new(2);
qc.rx(Qubit::new(0), theta.clone()).unwrap();
qc.ry(Qubit::new(1), theta).unwrap();
qc.cx(Qubit::new(0), Qubit::new(1)).unwrap();
// Bind parameters
let mut bindings = HashMap::new();
bindings.insert("θ", std::f64::consts::PI);
let evaluated = qc.assign_parameters( & Some(bindings)).unwrap();#include <cqlib_c.h>
int main(void) {
// Create a 2-qubit Bell state circuit
CCircuit *qc = circuit_new(2);
circuit_h(qc, 0);
circuit_cx(qc, 0, 1);
// Inspect
size_t ops = (size_t)circuit_num_operations(qc); // 2
circuit_free(qc);
return 0;
}| Language | Minimum Version | Binding Technology |
|---|---|---|
| Rust | 1.89 | Native |
| Python | 3.10 | PyO3 (abi3-py310) |
| C | 11 | cbindgen |
Prerequisites: Rust 1.89+, Python 3.10+ (for Python bindings)
git clone https://gitee.com/cq-lib/cqlib.git
cd cqlib
# Build core library
cargo build --release -p cqlib-core
# Build Python bindings
pip install maturin
maturin develop --release -m crates/binding-python/Cargo.toml
# Build C bindings
cargo build --release -p binding-cTip: when linking with MinGW gcc, build with
cargo build --release -p binding-c --target x86_64-pc-windows-gnuinstead. See crates/binding-c/README.md.
Run the test suite:
cargo test --all
pytest crates/binding-python/tests/| Resource | Link |
|---|---|
| API Reference (Rust) | docs.rs/cqlib-core |
| API Reference (Python) | qc.zdxlz.com/docs |
| API Reference (C) | docs/api/en/c/0_overview.md |
| Source Repository (Gitee) | gitee.com/cq-lib/cqlib |
| Source Repository (GitHub) | github.com/cq-lib/cqlib |
Contributions are welcome. Please read the Contributing Guide before submitting changes. All participants are expected to follow the Code of Conduct. If you need to report a security issue, please follow the Security Policy.
Please use the repository issue tracker for discussion. When contributing, open a pull request against the main branch
and ensure all relevant tests pass.
Cqlib is licensed under the Apache License, Version 2.0.