Depth calculation can be improved

Aperta
#3,443 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
15/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Start with the linked Catalyst pull request #3426 and PennyLane pull request #10440; both contain candidate implementations, and the issue says they are large and AI-generated. Check the proposed dependency summaries against the two examples, especially the expected depths of 100 and 44, then review the stated platform, version, and workload coverage gaps. The issue considers the work done when the metric semantics and analysis cost have been reviewed and integration coverage is added.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The PBC resource analysis can overestimate circuit depth. In particular, adding subroutine depths can incorrectly serialize operations on independent qubits. To unlock my work, I have created two branches that potentially solve this issue (AI generated, very big PR 😅). I'm sharing the details in case this is useful.

Example 1: Independent sequences on two qubits
import pennylane as qp
from catalyst import qjit
from catalyst.passes import to_ppr


@qjit(
    target="mlir",
    pipelines=[("pipe", ["quantum-compilation-stage"])],
)
@to_ppr
@qp.qnode(qp.device("lightning.qubit", wires=2))
def circuit():
    for _ in range(100):
        qp.T(0)

    for _ in range(100):
        qp.T(1)


resources = qp.analyze(circuit, level=1)().resources
print(resources.qubit_disjoint_depth)

For the sequence of 100 gates on each wire, the expected qubit-disjoint depth is 100, rather than 200.

Each qubit has 100 sequential operations, but the two sequences are independent and can occupy the same 100 logical layers. Their order in the Python source does not introduce a quantum dependency between the wires.

Example 2: Deterministic synthesis

The same principle should apply when the independent sequences are generated by synthesis.

import numpy as np
import pennylane as qp
from catalyst import qjit
from catalyst.passes import to_ppr

PBC = {
    "PPR_8": 100,
    "PPR_4": 10,
    "PPR_2": 1,
    "GlobalPhase": 0,
    "PauliMeasure": 2,
    "PauliMeasureMP": 2,
    "MidMeasure": 2,
    "MidMeasureMP": 2,
    "MidCircuitMeasure": 2,
}

epsilon = 1e-4
syllables_per_rz = 0.58 * np.log2(1 / epsilon) + 3.7
PBC_RZ = PBC | {"RZ": 110 * syllables_per_rz}


@qjit(
    capture=True,
    target="mlir",
    pipelines=[("pipe", ["quantum-compilation-stage"])],
)
@to_ppr
@qp.transforms.gridsynth(
    method="deterministic",
    epsilon=epsilon,
    ppr_basis=True,
)
@qp.transform(pass_name="symbol-dce")
@qp.decompose(gate_set=PBC_RZ)
@qp.qnode(qp.device("null.qubit", wires=2))
def circuit():
    qp.RX(0.2, wires=0)
    qp.RY(0.2, wires=1)


resources = qp.analyze(circuit, level="user")().resources
assert resources.extra["qubit_disjoint_depth_status"] == "exact"
print(resources.qubit_disjoint_depth)

With the tested PR revisions, this prints 44 with status exact. Placing both rotations on the same qubit gives 86, reflecting the additional sequential dependencies.

This example deliberately uses method="deterministic". The original mixed-fallback variant is not covered by this deterministic-depth guarantee.

Proposed solution

Catalyst tracks per-qubit dependencies and composes them across function calls and supported loops. This preserves parallelism between independent operations while respecting dependencies on shared qubits.

The implementation:

  • Replaces scalar depth aggregation with dependency summaries.
  • Reuses summaries across compatible function calls.
  • Composes invariant loop summaries without fully unrolling the loop.
  • Resolves supported classical computations when their values determine the quantum dependency graph.
  • Supports deterministic PPR synthesis by analyzing the sequence produced by the synthesis runtime.
  • Reports exact when the complete logical depth can be determined, and unavailable otherwise.

PennyLane consumes the certified total instead of reconstructing depth by summing child results. Unsupported cases return None with an explicit status. The new path also leaves any_commuting_depth unavailable, since an exact qubit-disjoint schedule does not establish commuting depth.

Larger workflow validation

The tested ODMR configuration reports exact depths of:

  • to-ppr: 3,034,595,019
  • ppr-to-ppm: 6,046,959,517

These results demonstrate the application of dependency analysis to a larger workflow. They do not establish a compilation-speed improvement.

Scope and tradeoffs

The intended metric is the logical depth of the emitted PBC dependency graph. It measures the parallelism already present in that graph; it does not optimize the circuit or predict physical execution time.

Exact analysis requires additional computation and memory. Dense dependency summaries retain quadratic storage and cubic composition time in the general worst case, although summary reuse improves important repeated patterns.

Resolving classical computations and synthesis also introduces integration and maintenance requirements. Unknown inputs, unsupported control flow, or analysis limits can produce unavailable, so downstream consumers must handle missing depth values explicitly.

Before merging, the implementation should receive integration coverage across supported platforms and PennyLane/Catalyst versions, together with review of the metric's semantics and analysis cost on representative workloads.

Lingua principale
Python
Stelle
234
Fork
84
Merge medio
3g 11h
PR unite (30g)
78

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PennyLaneAI/catalyst

Tutte le issue di PennyLaneAI/catalyst

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.