Repository: PennyLaneAI/pennylane
Pull request #1546 (2021-08-17 17:52:18)

[Code Together] Add a deprecation warning for `qml.Interferometer` before renaming
**Context:**
 Add a deprecation warning for `qml.Interferometer` and a test case to check the warning.

**Description of the Change:**
- Added a `UserWarning` with a deprecation message to the `ops.cv.Interferometer` class explaining that it will be renamed to `InterferometerUnitary`.
- Added a test case to check if a warning is raised when creating the operation.

**Benefits:**
Informs users about the deprecation of `qml.Interferometer`.

**Related GitHub Issues:**
#1531


codecov[bot]: # [Codecov](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) Report
> Merging [#1546](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) (f0e0a9c) into [master](https://codecov.io/gh/PennyLaneAI/pennylane/commit/3e1cb0182683c294b3073cfb2d53109c463e1dc8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) (3e1cb01) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546/graphs/tree.svg?width=650&height=150&src=pr&token=9S3YzlUgGk&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI)](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI)

```diff
@@           Coverage Diff           @@
##           master    #1546   +/-   ##
=======================================
  Coverage   98.79%   98.79%           
=======================================
  Files         187      187           
  Lines       13395    13399    +4     
=======================================
+ Hits        13233    13237    +4     
  Misses        162      162           
```


| [Impacted Files](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) | Coverage Δ | |
|---|---|---|
| [pennylane/ops/cv.py](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI#diff-cGVubnlsYW5lL29wcy9jdi5weQ==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI). Last update [3e1cb01...f0e0a9c](https://codecov.io/gh/PennyLaneAI/pennylane/pull/1546?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).

thisac: Thanks @AkashNarayanan for working on this! We'll have a look at the PR and review it soon.
AkashNarayanan: Hi @thisac ! I have made the suggested changes.
thisac: Hi @AkashNarayanan! Thanks for making the changes. Looks good, so I'll approve and merge. 💯 

Patch:
diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md
index 71b3c48b1..063de1709 100644
--- a/.github/CHANGELOG.md
+++ b/.github/CHANGELOG.md
@@ -139,6 +139,11 @@ and requirements-ci.txt (unpinned). This latter would be used by the CI.
 
 <h3>Breaking changes</h3>
 
+* The class `qml.Interferometer` is deprecated and will be renamed `qml.InterferometerUnitary`
+  after one release cycle.
+  [(#1546)](https://github.com/PennyLaneAI/pennylane/pull/1546)
+
+
 <h3>Bug fixes</h3>
 
 * Fix bug when computing the specs of a circuit with a Hamiltonian observable.
@@ -150,7 +155,7 @@ and requirements-ci.txt (unpinned). This latter would be used by the CI.
 
 This release contains contributions from (in alphabetical order):
 
-Thomas Bromley, Josh Izaac, Prateek Jain, Johannes Jakob Meyer, Maria Schuld, Ingrid Strandberg.
+Thomas Bromley, Josh Izaac, Prateek Jain, Johannes Jakob Meyer, Akash Narayanan, Maria Schuld, Ingrid Strandberg.
 
 # Release 0.17.0 (current release)
 
diff --git a/pennylane/ops/cv.py b/pennylane/ops/cv.py
index 5718122ea..93f416c67 100644
--- a/pennylane/ops/cv.py
+++ b/pennylane/ops/cv.py
@@ -35,6 +35,8 @@ quantum operations supported by PennyLane, as well as their conventions.
 # As the qubit based ``decomposition``, ``_matrix``, ``diagonalizing_gates``
 # abstract methods are not defined in the CV case, disabling the related check
 # pylint: disable=abstract-method
+import warnings
+
 import math
 import numpy as np
 from scipy.linalg import block_diag
@@ -585,6 +587,16 @@ class Interferometer(CVOperation):
         U (array): A shape ``(len(wires), len(wires))`` complex unitary matrix
         wires (Sequence[int] or int): the wires the operation acts on
     """
+
+    def __init__(self, *args, **kwargs):
+        warnings.warn(
+            "'Interferometer' is deprecated and will be renamed 'InterferometerUnitary'",
+            UserWarning,
+            stacklevel=2,
+        )
+
+        super().__init__(*args, **kwargs)
+
     num_params = 1
     num_wires = AnyWires
     par_domain = "A"


Test patch:
diff --git a/tests/ops/test_cv_ops.py b/tests/ops/test_cv_ops.py
index f10f53169..6b0f69646 100644
--- a/tests/ops/test_cv_ops.py
+++ b/tests/ops/test_cv_ops.py
@@ -70,6 +70,14 @@ class TestCV:
         np_testing.assert_allclose(res2, np.eye(size), atol=tol)
         assert op.wires == op_d.wires
 
+    def test_Interferometer_deprecation_warning(self):
+        """Tests whether a ``UserWarning`` is raised when ``Interferometer`` gate is used."""
+        with pytest.warns(
+            UserWarning,
+            match="'Interferometer' is deprecated and will be renamed 'InterferometerUnitary'",
+        ):
+            cv.Interferometer(np.array([[1, 1], [1, -1]]) * -1.0j / np.sqrt(2.0), wires=1)
+
     @pytest.mark.parametrize(
         "op",
         [