Skip to content

Commit

Permalink
fixed matrices for ecr, ch, iswap, dcx, csx
Browse files Browse the repository at this point in the history
  • Loading branch information
01110011011101010110010001101111 committed Aug 25, 2023
1 parent 5dc4ab8 commit 86e2255
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion test/operator/test_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_op():
qiskit_matrix = pair["qiskit"]().to_matrix()
tq_matrix = pair["tq"].matrix.numpy()
tq_matrix = switch_little_big_endian_matrix(tq_matrix)
# assert np.allclose(qiskit_matrix, tq_matrix)
assert np.allclose(qiskit_matrix, tq_matrix)
else:
for k in tqdm(range(RND_TIMES)):
rnd_params = np.random.rand(pair["tq"].num_params).tolist()
Expand Down
21 changes: 10 additions & 11 deletions torchquantum/functional/functionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ def r_matrix(params: torch.Tensor) -> torch.Tensor:
],
dtype=C_DTYPE,
),
"ecr": torch.tensor(
"ecr": INV_SQRT2 * torch.tensor(
[[0, 0, 1, 1j], [0, 0, 1j, 1], [1, -1j, 0, 0], [-1j, 1, 0, 0]], dtype=C_DTYPE
),
"sdg": torch.tensor([[1, 0], [0, -1j]], dtype=C_DTYPE),
Expand All @@ -1432,14 +1432,14 @@ def r_matrix(params: torch.Tensor) -> torch.Tensor:
"chadamard": torch.tensor(
[
[1, 0, 0, 0],
[0, INV_SQRT2, 0, INV_SQRT2],
[0, 0, 1, 0],
[0, INV_SQRT2, 0, -INV_SQRT2],
[0, 1, 0, 0],
[0, 0, INV_SQRT2, INV_SQRT2],
[0, 0, INV_SQRT2, -INV_SQRT2],
],
dtype=C_DTYPE,
),
"iswap": torch.tensor(
[[1, 0, 0, 0], [0, 1j, 0, 0], [0, 0, 1j, 0], [0, 0, 0, 1]], dtype=C_DTYPE
[[1, 0, 0, 0], [0, 0, 1j, 0], [0, 1j, 0, 0], [0, 0, 0, 1]], dtype=C_DTYPE
),
"ccz": torch.tensor(
[
Expand All @@ -1463,13 +1463,12 @@ def r_matrix(params: torch.Tensor) -> torch.Tensor:
"csx": torch.tensor(
[
[1, 0, 0, 0],
[0, 0.5 + 0.5j, 0, 0.5 - 0.5j],
[0, 0, 1, 0],
[0, 0.5 - 0.5j, 0, 0.5 + 0.5j],
[0, 1, 0, 0],
[0, 0, 0.5 + 0.5j, 0.5 - 0.5j],
[0, 0, 0.5 - 0.5j, 0.5 + 0.5j],
],
dtype=C_DTYPE,
)
/ np.sqrt(2),
),
"rx": rx_matrix,
"ry": ry_matrix,
"rz": rz_matrix,
Expand Down Expand Up @@ -1499,7 +1498,7 @@ def r_matrix(params: torch.Tensor) -> torch.Tensor:
"singleexcitation": singleexcitation_matrix,
"qft": qft_matrix,
"dcx": torch.tensor(
[[1, 0, 0, 0], [0, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0]], dtype=C_DTYPE
[[1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [0, 1, 0, 0]], dtype=C_DTYPE
),
"xxminyy": xxminyy_matrix,
"xxplusyy": xxplusyy_matrix,
Expand Down

0 comments on commit 86e2255

Please sign in to comment.