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

Remove transpilation hook #884

Merged
merged 3 commits into from
May 10, 2024
Merged
Changes from 2 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
25 changes: 2 additions & 23 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections import deque
from typing import Callable, Optional

import numpy as np
from qibo import __version__ as qibo_version
Expand Down Expand Up @@ -29,28 +28,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 +76,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,12 +119,8 @@ 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
)
*(self.compiler.compile(circuit, self.platform) for circuit in circuits)
)

if not self.platform.is_connected:
Expand Down
Loading