Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Jun 12, 2024
1 parent d10e15d commit 20d5b2b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
14 changes: 3 additions & 11 deletions src/qibo/gates/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2271,17 +2271,9 @@ def qasm_label(self):
return "ccx"

def decompose(self, *free, use_toffolis: bool = True) -> List[Gate]:
"""Decomposition of :math:`\\text{TOFFOLI}` gate.
Decompose :math:`\\text{TOFFOLI}` gate into :class:`qibo.gates.H`,
:class:`qibo.gates.T`, :class:`qibo.gates.TDG`, and
:class:`qibo.gates.CNOT`.
"""
from qibo.transpiler.decompositions import ( # pylint: disable=C0415
standard_decompositions,
)

return standard_decompositions(self)
c0, c1 = self.control_qubits
t = self.target_qubits[0]
return [self.__class__(c0, c1, t)]

def congruent(self, use_toffolis: bool = True) -> List[Gate]:
"""Congruent representation of ``TOFFOLI`` gate.
Expand Down
7 changes: 4 additions & 3 deletions tests/test_cirq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import numpy as np
import pytest

from qibo import gates, models
from qibo import Circuit, gates, matrices
from qibo.backends import NumpyBackend
from qibo.models import QFT
from qibo.quantum_info import random_statevector, random_unitary

numpy_backend = NumpyBackend()
Expand Down Expand Up @@ -54,7 +55,7 @@ def assert_gates_equivalent(
if ndevices is not None:
accelerators = {"/GPU:0": ndevices}

c = models.Circuit(nqubits, accelerators)
c = Circuit(nqubits, accelerators)
c.add(qibo_gate)
assert c.depth == target_depth
if accelerators and not backend.supports_multigpu:
Expand Down Expand Up @@ -307,7 +308,7 @@ def test_unitary_matrix_gate_controlled_by(backend, nqubits, ntargets, ndevices)

@pytest.mark.parametrize("nqubits", [5, 6, 7, 11, 12])
def test_qft(backend, accelerators, nqubits):
c = models.QFT(nqubits, accelerators=accelerators)
c = QFT(nqubits, accelerators=accelerators)
initial_state = random_statevector(2**nqubits, backend=numpy_backend)
final_state = backend.execute_circuit(c, np.copy(initial_state)).state()
final_state = backend.cast(final_state, dtype=final_state.dtype)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_gates_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from qibo import Circuit, gates, matrices
from qibo.parameter import Parameter
from qibo.quantum_info import random_hermitian, random_statevector, random_unitary
from qibo.transpiler.decompositions import standard_decompositions


def apply_gates(backend, gatelist, nqubits=None, initial_state=None):
Expand Down Expand Up @@ -1207,7 +1208,7 @@ def test_toffoli(backend, applyx):

# test decomposition
decomposition = Circuit(3)
decomposition.add(gates.TOFFOLI(0, 1, 2).decompose())
decomposition.add(standard_decompositions(gates.TOFFOLI(0, 1, 2)))
decomposition = decomposition.unitary(backend)

backend.assert_allclose(decomposition, backend.cast(matrices.TOFFOLI), atol=1e-10)
Expand Down

0 comments on commit 20d5b2b

Please sign in to comment.