Skip to content

Decomp/pbc decomposable interface - #3170

Open
hsajjad14 wants to merge 9 commits into
mainfrom
decomp/pbc-decomposable-interface
Open

Decomp/pbc decomposable interface#3170
hsajjad14 wants to merge 9 commits into
mainfrom
decomp/pbc-decomposable-interface

Conversation

@hsajjad14

@hsajjad14 hsajjad14 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Context:
The DecomposableGate interface was introduced to provide a generic interface for decomposition of quantum gates. We want the graph-decomposition to be able to decompose to the PBC dialect, but this will require the DecomposableGate interface be implemented for PBC gates.

Description of the Change:
This PR extends the DecomposableGate interface to the PBC dialect. It uses the same template for how the interface is extended for Quantum and Qref dialects.

I added the DecomposableGate interface to PBCOpInterfaces.td (this does not inherit QuantumGate unlike in QuantumInterface.td), then extend the two PPR operations in PBCOps.td, PPRotationOp and PPRotationArbitraryOp. Currently only these two operations in the PBC dialect have decomposition rules, PPMeasurementOp is qp.PauliMeasure, but it has no add_decomps in PennyLane yet.

PBCOpInterfaces.cpp is slightly different than QuantumInterfances.cpp. For defaultGetGraphOpId because the PPR operations don't have adjoint in its arguments in the PBCOps.td, it is not an attribute. Also the operation will never be a QuantumGate, thus there is no need for a wrapModifiers function around getOperatorName().
I used the same helpers from QuantumInterfances.cpp in PBCOpInterfaces.cpp, but from comparing with the QRef those helpers are slightly different, so I held off on moving the helpers into their own file.

In PBCOps.cpp I implement two operations PPRotationOp and PPRotationArbitraryOp. I use the same implementation from QuantumOps.cpp for PauliRotOp except because DecomposableGate for PBC does not inherit QuantumGate, for getWireLens() I used getInQubits().size() to get wires instead of getNonCtrlQubitOperands().size().

Benefits:
Allows PBC operations to be compatible with the graph-decomposition pass.

Possible Drawbacks:
Code duplication with Quantum and Qref dialect, especially for the helper functions.

Related GitHub Issues:
[sc-129100]

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.64%. Comparing base (918e259) to head (6cca181).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3170      +/-   ##
==========================================
- Coverage   95.72%   95.64%   -0.09%     
==========================================
  Files         174      177       +3     
  Lines       20720    20854     +134     
  Branches     2087     2100      +13     
==========================================
+ Hits        19835    19945     +110     
- Misses        691      722      +31     
+ Partials      194      187       -7     

☔ 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.

@kipawaa

kipawaa commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Thanks @hsajjad14!

PPMeasurementOp is qp.PauliMeasure, but it has no add_decomps in PennyLane yet.

We still need the interface for PPMs because they can be the result of a decomposition, and so need to be registered in the graph. Could you add the interface & tests for this as well?

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.

Could you add tests for controlled/adjoint gates as well?

@hsajjad14 hsajjad14 Sep 8, 2026

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.

For controlled PPR gates, the mlir generated for this qp.ctrl(qp.PauliRot, control = (0), control_values=(1))(angle, pauli_word="YZ", wires=[1, 2]) after to-ppr is %16:2 = pbc.ppr.arbitrary ["Y", "Z"](%cst) %15#1, %15#2 : !quantum.bit, !quantum.bit there is no control attribute for pbc. So that test would be the same as PPRotationArbitraryOp.

For adjoint gates, for PBC dialect the adjoint attribute gets lowered out to be a negative angle. I added tests for that in here 6cca181

@hsajjad14

hsajjad14 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

We still need the interface for PPMs because they can be the result of a decomposition, and so need to be registered in the graph. Could you add the interface & tests for this as well?

I added ppm op to the interface in 2f9a1cb. meas_uid and postselect are not lowered into PPMeasurementOp, so I set them to None manually.

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.

2 participants