Skip to content

Conversation

@josephleekl
Copy link
Contributor

@josephleekl josephleekl commented Oct 21, 2025

Context:
This is the first of 2 PRs to implement the 'Gridsynth' pass in Catalyst. (Second PR). This PR only contains the MLIR pass itself, and a dummy implementation of the actual runtime discretization function in order to test the data transfer between the MLIR and the C++ runtime. The actual discretization runtime, along with python tests, will be part of the next PR.

This branch needs to be used in conjunction with the rs-decomp branch in PennyLane.

To test this:

import pennylane as qml
from functools import partial

qml.capture.enable()

@qml.qjit(verbose=True, keep_intermediate=True)
@partial(qml.transforms.gridsynth, epsilon=0.12345, ppr_basis=False)
@qml.qnode(qml.device("null.qubit", wires=1))
def circuit(x):
    qml.RZ(x, 0)
    return qml.expval(qml.Z(0))

x = 1.1
print(circuit(x))

Description of the Change:

Benefits:

Possible Drawbacks:

Related GitHub Issues:

[sc-102150]

@josephleekl josephleekl changed the title RS decomposition [WIP] Gridsynth decomposition Oct 29, 2025
@josephleekl josephleekl changed the title [WIP] Gridsynth decomposition [WIP - Gridsynth 1] Gridsynth decomposition Oct 30, 2025
@josephleekl josephleekl changed the title [WIP - Gridsynth 1] Gridsynth decomposition [Gridsynth 1] Gridsynth decomposition Nov 25, 2025
@josephleekl josephleekl requested a review from AntonNI8 November 25, 2025 21:27
.dep-versions Outdated
# For a custom PL version, update the package version here and at
# 'doc/requirements.txt'
pennylane=0.44.0.dev31
pennylane=0.44.0.dev37
Copy link
Member

Choose a reason for hiding this comment

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

Once the PL PR is merged, let's update to that dev version

pennylane-lightning-kokkos==0.44.0-dev11
pennylane-lightning==0.44.0-dev11
pennylane==0.44.0.dev31
git+https://github.com/PennyLaneAI/pennylane.git@rs-decomp
Copy link
Member

Choose a reason for hiding this comment

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

Same here

auto getSizeType =
rewriter.getFunctionType({f64Type, f64Type, i1Type}, {rewriter.getIndexType()});
auto getSizeFunc =
catalyst::ensurefuncOrDeclare(rewriter, func, "rs_decomposition_get_size", getSizeType);
Copy link
Member

Choose a reason for hiding this comment

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

Do you know what is adding the _0 to the names? 🤔 doesn't seem to show up in the unit test for the pass, but seems like something in the end-to-end pipeline is adding it.

Copy link
Member

Choose a reason for hiding this comment

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

Apparantly it's the --inline-nested-module pass.

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 42 to 44
* Note: I have tried to use `MemRefT_int64_1d` directly from Types.h, but ran into
* C++ ABI errors (on macOS) leading to segmentation faults. Thus, we manually unpack the memref
* here.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the reason might be that we usually pass a pointer to the memref descriptor, precisely to avoid abi issues with how structs are passed (apparently those can differ). We typically just use stack memory for this.

But since your use case is limited with a small signature, the direct approach might work well :)

Copy link
Contributor

@sengthai sengthai left a comment

Choose a reason for hiding this comment

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

I appreciate this PR! @josephleekl
Here is part 1 of the review.


void populateGridsynthPatterns(RewritePatternSet &patterns, double epsilon, bool pprBasis)
{
patterns.add<DecomposeCustomOpPattern>(patterns.getContext(), epsilon, pprBasis);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we include decomposing PPRotationArbitraryOp (e.g, qec.ppr.arbitrary ["Z"](%const) %q0,) in this PR as well? https://github.com/PennyLaneAI/catalyst/blob/3eefa0088455a088841631e80f621f89e717c22d/mlir/include/QEC/IR/QECDialect.td#L354C1-L355C1

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.

7 participants