Repository navigation
refactor: Custom modifiers for Pauli exp - #52
Open
Walden-Killick wants to merge 13 commits into
Open
Walden-Killick wants to merge 13 commits into
Walden-Killick wants to merge 13 commits into
Conversation
Walden-Killick
added this pull request to stack #53
October 1, 2026 10:44
Walden-Killick
force-pushed
the
refactor/pauli_exp
branch
from
October 8, 2026 13:18
b9338aa to
308e66d
Compare
Walden-Killick
marked this pull request as ready for review
October 8, 2026 13:34
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
5 open findings
_take_pauli_qubitsdeclaresindicesasfrozenarray[int, n_paulis], butpauli_indicesis… · New This introduces new, non-trivial behavior for identity Paulis in the controlled/ctrl-daggered cases… · New The four methods (__call__,controlled,daggered,ctrl_daggered) duplicate the same… · New This dagger test runs unconditionally, butpauli_exp(...)can still return a non-unitary Guppy… · New The docstring says “no-op up to global phase”, but the assertion compares againstnp.eye(8)… · New
What changed in this PR
Refactors pauli_exp to return a Guppy unitary gadget (when the provided rz_method supports it), enabling custom modifiers like dagger/controlled, and updates tests/docs accordingly.
Changes:
- Add unitary-class implementation for
pauli_exp(includingcontrolled/daggeredvariants) and new identity-string behavior. - Update tests to validate
daggerbehavior and treat identity exponentials as no-ops (uncontrolled). - Bump
guppylangminimum version and adjust example notebook content.
| File | Description |
|---|---|
| tests/primitives/pauli/pauli_exp/test_pauli_exp.py | Adds dagger validation and changes identity-string expectations to a no-op unitary. |
| pyproject.toml | Raises minimum guppylang version to pick up needed unitary/modifier functionality. |
| guppyalgos/primitives/pauli/pauli_exp/pauli_exp.py | Implements unitary gadget path with custom modifiers, plus special handling for identity Pauli strings. |
| examples/pauli_exponential/pauli_exponential.ipynb | Removes the RUS rotation swap-in section from the example notebook. |
🧠 Review effort: Lite
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
Comment on lines
+159
to
+170
| pauli_indices = list(pauli_string.get_dict().keys()) | ||
|
|
||
| @guppy.comptime | ||
| @no_type_check | ||
| def pauli_gadget_fn(qreg: array[qubit, n_qubits], angle: angle) -> None: | ||
| ladder = cx_ladder() | ||
| qubit_subset = [qreg[i] for i in pauli_indices] | ||
| if not has_unitary_rz: | ||
|
|
||
| basis_change(qreg) | ||
| @guppy | ||
| @no_type_check | ||
| def pauli_gadget_fn(qreg: array[qubit, n_qubits], angle: angle) -> None: | ||
| ladder = cx_ladder() | ||
| basis_change(qreg) | ||
| qubit_subset, borrowed_qreg = _take_pauli_qubits( | ||
| qreg, comptime(pauli_indices) | ||
| ) |
Comment on lines
+110
to
+150
| @guppy.unitary | ||
| class identity_gadget: | ||
| @guppy | ||
| @no_type_check | ||
| def __call__(qreg: array[qubit, n_qubits], angle: angle) -> None: | ||
| pass | ||
|
|
||
| @guppy | ||
| @no_type_check | ||
| def controlled[n_controls: nat]( | ||
| qreg: array[qubit, n_qubits], | ||
| angle: angle, | ||
| controls: array[qubit, n_controls], | ||
| ) -> None: | ||
| if n_controls == 1: | ||
| rz_method(controls[0], -angle / 2) | ||
| else: | ||
| phase_qreg = qarray(1) | ||
| with control(controls): | ||
| rz_method(phase_qreg[0], angle) | ||
| discard_array(phase_qreg) | ||
|
|
||
| @guppy | ||
| @no_type_check | ||
| def daggered(qreg: array[qubit, n_qubits], angle: angle) -> None: | ||
| pass | ||
|
|
||
| @guppy | ||
| @no_type_check | ||
| def ctrl_daggered[n_controls: nat]( | ||
| qreg: array[qubit, n_qubits], | ||
| angle: angle, | ||
| controls: array[qubit, n_controls], | ||
| ) -> None: | ||
| if n_controls == 1: | ||
| rz_method(controls[0], angle / 2) | ||
| else: | ||
| phase_qreg = qarray(1) | ||
| with control(controls): | ||
| rz_method(phase_qreg[0], -angle) | ||
| discard_array(phase_qreg) |
Comment on lines
+84
to
+91
| @guppy | ||
| @no_type_check | ||
| def main_dagger(state_qreg: array[qubit, n_state_qubits]) -> None: | ||
| with dagger: | ||
| pauli_g(state_qreg, angle(theta)) | ||
|
|
||
| dagger_u = get_unitary(main_dagger, n_state_qubits) | ||
| assert_allclose_ignorephase(u_mat.conj().T, dagger_u) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Refactors the
pauli_expmethod to return a Guppy unitary with custom modifiers.Closes #59