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

Training loops: plan once, rebind at every step

Training repeats one circuit structure with new angles. Free the angles with Program.parametrize, build the parameter-shift batch once, and pass the values of each step to collect:

from lazyqc import Pauli, parameter_shift_requests, plan_all

symbolic, values = program.parametrize(indices)          # angles become p0, p1, ...
requests = parameter_shift_requests(symbolic, [Pauli(((0, "Z"),))], indices)
plan = plan_all(requests, symbolic=True)                 # structure only, no angles yet

for step in range(steps):
    result = plan.collect(bindings=values)               # lowered circuits are reused
    ...                                                  # update `values` from the Jacobian

Shifts are offsets of the same parameter (Parameter("p0").shifted(pi / 2)), so one plan serves every step and values equal planning from scratch. A symbolic plan lowers each task once into a Qulacs parametric circuit and only sets the new angles afterwards; backends without rebind bind each task instead. Symbolic planning does not combine with optimization, cutting or batch options. See examples/08_plan_once_training.py.

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.4.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.4.0
File Size Uploaded Provenance Actions
lazyqc-0.4.0.tar.gz 81.5 kB Without provenance Details for lazyqc-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 181.0 kB

Release files / lazyqc-0.4.0.tar.gz

Download URL lazyqc-0.4.0.tar.gz
Size 81.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9fa5621457c36c93b3a28aeffc0fbb977ae27bc9e19c6c1192733f1decf4f739
BLAKE2b-256 checksum
How to use checksums
d4c63d5b8fc85f80656eadc44fa2fdd7274f956a6a08f350bcdcd0531c780c43
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.4.0-py3-none-any.whl

Download URL lazyqc-0.4.0-py3-none-any.whl
Size 99.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10c67013397828327745738fc69a06bb073c55f1c09f36bc1dd8a617ee7e9c51
BLAKE2b-256 checksum
How to use checksums
e02b652cb5aa144d98f80af3cfc956d9d032ecfc848096501526d1371f3cac26
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.4.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