Skip to content

Adding PPM based decomposition to C(MultiX) - #10558

Open
KetpuntoG wants to merge 10 commits into
mainfrom
c_multix_ppm
Open

KetpuntoG wants to merge 10 commits into
mainfrom
c_multix_ppm

Conversation

@KetpuntoG

Copy link
Copy Markdown
Contributor

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.rst 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:

Working on the goal: All standard gates encountered in application_algos/workflows/ use best-in-class PPR and PPM decompositions on main pennylane

Description of the Change:

Adding lattice surgery like decomposition to c(multiX)

Benefits:

for efficient pbc level decompositions

Possible Drawbacks:

Larger PPM-weights

Comment thread doc/releases/changelog-dev.rst Resolved
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10558      +/-   ##
==========================================
- Coverage   99.39%   99.39%   -0.01%     
==========================================
  Files         613      613              
  Lines       67668    67717      +49     
==========================================
+ Hits        67258    67304      +46     
- Misses        410      413       +3     

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

Comment on lines +454 to +457
# Keep the existing unitary fallback ahead of the PPM alternative.
_controlled_multix = _make_controlled_decomp(_multix_decomposition)
_controlled_multix.name = "_controlled_multix"
_controlled_multix.add_condition(lambda control_wires, **_: len(control_wires) == 1)

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.

This may look strange but the reason of adding this is that if my C(MultiX) decomposition is the only decomposition added, it was always taking it and measurements always appears in not supported devices.

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.

Ah this is interesting! Can you ask core if this is the preferred way of doing this? Might be good to let them know that we hit this scenario :)

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.

asked in #pennylane-core and they are fine with this provisional approach ✅

@dwierichs
dwierichs self-requested a review November 19, 2026 21:52

@dwierichs dwierichs 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.

looking good, nice work @KetpuntoG
Just some small comments.

Comment thread doc/releases/changelog-dev.rst Outdated
Comment on lines +8 to +9
using three Pauli product measurements and one auxiliary qubit. It supports
dynamic bitstrings and controls on either ``0`` or ``1``.

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.

Suggested change
using three Pauli product measurements and one auxiliary qubit. It supports
dynamic bitstrings and controls on either ``0`` or ``1``.
using three Pauli product measurements and one auxiliary qubit.


:class:`~.X` | :math:`\sum_i b_i \leq n` (one per :math:`b_i=1`) | 2

Single-control ``C(MultiX)`` supports a lattice-surgery decomposition using three

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.

Can you add a regular entry to the table instead? :)

Comment on lines +454 to +457
# Keep the existing unitary fallback ahead of the PPM alternative.
_controlled_multix = _make_controlled_decomp(_multix_decomposition)
_controlled_multix.name = "_controlled_multix"
_controlled_multix.add_condition(lambda control_wires, **_: len(control_wires) == 1)

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.

Ah this is interesting! Can you ask core if this is the preferred way of doing this? Might be good to let them know that we hit this scenario :)

add_decomps("C(MultiX)", flip_zero_control2(_controlled_multix_ladder), _controlled_multix)


def _measure_z_multix(work_wire, bitstring, wires):

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.

We have this logic in the recently fixed QROM PPM rule, right? :) Maybe we can reuse it. But just an optional suggestion.

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.

Yes, I used the same idea as QROM. I kept the helper separate for now because QROM already imports MultiX, but we could combine them later

)
def _controlled_multix_lattice_surgery_ppm(base, control_wires, control_values, **_):
"""Implement a single-control MultiX with three PPMs and one consumed auxiliary qubit."""
cond(math.logical_not(control_values[0]), PauliX)(control_wires[0])

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 use the flip_zero_control2 wrapper here.

work_wires = rule.get_work_wire_spec(**op.arguments)
assert work_wires.burnable == work_wires.total == 1

@pytest.mark.usefixtures("enable_graph_decomposition")

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.

This is no longer needed as of very recently :)

Suggested change
@pytest.mark.usefixtures("enable_graph_decomposition")

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.

the test fails without this fixture 🤔


assert_decomposable(op)

@pytest.mark.usefixtures("enable_and_disable_graph_decomp")

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.

graph is enabled by default now, and I think it's okay to not test without :)

Suggested change
@pytest.mark.usefixtures("enable_and_disable_graph_decomp")

rule = qp.list_decomps(op)["_controlled_multix_lattice_surgery_ppm"]
outcomes = iter(outcomes)

# Catalyst does not preserve pauli_measure's postselect argument under capture.

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.

Is this a bug we should report? Are we using postselect? 🤔

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.

We’re not using postselect here. The test uses projectors to check all possible measurement outcomes, so I’ve updated the comment to explain that

@Qottmann

Copy link
Copy Markdown
Contributor

could we also add multi-control? should be basically the same decomp or am I missing something?

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.

3 participants