Skip to main content

LazyQC logo

LazyQC

CI License Python 3.12+ PyPI GitHub stars

LazyQC is a Python framework for lazy, observable-driven quantum simulation (v0.3.0). You describe programs and request expectation values first; LazyQC plans the batch (observable cones, shared preparations, ZX rewrites, and exact CX cuts under memory limits) and only runs the native Qulacs simulation when you call collect().

Installation

Requires Python 3.12 or newer. With uv:

uv add lazyqc

Optional extras: zx (PyZX rewrites), cutting (exact CX cuts, Qiskit frontend), tensor and mqt (alternative backends for benchmarking).

PennyLane device

With pip install "lazyqc[pennylane]", any QNode can run on LazyQC:

import pennylane as qml

dev = qml.device("lazyqc.qubit", wires=4)

@qml.qnode(dev, diff_method="best")  # device derivatives skip parameters outside every cone
def f(w):
    qml.RX(w[0], wires=0)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.Z(1))

dev.last_stats["skipped_structural_zeros"] reports shifted terms skipped after a gradient call.

Gradients with PennyLane

For bound symbolic parameters, adjoint_gradient computes a weighted scalar-loss gradient with Qulacs backpropagation inside each observable's causal cone. Observables with the same cone share a backpropagation:

import pennylane as qml
from lazyqc import Parameter, Program, adjoint_gradient

dev = qml.device("lazyqc.qubit", wires=2)

@qml.qnode(dev, diff_method="best")  # device derivatives skip parameters outside every cone
def circuit(w):
    qml.RX(w[0], wires=0)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.Z(0))

Alternatively, using the native LazyQC gradient function:

from lazyqc import Parameter, Program, adjoint_gradient

theta = Parameter("theta")
program = Program(2).ry(0, theta).cx(0, 1).rz(1, theta).bind(theta=0.4)
gradient = adjoint_gradient(program, [{0: "Z"}, {1: "X"}], [0.7, -0.2])
print(gradient["theta"])

profile_sensitivity(..., method="adjoint") computes occurrence-wise derivatives; method="auto" selects shifts or adjoint independently for each observable cone.

Quick start

from lazyqc import Program, plan_all

program = Program(4).ry(0, 0.4).cx(0, 1).ry(2, 0.8).cx(2, 3)
requests = [
    program.expectation({0: "Z"}),
    program.expectation({0: "X", 1: "X"}),
    program.expectation({2: "Z", 3: "Z"}),
]

plan = plan_all(requests, strategy="auto")  # classical planning only
print(plan.explain())
print(plan.collect().values)  # native simulation happens here

Gate set

H, X, Y, Z, RX, RY, RZ, CX, CZ and RZZ (program.cz(a, b), program.rzz(a, b, angle) with RZZ(theta) = exp(-i theta Z Z / 2)). The Qiskit and PennyLane frontends keep CZ and RZZ (IsingZZ) as single gates instead of expanding them into H, CX, H and CX, RZ, CX, which halves the gate count of QAOA-style circuits. RZZ uses the same two-term shift rule as the single-qubit rotations. Circuit cutting still cuts CX only. See examples/07_qaoa_native_gates.py for a native against translated comparison.

Weighted sums of Pauli terms

A Hamiltonian is a list of (coefficient, term) pairs. LazyQC plans the terms together, so terms whose cones coincide share one simulation, and returns the weighted sum as a single value. Coefficients are real; Pauli() is the identity.

hamiltonian = program.expectation([
    (0.5, {0: "Z"}),
    (-1.0, {0: "X", 1: "X"}),
    (2.0, {}),  # identity offset
])
print(plan_all([hamiltonian]).collect().values)  # one value for the whole sum

Qiskit Estimator

lazyqc.frontends.qiskit.Estimator implements Qiskit's BaseEstimatorV2, so code that goes through the Estimator primitive, including EstimatorQNN, can use LazyQC by swapping the estimator. Every PUB of a job is planned together, and the circuit is translated once.

from qiskit.quantum_info import SparsePauliOp
from lazyqc.frontends.qiskit import Estimator

estimator = Estimator()  # Estimator(default_precision=0.01, seed=7) adds emulated noise
result = estimator.run([(circuit, SparsePauliOp(["ZZI", "IXX"], [0.5, -1.0]), values)]).result()
print(result[0].data.evs)

Values are exact; a precision above zero adds Gaussian noise to them as StatevectorEstimator does. See examples/06_qiskit_estimator_qnn.py for a training loop timed against Aer.

Native threads

Qulacs uses one OpenMP thread per core by default, which is slower than a single thread on the small states cone reduction produces (2 to 3 times at 10 to 12 qubits) and competes with other OpenMP libraries in the same process, such as Aer. plan.collect() therefore runs on one thread when every task is narrower than 14 qubits, and caps the team at 8 threads for wider tasks. The setting used is reported in result.stats.native_threads. Pass collect(native_threads="default") to keep Qulacs' own team, or an integer to fix its size.

Gradients

For bound symbolic parameters, adjoint_gradient computes a weighted scalar-loss gradient with Qulacs backpropagation inside each observable's causal cone. Observables with the same cone share a backpropagation:

from lazyqc import Parameter, Program, adjoint_gradient

theta = Parameter("theta")
program = Program(2).ry(0, theta).cx(0, 1).rz(1, theta).bind(theta=0.4)
gradient = adjoint_gradient(program, [{0: "Z"}, {1: "X"}], [0.7, -0.2])
print(gradient["theta"])

profile_sensitivity(..., method="adjoint") computes occurrence-wise derivatives; method="auto" selects shifts or adjoint independently for each observable cone.

More examples live in examples/ and notebooks/, and design notes and results in docs/.

Development

uv sync --locked --all-extras
uv run pytest -q

Contributing

Contributions are welcome. Please read our Code of Conduct before opening an issue or pull request.

Citation

If you use LazyQC in your research, please cite the accompanying paper (see also CITATION.cff):

@article{montalban2026lazyqc,
  title   = {LazyQC: Lazy Planning for Batched Quantum Result Queries},
  author  = {Montalb{\'a}n, Iraitz},
  year    = {2026},
  note    = {arXiv preprint; journal and DOI to be added upon publication}
}

Metadata

Release files for lazyqc 0.3.0

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

Source distribution (sdist)

Source distribution for lazyqc 0.3.0
File Size Uploaded Provenance Actions
lazyqc-0.3.0.tar.gz 78.6 kB Without provenance Details for lazyqc-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lazyqc 0.3.0
File Interpreter ABI Platform Actions
lazyqc-0.3.0-py3-none-any.whl Python 3 none any Details for lazyqc-0.3.0-py3-none-any.whl

Total release size: 174.7 kB

Release files / lazyqc-0.3.0.tar.gz

Download URL lazyqc-0.3.0.tar.gz
Size 78.6 kB
Tags Source
SHA-256 checksum
How to use checksums
131c31c490776414f8eafe4f1507e1fe396523fb26799d91d76abee8fde0ce79
BLAKE2b-256 checksum
How to use checksums
0dbef81dcd53bf55ca1fdcddc44ed0bd98a1289ba7d5e044a2cd925a31f5c5e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / lazyqc-0.3.0-py3-none-any.whl

Download URL lazyqc-0.3.0-py3-none-any.whl
Size 96.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d1dad9b6d803d4df4b9fe5f8e5228e04e8d1d2f395fa2e1f8871f636ed3fd88
BLAKE2b-256 checksum
How to use checksums
931c44719ec0212671aa3f51ec1b0fc376b4dec64e9b3c5307be23409e868d00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for lazyqc 0.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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