# How to build the quantum circuit ansatz to implement a diagonal unitary operator with just 1 and -1 elements?

Let's consider a set of $$N = 2^n$$ binary values $$S_i \in \left\{-1, 1\right\}$$ and define the diagonal matrix $$W$$ as a quantum unitary operator acting on a system of $$n$$ qubits: $$W = \begin{pmatrix} S_1 & 0 & 0 & 0 & 0\\ 0 & S_2 & 0 & 0 & 0\\ 0 & 0 & \dots & 0 & 0\\ 0 & 0 & 0 & S_{N-1} & 0\\ 0 & 0 & 0 & 0 & S_N \end{pmatrix}$$ Is it possible to build a parameterized quantum circuit $$U(\theta)$$ to get all and only the unitary operators written as $$W$$ (with just $$1$$ or $$-1$$ on the main diagonal) varying the values of the $$\theta$$ parameters?

For example, if I consider the matrix: $$W_1 = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & -1 & 0\\ 0 & 0 & 0 & 1\\ \end{pmatrix}$$ the equivalent circuit can be built using the following Qiskit code:

import numpy as np
from qiskit import QuantumCircuit, transpile

W1 = np.diag([1, 1, -1, 1])

qc = QuantumCircuit(2)
qc.unitary(W1, qubits=[0, 1])

transpile(qc, basis_gates=['u', 'cx']).draw('mpl') However, if I consider another matrix as for instance $$W_2 = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & -1 & 0 & 0\\ 0 & 0 & -1 & 0\\ 0 & 0 & 0 & 1\\ \end{pmatrix}$$ the same piece of code gives me a different circuit: How can I build an ansatz for all the quantum unitary operators written like $$W$$?

• I don't think a parameterized ansatz will only produce such kind of diagonal unitary. You may find an ansatz that is able to give you all these diagonal unitary, but will not only get these stuff. Oct 23 at 5:37
• @Dran Not even if, having fixed the ansatz, I put constraints on the values of the parameters? Oct 23 at 6:55
• Then I don't see the point of making it into a parameterized ansatz with restricted input values. People parameterize the circuit mainly because they wanna optimize it for some loss function. Maybe you can elaborate more on the motivation of your question? Oct 23 at 7:06
• That's exactly what I want to do as well. But I also want to do it constraining the values of the parameters so that the unitary operator corresponding to the quantum circuit looks like a matrix written as $W$ Oct 23 at 7:23
• Can we assume any other constraints? For example, polynomially-many "-1"s Nov 5 at 12:10