-
Notifications
You must be signed in to change notification settings - Fork 657
[Decomposition] Clean up custom logic for adjoint and pow #7352
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
base: symbolic-rules-01
Are you sure you want to change the base?
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## symbolic-rules-01 #7352 +/- ##
===================================================
Coverage 99.65% 99.65%
===================================================
Files 529 529
Lines 50600 50840 +240
===================================================
+ Hits 50424 50664 +240
Misses 176 176 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
if base_class in same_type_adjoint_ops(): | ||
return [same_type_adjoint_decomp] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch is now generalized away into operator specific symbolic decomposition rules
if ( | ||
issubclass(base_class, qml.ops.Pow) | ||
and base_params["base_class"] in same_type_adjoint_ops() | ||
): | ||
return [adjoint_pow_decomp] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is removed. There is no reason why we need to switch the order of adjoint
and pow
such that the adjoint
is applied first.
if ( | ||
issubclass(base_class, qml.ops.Controlled) | ||
and base_params["base_class"] in same_type_adjoint_ops() | ||
): | ||
return [adjoint_controlled_decomp] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also removed. There is no reason why we need to switch the order of ctrl
and adjoint
such that adjoint
is applied first.
try: | ||
decomp_resource = rule.compute_resources(**op_node.params) | ||
d_node_idx = self._recursively_add_decomposition_node(rule, decomp_resource) | ||
self._graph.add_edge(d_node_idx, op_node_idx, 0) | ||
d_node = _DecompositionNode(rule, decomp_resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section is moved from another method.
# Special case: power of an adjoint | ||
if issubclass(base_class, qml.ops.Adjoint): | ||
return [flip_pow_adjoint] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually apply the pow
first, then adjoint
, because typically adjoint
does not turn the operator into a different type, but pow
might. For example, pow(SX, 2)
is a PauliX
. If we apply the adjoint
on the SX
first, SX
gets decomposed, while we could've just had PauliX
.
|
||
|
||
class AdjointDecomp(DecompositionRule): # pylint: disable=too-few-public-methods | ||
"""The adjoint version of a decomposition rule.""" | ||
def make_adjoint_decomp(base_decomposition: DecompositionRule): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as before. What's previously a subclass is now a method. There was no reason why it had to be a separate class.
|
||
|
||
@functools.lru_cache(maxsize=1) | ||
def same_type_adjoint_ops(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is completely removed, generalized to operator-specific adjoint decomposition rules.
Context:
Description of the Change:
Benefits:
Possible Drawbacks:
Related GitHub Issues:
[sc-90114]