Skip to content

Conversation

@dwierichs
Copy link
Contributor

Context:
The Clifford group by definition can transform Paulis to each other. In particular, we can conjugate RX, RY and RZ by appropriate Cliffords to get either one of the other rotations.

Description of the Change:
Add decompositions within the graph-based system that implement this. It amounts to 6 rules (RX->RY RX->RZ, RY->RX RY->RZ, RZ->RX RZ->RY).

Also, add an assert_valid test to all standard ops.

Benefits:
More versatile decomposition, in particular in the context of phase polynomials which prefer RZ over RX or RY rotations.

Possible Drawbacks:
N/A

Related GitHub Issues:

@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.43%. Comparing base (768083a) to head (d151ac6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8569   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files         588      588           
  Lines       62727    62757   +30     
=======================================
+ Hits        62373    62403   +30     
  Misses        354      354           

☔ View full report in Codecov by Sentry.
📢 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 +164 to +170
@pytest.mark.parametrize("op", ALL_OPERATIONS)
def test_assert_valid(self, op):
kwargs = SKIP_ASSERT_VALID.get(type(op), {})
if kwargs is True:
pytest.skip()

qml.ops.functions.assert_valid(op, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this!

@comp-phys-marc comp-phys-marc self-requested a review November 4, 2025 21:54

add_decomps(RY, _ry_to_rot, _ry_to_rz_rx)
def _ry_to_rx_cliff_resources():
return {change_op_basis_resource_rep(adjoint_resource_rep(qml.S), qml.RX, qml.S): 1}
Copy link
Contributor

Choose a reason for hiding this comment

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

This one checks out!

Copy link
Contributor

Choose a reason for hiding this comment

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

(checked this one by hand...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Image



def _rx_to_rz_cliff_resources():
return {change_op_basis_resource_rep(qml.Hadamard, qml.RZ, qml.Hadamard): 1}
Copy link
Contributor

@comp-phys-marc comp-phys-marc Nov 5, 2025

Choose a reason for hiding this comment

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

I know Hadamard transforms between X and Z bases.

@register_resources(_ry_to_rz_cliff_resources)
def _ry_to_rz_cliff(phi, wires: WiresLike, **__):
qml.change_op_basis(
qml.Hadamard(wires) @ qml.adjoint(qml.S(wires)),
Copy link
Contributor

Choose a reason for hiding this comment

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

This one checks out!

Copy link
Contributor

Choose a reason for hiding this comment

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

wires = 0
phi = 1.5 * 3.14

matrix = qml.matrix(qml.S(wires) @ qml.Hadamard(wires) @ qml.RZ(phi, wires) @ qml.Hadamard(wires) @ qml.adjoint(qml.S(wires)))
ry = qml.matrix(qml.RY(phi, wires))
assert np.allclose(matrix, ry)

@register_resources(_rz_to_ry_cliff_resources)
def _rz_to_ry_cliff(phi, wires: WiresLike, **__):
qml.change_op_basis(
qml.S(wires) @ qml.Hadamard(wires),
Copy link
Contributor

Choose a reason for hiding this comment

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

Checks out.

wires = 0
phi = 1.5 * 3.14

matrix = qml.matrix(qml.Hadamard(wires) @ qml.adjoint(qml.S(wires)) @ qml.RY(phi, wires) @ qml.S(wires) @ qml.Hadamard(wires))
rz = qml.matrix(qml.RZ(phi, wires))
assert np.allclose(matrix, rz)

Copy link
Contributor

@comp-phys-marc comp-phys-marc left a comment

Choose a reason for hiding this comment

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

All the decompositions look right!

@dwierichs dwierichs requested review from JerryChen97 and removed request for JerryChen97 November 5, 2025 16:37
@JerryChen97
Copy link
Contributor

@dwierichs dwierichs requested a review from JerryChen97 December 5, 2025 13:22

<h3>Improvements 🛠</h3>

<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops... looks like a bad merge 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 believe this is a GH issue. Recently somehow you can't trust the GH entry point from the notifications any more; we have to go back to the PR and click the files section to see the correct diff

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically their problem made you see and comment on an outdated part:
image


<h3>Breaking changes 💔</h3>

<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

Bad merge here too.

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.

4 participants