15
15
qml .decomposition .enable_graph ()
16
16
17
17
18
- @decomposition_rule (base = qml .adjoint (qml .RZ (float , wires = 0 )))
18
+ @decomposition_rule (op = qml .adjoint (qml .RZ (float , wires = 1 )))
19
19
def adjoint_rotation (phi , wires , base , ** __ ):
20
20
"""Decompose the adjoint of a rotation operator by inverting the angle."""
21
21
_ , struct = base ._flatten ()
22
22
base ._unflatten ((- phi ,), struct )
23
+
24
+
25
+ @decomposition_rule (op = qml .adjoint (qml .adjoint (qml .Hadamard (wires = 0 ))))
26
+ def cancel_adjoint (* params , wires , base ):
27
+ """Decompose the adjoint of a rotation operator by inverting the angle."""
28
+ base .base ._unflatten (* base .base ._flatten ())
29
+
30
+ #
31
+ @decomposition_rule (op = qml .ctrl (qml .adjoint (qml .RX (0.2 , wires = [0 ])), control = 1 ))
32
+ def flip_control_adjoint (
33
+ * _ , wires , control_wires , control_values , work_wires , work_wire_type , base , ** __
34
+ ):
35
+ """Decompose the control of an adjoint by applying control to the base of the adjoint
36
+ and taking the adjoint of the control."""
37
+ base_op = base .base ._unflatten (* base .base ._flatten ())
38
+ qml .adjoint (
39
+ qml .ctrl (
40
+ base_op ,
41
+ control = wires [: len (control_wires )],
42
+ control_values = control_values ,
43
+ work_wires = work_wires ,
44
+ work_wire_type = work_wire_type ,
45
+ )
46
+ )
23
47
24
48
25
49
@qml .qjit ()
@@ -29,7 +53,9 @@ def circuit():
29
53
30
54
qml .adjoint (qml .RY (0.432 , wires = 1 ))
31
55
32
- adjoint_rotation (float , int )
56
+ adjoint_rotation (float )
57
+ cancel_adjoint ()
58
+ flip_control_adjoint ()
33
59
34
60
return qml .expval (qml .Z (0 ))
35
61
0 commit comments