Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: ctrl_decomp_zyz - isclose => allclose #5198

Merged
merged 8 commits into from
Feb 16, 2024

Conversation

vincentmr
Copy link
Contributor

@vincentmr vincentmr commented Feb 13, 2024

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:
While introducing C(Rot) in Lightning, the test below failed in ctrl_decomp_zyz because all the qml.math.isclose branches raise errors with gradient tracers.

import pennylane as qml
import pennylane.numpy as np

np.random.seed(1337)

dev = qml.device("default.qubit", wires=3)
target_wires = [2]
control_wires = [0, 1]
control_values = [True, True]
def circuit(p):
    qml.ctrl(
        qml.Rot(*p, wires=target_wires),
        control_wires,
        control_values=control_values,
    )
    return np.array([qml.expval(qml.PauliY(i)) for i in range(3)])

circ_ad = qml.QNode(circuit, dev, diff_method="adjoint")
par = np.array([0.1234, -np.pi / 7, 0.5678])
jac_ad = np.array(qml.jacobian(circ_ad)(par))

Description of the Change:
Change isclose by allclose as suggested by @albi3ro .

Benefits:

Possible Drawbacks:

Related GitHub Issues:

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3216650) 99.68% compared to head (d9e1735) 99.68%.
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5198      +/-   ##
==========================================
- Coverage   99.68%   99.68%   -0.01%     
==========================================
  Files         396      396              
  Lines       36661    36378     -283     
==========================================
- Hits        36547    36262     -285     
- Misses        114      116       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vincentmr vincentmr marked this pull request as ready for review February 13, 2024 21:01
@vincentmr vincentmr requested a review from a team February 13, 2024 21:16
@vincentmr
Copy link
Contributor Author

Rot decomposition isclose allclose [sc-56743]

@vincentmr vincentmr changed the title isclose => allclose Bugfix: ctrl_decomp_zyz - isclose => allclose Feb 13, 2024
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Mind adding some tests?

@vincentmr
Copy link
Contributor Author

Mind adding some tests?

No, some functional test like the example above would be good?

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
@vincentmr
Copy link
Contributor Author

@albi3ro I limited the changes to ctrl_decomp_zyz since the other functions are said to be non-autodifferentiable.

@vincentmr vincentmr enabled auto-merge (squash) February 16, 2024 22:00
@vincentmr vincentmr merged commit f7bba2b into master Feb 16, 2024
39 checks passed
@vincentmr vincentmr deleted the bugfix/ctrl_decomp_zyz_isclose branch February 16, 2024 22:02
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