Describe the bug
CNOT(0,1).to_matrix() returns
$$
\begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 \\
0 & 0 & 1 & 0 \\
0 & 1 & 0 & 0
\end{pmatrix}
$$
but I expect it to be
$$
\begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
0 & 0 & 1 & 0
\end{pmatrix}
$$
In comparison, SWAP(0,1), H(0)+H(1) are as expected, and when rewriting CZ(0,1) with H(1)+CX(0,1)+H(1) it also is as expected.
The behaviour of the cirquit itself however is correct, so when CNOT(0,1) is applied to |10>, one gets |11> instead of |10> as the matrix would imply.
Note also that CNOT(1,0).to_matrix() returns the expected matrix of CNOT(0,1), and vice versa, so the control and target seem to be swapped.
To Reproduce
import tequila as tq
U = tq.gates.CNOT(control=0, target=1)
print(U.to_matrix().real)
for b in [tq.QubitWaveFunction.from_string(b) for b in ["|00>", "|01>", "|10>", "|11>"]]:
print(f"{b} -> {tq.simulate(objective=U, initial_state=b)}")
Expected behavior
Computer (please complete the following information):
tequila version: 1.9.10
python version: 3.10.12 (main, Nov 4 2025, 08:48:33) [GCC 11.4.0]
platform: #88~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Oct 14 14:03:14 UTC 2
Additional context
I am trying to verify excercise 1 from Quantum Computing sheet 8, which resulted in a different matrix than I calculated by hands.
Describe the bug
CNOT(0,1).to_matrix() returns
but I expect it to be
In comparison, SWAP(0,1), H(0)+H(1) are as expected, and when rewriting CZ(0,1) with H(1)+CX(0,1)+H(1) it also is as expected.
The behaviour of the cirquit itself however is correct, so when CNOT(0,1) is applied to |10>, one gets |11> instead of |10> as the matrix would imply.
Note also that CNOT(1,0).to_matrix() returns the expected matrix of CNOT(0,1), and vice versa, so the control and target seem to be swapped.
To Reproduce
Expected behavior
Computer (please complete the following information):
tequila version: 1.9.10
python version: 3.10.12 (main, Nov 4 2025, 08:48:33) [GCC 11.4.0]
platform: #88~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Oct 14 14:03:14 UTC 2
Additional context
I am trying to verify excercise 1 from Quantum Computing sheet 8, which resulted in a different matrix than I calculated by hands.