Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into qibo_routing
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillermoAbadLopez committed Oct 30, 2024
2 parents 150bf42 + fe0e669 commit 3b24989
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 388 deletions.
18 changes: 8 additions & 10 deletions src/qililab/digital/circuit_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import networkx as nx
import numpy as np
from qibo import gates
from qibo.gates import Gate, M
from qibo.models import Circuit
from qibo.transpiler.placer import Placer
from qibo.transpiler.router import Router
Expand Down Expand Up @@ -101,7 +100,6 @@ def transpile_circuits(
# Non-Default Trivial placer, and Default Router, but with its kwargs specified:
pulse_sched, final_layouts = transpiler.transpile_circuit([c], placer=Trivial, router=(Sabre, {"lookahead": 2}))
Args:
circuits (list[Circuit]): list of qibo circuits.
placer (Placer | type[Placer] | tuple[type[Placer], dict], optional): `Placer` instance, or subclass `type[Placer]` to
Expand Down Expand Up @@ -314,11 +312,11 @@ def circuit_to_pulses(self, circuits: list[Circuit]) -> list[PulseSchedule]:

# Measurement gates need to be handled on their own because qibo allows to define
# an M gate as eg. gates.M(*range(5))
if isinstance(gate, M):
if isinstance(gate, gates.M):
gate_schedule = []
gate_qubits = gate.qubits
for qubit in gate_qubits:
gate_schedule += self._gate_schedule_from_settings(M(qubit))
gate_schedule += self._gate_schedule_from_settings(gates.M(qubit))

# handle control gates
else:
Expand All @@ -341,8 +339,8 @@ def circuit_to_pulses(self, circuits: list[Circuit]) -> list[PulseSchedule]:
pulse_event = self._gate_element_to_pulse_event(time=start_time, gate=gate, gate_event=gate_event)
# pop first qubit from gate if it is measurement
# this is so that the target qubit for multiM gates is every qubit in the M gate
if isinstance(gate, M):
gate = M(*gate.qubits[1:])
if isinstance(gate, gates.M):
gate = gates.M(*gate.qubits[1:])
# add event
delay = self.digital_compilation_settings.buses[gate_event.bus].delay
pulse_schedule.add_event(pulse_event=pulse_event, bus_alias=gate_event.bus, delay=delay) # type: ignore
Expand All @@ -358,7 +356,7 @@ def circuit_to_pulses(self, circuits: list[Circuit]) -> list[PulseSchedule]:

return pulse_schedule_list

def _gate_schedule_from_settings(self, gate: Gate) -> list[GateEventSettings]:
def _gate_schedule_from_settings(self, gate: gates.Gate) -> list[GateEventSettings]:
"""Gets the gate schedule. The gate schedule is the list of pulses to apply
to a given bus for a given gate
Expand Down Expand Up @@ -418,7 +416,7 @@ def _get_total_schedule_duration(self, schedule: list[GateEventSettings]) -> int
time = max(time, schedule_element.pulse.duration + schedule_element.wait_time)
return time

def _get_gate_qubits(self, gate: Gate, schedule: list[GateEventSettings] | None = None) -> tuple[int, ...]:
def _get_gate_qubits(self, gate: gates.Gate, schedule: list[GateEventSettings] | None = None) -> tuple[int, ...]:
"""Gets qubits involved in gate. This includes gate.qubits but also qubits which are targets of
buses in the gate schedule
Expand All @@ -444,7 +442,7 @@ def _get_gate_qubits(self, gate: Gate, schedule: list[GateEventSettings] | None

return tuple(set(schedule_qubits + gate_qubits)) # convert to set and back to list to remove repeated items

def _gate_element_to_pulse_event(self, time: int, gate: Gate, gate_event: GateEventSettings) -> PulseEvent:
def _gate_element_to_pulse_event(self, time: int, gate: gates.Gate, gate_event: GateEventSettings) -> PulseEvent:
"""Translates a gate element into a pulse.
Args:
Expand All @@ -467,7 +465,7 @@ def _gate_element_to_pulse_event(self, time: int, gate: Gate, gate_event: GateEv
bus = self.digital_compilation_settings.buses[gate_event.bus]
qubit = (
gate.qubits[0]
if isinstance(gate, M)
if isinstance(gate, gates.M)
else next((qubit for qubit in bus.qubits), None)
if bus is not None
else None
Expand Down
6 changes: 5 additions & 1 deletion tests/digital/test_circuit_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import networkx as nx

from qililab.digital import CircuitTranspiler
from qililab.digital.circuit_router import CircuitRouter
from qililab.digital.native_gates import Drag, Wait
from qililab.pulse import PulseSchedule
from qililab.settings.digital import DigitalCompilationSettings

from qililab.digital import CircuitTranspiler
from qililab.digital.native_gates import Drag, Wait
from qililab.pulse import PulseSchedule
from qililab.settings.digital import DigitalCompilationSettings
Expand Down
Loading

0 comments on commit 3b24989

Please sign in to comment.