-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controlled operations rework Part 1 (#5125)
**Context:** All controlled operations should inherit from the general Controlled class, and the decomposition of controlled operations is not consistent for custom and non-custom controlled operations. This is a continuation of #5069 This is the first PR out of two for this rework. The second PR will focus on making sure that all custom controlled operations inherit from Controlled for more consistent inheritance structure. **Description of the Change:** - Make `MultiControlledX` inherit from ControlledOp. - `qml.ctrl` called on operators with custom controlled versions will return instances of the custom class. - Special handling of `PauliX` based controlled operations (`PauliX`, `CNOT`, `Toffoli`, `MultiControlledX`) - Calling `qml.ctrl` on one of these operators will always resolve to the best option in `CNOT`, `Toffoli`, or `MultiControlledX` depending on the number of control wires and control values. - `qml.ctrl` will flatten nested controlled operators to a single multi-controlled operation. - Controlled operators with a custom controlled version decomposes like how their controlled counterpart decomposes, as opposed to decomposing into their controlled version. - Special handling of `PauliX` based controlled operations: e.g., `Controlled(CNOT([0, 1]), [2, 3])` will have the same decomposition behaviour as a `MultiControlledX([2, 3, 0, 1])` **Benefits:** Cleaner code and more consistent behaviour **Possible Drawbacks:** Change of decomposition behaviour may cause issues. ~For `MultiControlledX`, the `wires` attribute now refers to all wires, as in `control_wires + target_wire + work_wires`, to access only the `control_wires + target_wires`, use the `active_wires` attribute.~ **Related GitHub Issues:** #5069 #1447 **Related Shortcut Stories** [sc-55949] [sc-55131] [sc-55358] --------- Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
- Loading branch information
1 parent
9555cdd
commit d0c435d
Showing
20 changed files
with
1,565 additions
and
1,253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.