quri_parts.circuit.topology package#

class quri_parts.circuit.topology.SquareLattice(xsize: int, ysize: int, qubit_to_coord: Mapping[int, tuple[int, int]] | None = None)#

Bases: object

Represents qubits connected in a rectangular lattice with no missing pieces, and searches for the shortest path between any two qubits.

  • xsize – Size of lattice in x direction.

  • ysize – Size of lattice in y direction.

  • coord_to_qubit – Mapping from coordinates to qubit indices. If omitted, it is automatically assigned from the origin with x changing first.

get_qubit(coord: tuple[int, int]) int#

Returns qubit index corresponding to the given coordinate.

get_coord(qubit: int) tuple[int, int]#

Returns coordinate corresponding to the given qubit index.

is_adjacent(qubit_a: int, qubit_b: int) bool#

Check if the given qubits are directory connected to each other on the lattice.

qubit_path(qubit_a: int, qubit_b: int) Sequence[int]#

Returns sequence of qubits on the shortest path between the coordinates of two qubits.

  • qubit_a – Qubit index at the starting point.

  • qubit_b – Qubit index at the end point.

class quri_parts.circuit.topology.SquareLatticeSWAPInsertionTranspiler(square_lattice: SquareLattice)#

Bases: GateDecomposer

When the connection of qubits is expressed in SquareLattice, insert SWAPs as appropriate before and after for gates applied between two qubits that are not connected to each other.

is_target_gate(gate: QuantumGate) bool#

Determine if a given gate is subject to decomposition.


gate – Gates in the circuit that are scanned from the front.

decompose(gate: QuantumGate) Sequence[QuantumGate]#

Describe the specific decomposition process. Only the target gates satisfying is_target_gate() method are passed.


gate – The gates to be decomposed.