Skip to content

Commit

Permalink
Cleans up code and refactors tests for single qubit unitary decomposi…
Browse files Browse the repository at this point in the history
…tions (#4869)

**Context:**

As I am implementing the XZX single qubit decomposition
(#4862), I noticed some
issues with the the code and the tests for single qubit unitary
decompositions.

**Description of the Change:**

Cleans up ```transforms/decompositions/single_qubit_unitary.py```. 

- Removes duplicate code,
- Fixes doc examples that were untrue
- Adds support for returning global phase for the `rot` decomposition.
- Normalize all rotation angles to the range $[0, 4\pi]$

Refactors ```tests/transforms/test_decompositions.py```. 

- Generalizes logic for obtaining decompositions and asserting their
correctness such that all types of decompositions share the same
assertion logic. Removes duplicate code.
- Adds testing for when ```return_global_phase=False``` as well as when
```return_global_phase=True```
- Update test cases to use analytical instead of numerical values when
possible.

**Benefits:**

Cleaner code.

**Related GitHub Issues:**

#4868
#4862
  • Loading branch information
astralcai authored Nov 23, 2023
1 parent 1e6c11d commit b43e809
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 373 deletions.
6 changes: 6 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
* `GlobalPhase` now decomposes to nothing, in case devices do not support global phases.
[(#4855)](https://github.com/PennyLaneAI/pennylane/pull/4855)

* The `rot` decomposition now has support for returning a global phase.
[(#4869)](https://github.com/PennyLaneAI/pennylane/pull/4869)

<h3>Breaking changes 💔</h3>

* The decomposition of `GroverOperator` now has an additional global phase operation.
Expand Down Expand Up @@ -126,6 +129,9 @@
* Specifying `control_values` passed to `qml.ctrl` as a string is no longer supported.
[(#4816)](https://github.com/PennyLaneAI/pennylane/pull/4816)

* The `rot` decomposition will now normalize its rotation angles to the range `[0, 4pi]` for consistency
[(#4869)](https://github.com/PennyLaneAI/pennylane/pull/4869)

<h3>Deprecations 👋</h3>

* `qml.grad` and `qml.jacobian` now explicitly raise errors if trainable parameters are integers.
Expand Down
Loading

0 comments on commit b43e809

Please sign in to comment.