Skip to content

Commit

Permalink
feat: Remove transpilation hook from Qibolab backend
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Apr 25, 2024
1 parent a514441 commit 33c3bf2
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,13 @@ def __init__(self, platform):
"qibolab": qibolab_version,
}
self.compiler = Compiler.default()
self.transpiler: Optional[Callable] = None

def apply_gate(self, gate, state, nqubits): # pragma: no cover
raise_error(NotImplementedError, "Qibolab cannot apply gates directly.")

def apply_gate_density_matrix(self, gate, state, nqubits): # pragma: no cover
raise_error(NotImplementedError, "Qibolab cannot apply gates directly.")

def transpile(self, circuit):
"""Applies the transpiler to a single circuit.
This transforms the circuit into proper connectivity and native
gates.
"""
# TODO: Move this method to transpilers
if self.transpiler is None or self.transpiler.is_satisfied(circuit):
native = circuit
qubit_map = {q: q for q in range(circuit.nqubits)}
else:
native, qubit_map = self.transpiler(circuit) # pylint: disable=E1102
return native, qubit_map

def assign_measurements(self, measurement_map, readout):
"""Assigning measurement outcomes to
:class:`qibo.states.MeasurementResult` for each gate.
Expand Down Expand Up @@ -92,8 +77,7 @@ def execute_circuit(self, circuit, initial_state=None, nshots=1000):
"Hardware backend only supports circuits as initial states.",
)

native_circuit, qubit_map = self.transpile(circuit)
sequence, measurement_map = self.compiler.compile(native_circuit, self.platform)
sequence, measurement_map = self.compiler.compile(circuit, self.platform)

if not self.platform.is_connected:
self.platform.connect()
Expand Down Expand Up @@ -136,11 +120,10 @@ def execute_circuits(self, circuits, initial_state=None, nshots=1000):
)

# TODO: Maybe these loops can be parallelized
native_circuits, _ = zip(*(self.transpile(circuit) for circuit in circuits))
sequences, measurement_maps = zip(
*(
self.compiler.compile(circuit, self.platform)
for circuit in native_circuits
for circuit in circuits
)
)

Expand Down

0 comments on commit 33c3bf2

Please sign in to comment.