Skip to content

Block-local commutation analysis#4984

Open
taalexander wants to merge 3 commits into
NVIDIA:mainfrom
taalexander:feature/block-local-commutation-analysis
Open

Block-local commutation analysis#4984
taalexander wants to merge 3 commits into
NVIDIA:mainfrom
taalexander:feature/block-local-commutation-analysis

Conversation

@taalexander

@taalexander taalexander commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Based on prerequisite work in #4982.

This PR adds a read-only block-local analysis for determining whether two Quake operations are proven to commute. A later transformation will use it to find rewrites across intervening commuting operations.

The analysis assigns virtual-qubit identifiers to supported scalar Quake values, builds operation-local control and target views, and applies a centralized set of exact commutation rules. Identity tracking remains a separate internal analysis and translation unit for separation of concerns, but it is included in this PR as an implementation dependency of CommutationAnalysis. It is not proposed as the shared identity-analysis API. #4983 is superseded by this combined review unit.

The current rules cover disjoint support, the same operation or exact adjoint, computational-basis diagonal operations, common Pauli axes, Pauli-product parity, diagonal actions on controls, compatible controlled targets, and mutually exclusive controls. Unsupported or ambiguous cases remain indeterminate.

The following AI-generated candidates are recorded for later validation rather than included in this PR.

Future extensions

Structurally provable candidates

  • Two controlled custom unitaries sharing a control but acting on disjoint targets.
  • Controlled custom unitaries with opposite polarity on a shared control and no target-control crossover.
  • An all-I/Z ExpPauli acting on the controls of another controlled operation.
  • Controlled all-I/Z Pauli products that are diagonal but are not currently classified as computational-basis diagonal.
  • A dynamic ExpPauli word produced by a compile-time constant expression.
  • Symbolic Pauli words whose equality or anti-commutation parity is known by another analysis.

Parameter-dependent candidates

  • An identity-valued rotation, such as Rx(0), against an otherwise noncommuting operation on the same target.
  • Equivalent parameter expressions represented by different SSA values, such as %theta and %theta + 0.
  • PhasedRx operations whose phase parameters are equivalent modulo the exact phase period.
  • U2 or U3 parameter combinations that reduce to a known axis rotation.
  • Cross-operation equivalences exposed by exact constant parameters but not already handled by the X-, Y-, and Z-axis families.
  • Special angles at which generally noncommuting Pauli rotations become identity or another commuting operator.

These cases may be better handled by folding and canonicalization before commutation analysis.

Permutation candidates

  • Swap(a,b) with CZ(a,b), which is invariant under exchanging its two qubits.
  • Swap(a,b) with a symmetric Pauli product such as XX, YY, or ZZ on (a,b).
  • Swap(a,b) with any multi-qubit operation whose target action is invariant under the same permutation.
  • Equivalent larger qubit permutations represented by different sequences of Swap operations.

Custom-unitary candidates

  • Different custom-unitary symbols containing identical constant matrices.
  • Different diagonal custom unitaries acting on the same target.
  • Different custom-unitary matrices that can be proven to commute exactly.
  • Custom operators exposing a common generator, eigenspace, or diagonalizing basis.
  • Controlled custom operators for which only target-action properties are needed by a generic controlled rule.

Basis-aware candidates

  • Operations diagonal in the same noncomputational basis.
  • Controls whose effective basis is established by surrounding conjugations, such as H-C(U)-H.
  • Pauli or Clifford conjugation that transforms two operations into a recognized commuting family.
  • Mutually exclusive controls established by classical or quantum dataflow rather than opposite static polarity on one control operand.

These require sequence-level basis, Clifford, or predicate tracking rather than only an operation-pair query.

Cases requiring a different semantic contract

  • Reordering operations that commute only up to global phase.
  • State-dependent commutation on a proven invariant subspace.
  • Reordering or eliminating diagonal gates around computational-basis measurement.
  • Relations involving measurement, reset, or quantum channels.
  • Incremental preservation of cached results across block mutation.

Reject malformed control-polarity metadata and invalid static ExpPauli literals during IR verification. Represent Pauli words as typed symbols so decomposition and later analyses share one validated interpretation instead of repeating string comparisons.

Validated with the cudaq-opt target and the four affected lit pipelines.

Signed-off-by: Thomas Alexander <talexander@nvidia.com>
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

CI Summary (push) — ✅ passed

Run #30095037569 · ✅ 6 · ⏩ 7 · ❌ 0 · ⛔ 0

Top-level jobs (13)
Job Result
binaries ⏩ skipped
build_and_test ✅ success
config_devdeps ✅ success
config_source_build ⏩ skipped
config_wheeldeps ✅ success
devdeps ✅ success
docker_image ⏩ skipped
gen_code_coverage ⏩ skipped
metadata ✅ success
python_metapackages ⏩ skipped
python_wheels ⏩ skipped
source_build ⏩ skipped
wheeldeps ✅ success
⏩ Skipped jobs (7) — intentionally skipped on PR builds; run on merge_group / workflow_dispatch
Job
binaries
config_source_build
docker_image
gen_code_coverage
python_metapackages
python_wheels
source_build
All sub-jobs (42) — every matrix leg, with links
Job Status Link
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
CI Summary ❔ in_progress view
Configure build (devdeps) ✅ success view
Configure build (source_build) ⏩ skipped view
Configure build (wheeldeps) ✅ success view
Create CUDA Quantum installer ⏩ skipped view
Create Docker images ⏩ skipped view
Create Python metapackages ⏩ skipped view
Create Python wheels ⏩ skipped view
Gen code coverage ⏩ skipped view
Load dependencies (amd64, gcc12) / Caching ✅ success view
Load dependencies (amd64, gcc12) / Finalize ✅ success view
Load dependencies (amd64, gcc12) / Metadata ✅ success view
Load dependencies (amd64, llvm) / Caching ✅ success view
Load dependencies (amd64, llvm) / Finalize ✅ success view
Load dependencies (amd64, llvm) / Metadata ✅ success view
Load dependencies (arm64, gcc12) / Caching ✅ success view
Load dependencies (arm64, gcc12) / Finalize ✅ success view
Load dependencies (arm64, gcc12) / Metadata ✅ success view
Load dependencies (arm64, llvm) / Caching ✅ success view
Load dependencies (arm64, llvm) / Finalize ✅ success view
Load dependencies (arm64, llvm) / Metadata ✅ success view
Load source build cache ⏩ skipped view
Load wheel dependencies (amd64, 12.6) / Caching ✅ success view
Load wheel dependencies (amd64, 12.6) / Finalize ✅ success view
Load wheel dependencies (amd64, 12.6) / Metadata ✅ success view
Load wheel dependencies (amd64, 13.0) / Caching ✅ success view
Load wheel dependencies (amd64, 13.0) / Finalize ✅ success view
Load wheel dependencies (amd64, 13.0) / Metadata ✅ success view
Load wheel dependencies (arm64, 12.6) / Caching ✅ success view
Load wheel dependencies (arm64, 12.6) / Finalize ✅ success view
Load wheel dependencies (arm64, 12.6) / Metadata ✅ success view
Load wheel dependencies (arm64, 13.0) / Caching ✅ success view
Load wheel dependencies (arm64, 13.0) / Finalize ✅ success view
Load wheel dependencies (arm64, 13.0) / Metadata ✅ success view
Prepare cache clean-up ❔ in_progress view
Retrieve PR info ✅ success view
✅ Required checks (6/6) — declared in .github/required-checks.yml for push
Required check Status Link
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ✅ success view

@taalexander
taalexander force-pushed the feature/block-local-commutation-analysis branch from 1cfc218 to f0e98ef Compare July 24, 2026 01:17
@taalexander taalexander changed the title Block local commutation analysis Block-local commutation analysis Jul 24, 2026
Qualify Pauli symbols at their use sites and preserve valid one-, two-, and three-qubit ExpPauli lowering coverage. This addresses review feedback without weakening the existing mismatch diagnostic.

Signed-off-by: Thomas Alexander <talexander@nvidia.com>
Provide a reusable read-only query for structural commutation between Quake operators in one value-form block. Keep the block-local qubit identity analysis as an internal, separately tested implementation dependency of the commutation analysis rather than publishing it as an independent review unit.

The rule set covers disjoint support, identical operations, diagonal and same-axis operators, Pauli parity, controlled-target compatibility, and mutually exclusive controls. Unsupported values and opaque shared-support semantics remain conservative.

The combined tree matches the previously tested identity and commutation PRs; the ownership comment now identifies CommutationAnalysis as the identity helper's consumer.

Signed-off-by: Thomas Alexander <talexander@nvidia.com>
@taalexander
taalexander force-pushed the feature/block-local-commutation-analysis branch from f0e98ef to 381651e Compare July 24, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant