Skip to content

Add PBC depth to resource-analysis JSON#2967

Open
sengthai wants to merge 24 commits into
mainfrom
sengthai/pbc-depth-in-resource-analysis
Open

Add PBC depth to resource-analysis JSON#2967
sengthai wants to merge 24 commits into
mainfrom
sengthai/pbc-depth-in-resource-analysis

Conversation

@sengthai

@sengthai sengthai commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Previously, the resource-analysis counts only gate and qubit number. The PBC depth analysis only exists in ppm_specs pass.

In this PR, we add PBC depth (any_commuting_depth / qubit_disjoint_depth) to resource-analysis JSON output. Also, report depth for both function bodies and lifted loop entries (for_loop_*, dyn_for_loop_*), same operation counts. For non-pbc circuit, the depth value is empty.

Note:
any_commuting_depth: the PPR/PPM that has non-overlapping qubit or commute to all gates in the layer.
qubit_disjoint_depth: the PPR/PPM that has non-overlapping qubit to all gates in the layer.

For the circuit something like this:

scf.for ... to %n ... {
  pbc.ppr ["Z"](4) ...
}
pbc.ppr ["X"](4) ...

The output:

{
  "circuit": {
    "depth": {
      "any_commuting_depth": 1,
      "qubit_disjoint_depth": 1
    },
    "var_function_calls": {
      "dyn_for_loop_1": "0x..."
    }
  },
  "dyn_for_loop_1": {
    "depth": {
      "any_commuting_depth": 1,
      "qubit_disjoint_depth": 1
    }
  }
}

See also: PennyLaneAI/pennylane#9703

Comment thread mlir/lib/Catalyst/Transforms/ResourceAnalysisPass.cpp
Comment thread mlir/include/PBC/Utils/PBCLayer.h Outdated
Comment thread mlir/lib/Catalyst/Transforms/ResourceAnalysisPass.cpp Outdated
Comment thread mlir/lib/Catalyst/Transforms/ResourceAnalysisPass.cpp Outdated
@sengthai sengthai requested review from a team and jzaia18 June 18, 2026 19:42
Comment thread mlir/include/PBC/Utils/PBCLayer.h Outdated
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.97%. Comparing base (a97d03a) to head (3b9ed72).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2967   +/-   ##
=======================================
  Coverage   96.97%   96.97%           
=======================================
  Files         166      166           
  Lines       19209    19209           
  Branches     1788     1788           
=======================================
  Hits        18628    18628           
  Misses        429      429           
  Partials      152      152           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rniczh rniczh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread mlir/lib/Catalyst/Transforms/ResourceAnalysisPass.cpp Outdated
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp Outdated
@sengthai sengthai requested a review from jzaia18 June 19, 2026 17:47
auto d1 = computeBlockWorstCaseDepth(block, /*onlyOnDisjointQubit=*/true);
if (failed(d1) || *d1 == 0) {
return std::nullopt;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we not care about skipDynamic in the else branch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipDynamic doesn't matter in else branch. the reason is that whether skipDynamic changes anything depends only on whether the block contains a dynamic loop and that is completely independent of onlyOnDisjointQubit.

Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp
Comment thread mlir/test/Catalyst/ResourceAnalysisTest.mlir
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp Outdated
Comment thread mlir/lib/Catalyst/Transforms/ResourceAnalysisPass.cpp Outdated
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp Outdated
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp Outdated
Comment thread mlir/lib/Catalyst/Transforms/ResourceAnalysisPass.cpp
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp Outdated
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp
Comment thread mlir/lib/PBC/Utils/PBCLayer.cpp
@sengthai sengthai requested a review from jzaia18 June 29, 2026 18:03

@jzaia18 jzaia18 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nice work

Co-authored-by: Jake Zaia <23638795+jzaia18@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants