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.2.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

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

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.2.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.2.0
File Size Uploaded Provenance Actions
lazyqc-0.2.0.tar.gz 71.6 kB Without provenance Details for lazyqc-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 159.8 kB

Release files / lazyqc-0.2.0.tar.gz

Download URL lazyqc-0.2.0.tar.gz
Size 71.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1fd8f6284eb70e81c924ce2a8163b21dda75b5556f881b4b24c7172dafe355c3
BLAKE2b-256 checksum
How to use checksums
990f287e6d57dfceda475e21ec64d12901e7ddf74b1d89e899b25588cd37bdf9
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.2.0-py3-none-any.whl

Download URL lazyqc-0.2.0-py3-none-any.whl
Size 88.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d9b3530a41560f70d5bef5a354bbe4de03695d1200d3fe0f4b045ecdab9bfab
BLAKE2b-256 checksum
How to use checksums
b2fb3bf7de1ff5362c7b57e77f6ce1c4600ed684b09da43135ad5083958b127f
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.2.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