diff --git a/src/qibo/gates/gates.py b/src/qibo/gates/gates.py index 2e726c02cd..54b02b45f2 100644 --- a/src/qibo/gates/gates.py +++ b/src/qibo/gates/gates.py @@ -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. diff --git a/tests/test_cirq.py b/tests/test_cirq.py index 636581656d..8ff8498d7a 100644 --- a/tests/test_cirq.py +++ b/tests/test_cirq.py @@ -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() @@ -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: @@ -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) diff --git a/tests/test_gates_gates.py b/tests/test_gates_gates.py index 902a49fa8e..2b2ae20973 100644 --- a/tests/test_gates_gates.py +++ b/tests/test_gates_gates.py @@ -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): @@ -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)