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

Support controlled ZYZ decomposition of composite operators #5242

Merged
merged 8 commits into from
Feb 22, 2024

Conversation

Mandrenkov
Copy link
Contributor

Context:

Attempting to run the preliminary example from the QSVT in Practice demo with the Lightning Qubit device

import pennylane as qml
from pennylane import numpy as pnp

dev = qml.device("lightning.qubit", wires=[0, 1])

A = pnp.array([[0.1, 0.2], [0.3, 0.4]])
phase_angles = pnp.array([0.0, 1.0, 2.0, 3.0])


@qml.qnode(dev)
def my_circuit(phase_angles):
    qml.qsvt(A, phase_angles, wires=[0, 1])
    return qml.state()

print(my_circuit(phase_angles))

yields the error

  File "/Users/.../PennyLane-0.35.0.dev0-py3.11.egg/pennylane/ops/op_math/controlled_decompositions.py", line 188, in ctrl_decomp_zyz
    phi, theta, omega = target_operation.single_qubit_rot_angles()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Prod' object has no attribute 'single_qubit_rot_angles'

Description of the Change:

  • Updated ctrl_decomp_zyz() to support Operators that are not Operations.
  • Trimmed trailing whitespace from the changelog (done automatically by VS Code).

Benefits:

  • The QSVT in Practice demo can be executed on the Lightning Qubit device.

Possible Drawbacks:

None.

Related GitHub Issues:

None.

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e166f7e) 99.68% compared to head (dc5bf45) 99.67%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5242      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.01%     
==========================================
  Files         399      399              
  Lines       36848    36567     -281     
==========================================
- Hits        36731    36449     -282     
- Misses        117      118       +1     

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

@Mandrenkov Mandrenkov marked this pull request as ready for review February 21, 2024 16:28
Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

since we were already doing the try-except thing, do you know if it hurts to instead just update the except to catch (NotImplementedError, AttributeError)?

@Mandrenkov
Copy link
Contributor Author

Thanks for taking a look, @timmysilv!

since we were already doing the try-except thing, do you know if it hurts to instead just update the except to catch (NotImplementedError, AttributeError)?

That also works! The main difference is that that doing so would also catch AttributeErrors inside the implementation of single_qubit_rot_angles() which might not be preferable. I opted for the if-else approach because:

  1. It explicitly documents the assumption that the Operator is an Operation (in that branch).
  2. In my opinion,AttributeError is a bit too broad of an exception to catch. A lot of silly mistakes can get caught here which are better left exposed (and subsequently fixed).

@Mandrenkov
Copy link
Contributor Author

Thanks for the review, @albi3ro!

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.

Thanks for the updates :)

@Mandrenkov Mandrenkov enabled auto-merge (squash) February 22, 2024 15:38
@Mandrenkov Mandrenkov merged commit 3407a9e into master Feb 22, 2024
39 checks passed
@Mandrenkov Mandrenkov deleted the sc-56851-ctrl-decomp-zyz-composite-op branch February 22, 2024 17:05
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