Depth calculation can be improved

Open
#3,443 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
15/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
234
Forks
84
Avg merge
3d 11h
Merged PRs (30d)
78

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PennyLaneAI/catalyst

All issues in PennyLaneAI/catalyst

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.