Repository: PennyLaneAI/pennylane (python)

Issue:
[BUG] The `_controlled` method of `DiagonalQubitUnitary` returns the wrong operation
### Expected behavior

`DiagonalQubitUnitary(D, wires=wires)._controlled(control=control)` queues the controlled version of the `DiagonalQubitUnitary`, controlled by the wires `control`, which should again be a `DiagonalQubitUnitary` with matrix dimension `2**(len(wires)+len(control))`.

### Actual behavior

`DiagonalQubitUnitary(D, wires=wires)._controlled(control=control)` queues a `DiagonalQubitUnitary` with diagonal `np.array([1, 1, *D])`, which in particular has the incorrect shape (except for the case of `len(D)=2`):
```python
O = qml.DiagonalQubitUnitary([-1, -1, -1, -1], wires=[0, 1])
with qml.tape.QuantumTape() as tape:
    O._controlled(control=2)
ctrl_O = tape.operations[0]
```
```pycon
>>> ctrl_O.get_matrix().shape
(6, 6)
>>> qml.math.diag(ctrl_O.get_matrix())
array([ 1,  1, -1, -1, -1, -1])
```

### Additional information

It is clear why this is happening:
```python
def _controlled(self, control):
    DiagonalQubitUnitary(
        qml.math.concatenate([np.array([1, 1]), self.parameters[0]]),
        wires=Wires(control) + self.wires,
   )
```
This code should instead read
```python
def _controlled(self, control):
    DiagonalQubitUnitary(
        qml.math.concatenate([np.ones_like(self.parameters[0]), self.parameters[0]]),
        wires=Wires(control) + self.wires,
   )
```

### Source code

_No response_

### Tracebacks

_No response_

### System information

```shell
Not relevant, bug source was found in source code.
```


### Existing GitHub issues

- [X] I have searched existing GitHub issues to make sure the issue does not already exist.

Pull request description:
Fix `DiagonalQubitUnitary._controlled`
Fixes #2522 by replacing
```python
qml.math.concatenate([np.array([1, 1]), self.parameters[0]]),
```
in `DiagonalQubitUnitary._controlled` with
```python
qml.math.concatenate([np.ones_like(self.parameters[0]), self.parameters[0]]),
```

Patch:
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 3b07fae6c..62e070a86 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -47,6 +47,12 @@
 
 <h3>Deprecations</h3>
 
+<h3>Bug fixes</h3>
+
+* Fixes a bug in `DiagonalQubitUnitary._controlled` where an invalid operation was queued
+  instead of the controlled version of the diagonal unitary.
+  [(#2525)](https://github.com/PennyLaneAI/pennylane/pull/2525)
+
 <h3>Documentation</h3>
 
 <h3>Contributors</h3>
diff --git a/pennylane/ops/qubit/matrix_ops.py b/pennylane/ops/qubit/matrix_ops.py
index 985d216ee..0e41e9250 100644
--- a/pennylane/ops/qubit/matrix_ops.py
+++ b/pennylane/ops/qubit/matrix_ops.py
@@ -441,7 +441,7 @@ class DiagonalQubitUnitary(Operation):
 
     def _controlled(self, control):
         DiagonalQubitUnitary(
-            qml.math.concatenate([np.array([1, 1]), self.parameters[0]]),
+            qml.math.concatenate([np.ones_like(self.parameters[0]), self.parameters[0]]),
             wires=Wires(control) + self.wires,
         )
 


Test patch:
diff --git a/tests/ops/qubit/test_matrix_ops.py b/tests/ops/qubit/test_matrix_ops.py
index a8d89d901..dbb811b81 100644
--- a/tests/ops/qubit/test_matrix_ops.py
+++ b/tests/ops/qubit/test_matrix_ops.py
@@ -232,6 +232,17 @@ class TestDiagonalQubitUnitary:
         assert np.allclose(decomp[0].data[0], np.diag(D))
         assert np.allclose(decomp2[0].data[0], np.diag(D))
 
+    def test_controlled(self):
+        """Test that the correct controlled operation is created when controlling a qml.DiagonalQubitUnitary."""
+        D = np.array([1j, 1, 1, -1, -1j, 1j, 1, -1])
+        op = qml.DiagonalQubitUnitary(D, wires=[1, 2, 3])
+        with qml.tape.QuantumTape() as tape:
+            op._controlled(control=0)
+        mat = qml.matrix(tape)
+        assert qml.math.allclose(
+            mat, qml.math.diag(qml.math.append(qml.math.ones(8, dtype=complex), D))
+        )
+
     def test_matrix_representation(self, tol):
         """Test that the matrix representation is defined correctly"""
         diag = np.array([1, -1])