Skip to content

Commit

Permalink
refactor shortest paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone-Bordoni committed Dec 11, 2023
1 parent 6ada47c commit d587786
Show file tree
Hide file tree
Showing 4 changed files with 388 additions and 381 deletions.
24 changes: 23 additions & 1 deletion src/qibo/transpiler/placer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from qibo.models import Circuit
from qibo.transpiler.abstract import Placer, Router
from qibo.transpiler.exceptions import PlacementError
from qibo.transpiler.router import _find_gates_qubits_pairs


def assert_placement(
Expand Down Expand Up @@ -60,6 +59,29 @@ def assert_mapping_consistency(layout: dict, connectivity: nx.Graph = None):
)


def _find_gates_qubits_pairs(circuit: Circuit):
"""Helper method for :meth:`qibo.transpiler.placer`.
Translate qibo circuit into a list of pairs of qubits to be used by the router and placer.
Args:
circuit (:class:`qibo.models.circuit.Circuit`): circuit to be transpiled.
Returns:
gates_qubits_pairs (list): list containing pairs of qubits targeted by two qubits gates.
"""
gates_qubits_pairs = []
for gate in circuit.queue:
if isinstance(gate, gates.M):
pass
elif len(gate.qubits) == 2:
gates_qubits_pairs.append(sorted(gate.qubits))
elif len(gate.qubits) >= 3:
raise_error(
ValueError, "Gates targeting more than 2 qubits are not supported"
)
return gates_qubits_pairs


class Trivial(Placer):
"""Place qubits according to the following notation:
Expand Down
Loading

0 comments on commit d587786

Please sign in to comment.