Skip to content

Conversation

@multiphaseCFD
Copy link
Member

@multiphaseCFD multiphaseCFD commented Jul 14, 2025

Before submitting

Please complete the following checklist when submitting a PR:

  • All new features must include a unit test.
    If you've fixed a bug or added code that should be tested, add a test to the
    test directory!

  • All new functions and code must be clearly commented and documented.
    If you do make documentation changes, make sure that the docs build and
    render correctly by running make docs.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the doc/releases/changelog-dev.md file, summarizing the
    change, and including a link back to the PR.

  • The PennyLane source code conforms to
    PEP8 standards.
    We check all of our code against Pylint.
    To lint modified files, simply pip install pylint, and then
    run pylint pennylane/path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context:
[sc-88794]

This PR adds a pass to lower all gates in the MBQC gate set to a MBQC formalism. Those gates include Hadamard, S, RZ, RotXZX, CNOT. The program structure or control flows (if, for, while) can be also maintained.

The resource auxiliary qubits used as computational resources are statically allocated and deallocated in a gate by gate manner. This PR also assumes that a auxiliary qubit can be swapped with a target qubit in the global register.

This pass can lower a circuit with 1k wires, 10 k gates and 100k shots on a null.qubit device, given that autograph is set as True. It's also compatible with the measurements_from_samples_pass, which is tested in the unit test as well.

Here is a sample script (pennylane_catalyst==0.13.0.dev18 and xdsl==0.46.0):

import xdsl
import catalyst

from catalyst.ftqc import mbqc_pipeline

from catalyst.passes.xdsl_plugin import getXDSLPluginAbsolutePath

import pennylane as qml
from pennylane.compiler.python_compiler.transforms import (
    convert_to_mbqc_formalism_pass,
    measurements_from_samples_pass,
)

from pennylane.ftqc import RotXZX

qml.capture.enable()

dev = qml.device("null.qubit", wires=1000, shots=100000)

@qml.qjit(
    target="mlir",
    pass_plugins=[getXDSLPluginAbsolutePath()],
    pipelines=mbqc_pipeline(),
    autograph=True,
)
@convert_to_mbqc_formalism_pass
@measurements_from_samples_pass
@qml.qnode(dev)
def circuit():
    for i in range(1000):
        qml.H(i)
        qml.S(i)
        RotXZX(0.1, 0.2, 0.3, wires=[i])
        qml.RZ(phi=0.1, wires=[i])
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.Z(wires=0))

res = circuit()

To capture the program structure without unrolling loops:

@qml.qjit(target="mlir", pass_plugins=[xdsl_plugin.getXDSLPluginAbsolutePath()], autograph=True)
@convert_to_mbqc_formalism_pass
@qml.qnode(dev)
def circuit_ref():
    @qml.for_loop(0, 100, 1)
    def loop_func(i):
        qml.H(i)
        qml.S(i)
        RotXZX(0.1, 0.2, 0.3, wires=[i])
        qml.RZ(phi=0.1, wires=[i])
    loop_func()
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.Z(wires=0))

Description of the Change:

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@joeycarter joeycarter added the unified compiler Issues and pull requests related to PennyLane's xDSL python compiler. label Jul 17, 2025
Copy link
Contributor

@joeycarter joeycarter left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @multiphaseCFD! Happy to approve once these few remaining items are resolved.

Copy link
Contributor

@joeycarter joeycarter left a comment

Choose a reason for hiding this comment

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

Looks good! 💯

Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

Thanks @multiphaseCFD, looks great! I left a few non-blocking comments 🚀

@multiphaseCFD multiphaseCFD added this pull request to the merge queue Sep 2, 2025
Merged via the queue into master with commit bb3885e Sep 2, 2025
52 checks passed
@multiphaseCFD multiphaseCFD deleted the shuli/add_convert_to_mbqc_pass branch September 2, 2025 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unified compiler Issues and pull requests related to PennyLane's xDSL python compiler.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants