1515qml .decomposition .enable_graph ()
1616
1717
18- @decomposition_rule (base = qml .adjoint (qml .RZ (float , wires = 0 )))
18+ @decomposition_rule (op = qml .adjoint (qml .RZ (float , wires = 1 )))
1919def adjoint_rotation (phi , wires , base , ** __ ):
2020 """Decompose the adjoint of a rotation operator by inverting the angle."""
2121 _ , struct = base ._flatten ()
2222 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+ )
2347
2448
2549@qml .qjit ()
@@ -29,7 +53,9 @@ def circuit():
2953
3054 qml .adjoint (qml .RY (0.432 , wires = 1 ))
3155
32- adjoint_rotation (float , int )
56+ adjoint_rotation (float )
57+ cancel_adjoint ()
58+ flip_control_adjoint ()
3359
3460 return qml .expval (qml .Z (0 ))
3561
0 commit comments