Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create gates.CY #158

Merged
merged 8 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers=[
[tool.poetry.dependencies]
python=">=3.8.0,<3.12"
numba=">=0.51.0"
qibo=">=0.2.2"
qibo={ git = "https://github.com/qiboteam/qibo.git@controlled_y" }
scipy = "^1.10.1"
psutil = "^5.9.5"

Expand Down
3 changes: 2 additions & 1 deletion src/qibojit/backends/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"TOFFOLI": "apply_x",
"Y": "apply_y",
"Z": "apply_z",
"CY": "apply_y",
"CZ": "apply_z",
"U1": "apply_z_pow",
"CU1": "apply_z_pow",
Expand Down Expand Up @@ -176,7 +177,7 @@ def apply_gate(self, gate, state, nqubits):

def apply_gate_density_matrix(self, gate, state, nqubits, inverse=False):
name = gate.__class__.__name__
if name == "Y":
if name in ["Y", "CY"]:
return self._apply_ygate_density_matrix(gate, state, nqubits)
if inverse:
# used to reset the state when applying channels
Expand Down
4 changes: 4 additions & 0 deletions src/qibojit/backends/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class CuQuantumMatrices(NumpyMatrices):
def CNOT(self):
return self.X

@cached_property
def CY(self):
return self.Y

@cached_property
def CZ(self):
return self.Z
Expand Down
24 changes: 24 additions & 0 deletions src/qibojit/tests/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ def test_apply_two_qubit_base(backend, nqubits, targets, use_qubits, dtype):
backend.assert_allclose(state, target_state, atol=ATOL.get(dtype))


@pytest.mark.parametrize(
("nqubits", "targets"),
[
(2, [0, 1]),
(3, [0, 2]),
(4, [1, 3]),
(3, [1, 2]),
(4, [0, 2]),
(4, [2, 3]),
(5, [3, 4]),
(6, [1, 4]),
],
)
def test_apply_cy(backend, nqubits, targets, dtype):
tbackend = NumpyBackend()
state = random_statevector(2**nqubits, backend=tbackend).astype(dtype)
gate = gates.CY(*targets)

set_precision(dtype, backend, tbackend)
target_state = tbackend.apply_gate(gate, np.copy(state), nqubits)
state = backend.apply_gate(gate, np.copy(state), nqubits)
backend.assert_allclose(state, target_state, atol=ATOL.get(dtype))


@pytest.mark.parametrize(
("nqubits", "targets"),
[
Expand Down
Loading