qrunch.quantum.circuits.synthesis.layout.hardware_mapping_utils

Module containing classes for describing qubit connections on quantum hardware.

Classes

DeviceData

Class for handling device data.

LogicalQubit

Dataclass for a logical qubit.

PhysicalQubit

Dataclass for a physical qubit.

QubitConnection

Dataclass for storing one hardware connection between two physical qubits.

QubitConnectionGraph

Class for holding a coupling graph for qubits on hardware.

QubitMap

Class for holding a map between physical and logical qubits.

class DeviceData

Bases: object

Class for handling device data.

Parameters:
  • name – name of the device

  • num_qubits – number of qubits the device has

  • single_qubit_fidelities – single qubit fidelities indexed by qubit id

  • two_qubit_fidelities – two qubit fidelities indexed by qubit id pairs

  • readout_fidelities – readout fidelities indexed by qubit id

  • original_noise_model – original noise model if available. The original third party noise model will contain more information about the device, but is not standardized across different providers. This will be used, if the backend supports it.

__init__(name: str, qubits: list[PhysicalQubit], single_qubit_errors: dict[PhysicalQubit, float], two_qubit_errors: dict[QubitConnection[PhysicalQubit], float], readout_errors: dict[PhysicalQubit, float], original_noise_model: Any | None = None) None
Parameters:
Return type:

None

property connection_graph: QubitConnectionGraph[PhysicalQubit]

Return the connection graph.

classmethod from_mean_errors(name: str, num_qubits: int, mean_single_qubit_error: float, mean_two_qubit_error: float, mean_readout_error: float, connection_graph: QubitConnectionGraph[PhysicalQubit] | None = None, original_noise_model: Any | None = None) DeviceData

Create device data from mean errors.

Parameters:
  • name (str) – name of the device

  • num_qubits (int) – number of qubits the device has

  • connection_graph (QubitConnectionGraph[PhysicalQubit] | None) – connection graph of the device

  • mean_single_qubit_error (float) – mean single qubit error

  • mean_two_qubit_error (float) – mean two qubit error

  • mean_readout_error (float) – mean readout error

  • original_noise_model (Any | None) – original noise model if available

Return type:

DeviceData

property mean_readout_error: float

Return the mean readout error.

property mean_single_qubit_error: float

Return the mean single qubit error.

property mean_two_qubit_error: float

Return the mean two qubit error.

property median_readout_error: float

Return the median readout error.

property median_single_qubit_error: float

Return the median single qubit error.

property median_two_qubit_error: float

Return the median two qubit error.

name: str
property num_qubits: int

Return the number of qubits in the device.

original_noise_model: Any | None = None
qubits: list[PhysicalQubit]
readout_errors: dict[PhysicalQubit, float]
remove_qubit(qubit_to_remove: PhysicalQubit) DeviceData

Create a new DeviceData instance with the specified qubit removed.

Parameters:

qubit_to_remove (PhysicalQubit)

Return type:

DeviceData

single_qubit_errors: dict[PhysicalQubit, float]
two_qubit_errors: dict[QubitConnection[PhysicalQubit], float]
class LogicalQubit

Bases: object

Dataclass for a logical qubit.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:

index – The index of the logical qubit.

__init__(index: int) None
Parameters:

index (int)

Return type:

None

index: int
class PhysicalQubit

Bases: object

Dataclass for a physical qubit.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:

index – The index of the physical qubit.

__init__(index: int) None
Parameters:

index (int)

Return type:

None

index: int
class QubitConnection

Bases: Generic[QubitTypeVar]

Dataclass for storing one hardware connection between two physical qubits.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:
  • qubit_1 – Index of the first qubit in the connection.

  • qubit_2 – Index of the second qubit in the connection.

__init__(qubit_1: QubitTypeVar, qubit_2: QubitTypeVar) None
Parameters:
  • qubit_1 (QubitTypeVar)

  • qubit_2 (QubitTypeVar)

Return type:

None

classmethod from_logical_indices(index_1: int, index_2: int) QubitConnection[LogicalQubit]

Create qubit connection between two logical qubits from integer indices.

Parameters:
  • index_1 (int) – Index of the first logical qubit.

  • index_2 (int) – Index of the second logical qubit.

Return type:

QubitConnection[LogicalQubit]

classmethod from_physical_indices(index_1: int, index_2: int) QubitConnection[PhysicalQubit]

Create qubit connection between two physical qubits from integer indices.

Parameters:
  • index_1 (int) – Index of the first physical qubit.

  • index_2 (int) – Index of the second physical qubit.

Return type:

QubitConnection[PhysicalQubit]

property indices: tuple[int, int]

Indices for the connected qubits.

qubit_1: QubitTypeVar
qubit_2: QubitTypeVar
property qubits: tuple[QubitTypeVar, QubitTypeVar]

Tuple of the two qubits.

class QubitConnectionGraph

Bases: Generic[QubitTypeVar]

Class for holding a coupling graph for qubits on hardware.

__init__(qubit_connections: list[QubitConnection[QubitTypeVar]]) None

Initialize hardware coupling map from a list of qubit connections.

Parameters:

qubit_connections (list[QubitConnection[QubitTypeVar]]) – List of qubit connections on the hardware.

Return type:

None

conjugate() Iterator[QubitConnection[QubitTypeVar]]

Iterate through the qubit connections not in the graph.

Yields:

Qubit connection not in the graph.

Return type:

Iterator[QubitConnection[QubitTypeVar]]

exclude_qubits(qubits_to_exclude: set[QubitTypeVar]) QubitConnectionGraph[QubitTypeVar]

Create a new QubitConnectionGraph excluding the specified qubits.

Parameters:

qubits_to_exclude (set[QubitTypeVar]) – Set of qubits to exclude from the new graph.

Return type:

QubitConnectionGraph[QubitTypeVar]

classmethod from_all_to_all_connected_physical_qubits(num_qubits: int) QubitConnectionGraph[PhysicalQubit]

Get all-to-all qubit connections.

Returns:

List of all-to-all qubit connections.

Parameters:

num_qubits (int)

Return type:

QubitConnectionGraph[PhysicalQubit]

classmethod from_linearly_connected_physical_qubits(num_qubits: int) QubitConnectionGraph[PhysicalQubit]

Get linearly connected qubit connections.

Returns:

List of linearly connected qubit connections.

Parameters:

num_qubits (int)

Return type:

QubitConnectionGraph[PhysicalQubit]

classmethod from_square_lattice_connected_physical_qubits(num_qubits_per_side: int) QubitConnectionGraph[PhysicalQubit]

Get square lattice qubit connections.

Returns:

List of square lattice qubit connections.

Parameters:

num_qubits_per_side (int)

Return type:

QubitConnectionGraph[PhysicalQubit]

get_all_qubits() list[QubitTypeVar]

Get all qubit in the connection graph.

Return type:

list[QubitTypeVar]

get_connected_qubits(qubit: QubitTypeVar) list[QubitTypeVar]

Get all qubits connected to the given qubit.

Parameters:

qubit (QubitTypeVar) – Qubit to find connections for.

Return type:

list[QubitTypeVar]

get_number_of_connected_components() int

Compute connected components of the (undirected) connection graph.

Return type:

int

property num_qubits: int

Number of qubits in the connections graph.

class QubitMap

Bases: object

Class for holding a map between physical and logical qubits.

A map can be set up and accessed through, e.g.,

qubit_map = QubitMap()
qubit_map.map_logical_to_physical_qubit(LogicalQubit(0), PhysicalQubit(2))

print(qubit_map[LogicalQubit(0)])  # PhysicalQubit(2)
print(qubit_map[PhysicalQubit(2)])  # LogicalQubit(0)
__init__() None

Initialize an instance of qubit map.

Return type:

None

get_logical_to_physical_index_map() dict[int, int]

Get mapping from logical qubit indices to physical qubit indices.

Return type:

dict[int, int]

map_logical_to_physical_qubit(logical_qubit: LogicalQubit, physical_qubit: PhysicalQubit) None

Map logical qubit to a physical qubit.

Parameters:
  • logical_qubit (LogicalQubit) – Logical qubit to be mapped.

  • physical_qubit (PhysicalQubit) – Physical qubit to be mapped.

Raises:

ValueError – If either logical or physical qubit is already mapped.

Return type:

None

swap_logical_qubits_mapped_to_physical_qubits(physical_qubit_1: PhysicalQubit, physical_qubit_2: PhysicalQubit) None

Swap logical qubits mapped to the given physical qubits.

Parameters:
  • physical_qubit_1 (PhysicalQubit) – First physical qubit to be swapped.

  • physical_qubit_2 (PhysicalQubit) – Second physical qubit to be swapped.

Raises:

ValueError – If neither of the physical qubits have been mapped.

Return type:

None