Skip to content

Conversation

@Qottmann
Copy link
Contributor

@Qottmann Qottmann commented Sep 8, 2025

requested by Diego
Usage would look something like this:

import pennylane as qml
import numpy as np
from functools import partial
from pennylane.transforms.rz_phase_gradient import rz_phase_gradient

precision = 3
phi = (1/2 + 1/4 + 1/8) * 2 * np.pi
wire="targ"
aux_wires = [f"aux_{i}" for i in range(precision)]
phase_grad_wires = [f"qft_{i}" for i in range(precision)]
work_wires = [f"work_{i}" for i in range(precision-1)]
wire_order = [wire] + aux_wires + phase_grad_wires + work_wires

def phase_gradient(wires):
    qml.X(wires[-1])
    qml.QFT(wires)

@partial(qml.transforms.rz_phase_gradient, aux_wires=aux_wires, phase_grad_wires=phase_grad_wires, work_wires=work_wires)
@qml.qnode(qml.device("default.qubit"))
def rz_circ(phi, wire):
    qml.Hadamard(wire) # prepare |+>
    phase_gradient(phase_grad_wires) # prepare phase gradient state

    qml.RZ(phi, wire)

    qml.adjoint(phase_gradient)(phase_grad_wires)
    qml.Hadamard(wire)

    return qml.probs(wire)

rz_circ(phi, wire)
# array([0.85355339, 0.14644661])

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2025

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented Sep 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.39%. Comparing base (5e0f279) to head (e1234f5).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8213      +/-   ##
==========================================
- Coverage   99.40%   99.39%   -0.01%     
==========================================
  Files         562      563       +1     
  Lines       58197    58232      +35     
==========================================
+ Hits        57848    57882      +34     
- Misses        349      350       +1     

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

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Already looks like a very nice version to me!
Main points:

  • Naming/number of registers for aux/work
  • Use of ChangeOpBasis

And then more tests for multiple RZ gates, different precisions and the like, once you're going for the finish line :)

@Qottmann Qottmann changed the title [WIP] RZ Phase gradient method transform RZ Phase gradient method transform Sep 10, 2025
@DSGuala
Copy link
Contributor

DSGuala commented Sep 10, 2025

[sc-99057]

Copy link
Contributor

@DSGuala DSGuala left a comment

Choose a reason for hiding this comment

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

Nice work! Let me know if you want to have a chat to go through the comments together more quickly 🙂

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Nice, thanks @Qottmann
Just some docs polishing/render debugging before approving :)

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

🎉

Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

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

Great work! Nice to see this in PL 🚀

@KetpuntoG
Copy link
Contributor

@Qottmann, don't forget the changelog

Copy link
Contributor

@DSGuala DSGuala left a comment

Choose a reason for hiding this comment

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

Thanks! Really nicely documented now. Approved after final comments are addressed 🥳

@Qottmann Qottmann enabled auto-merge September 22, 2025 09:57
@Qottmann Qottmann added this pull request to the merge queue Sep 22, 2025
Merged via the queue into master with commit 15ba966 Sep 22, 2025
52 checks passed
@Qottmann Qottmann deleted the phase-gradient branch September 22, 2025 10:35
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.

5 participants