cirq.MappingManager

Class that manages the mapping from logical to physical qubits.

For efficiency, the mapping manager maps all logical and physical qubits to integers, and maintains a mapping from logical qubit integers to physical qubit integers. This speedup is important to avoid qubit hashing in hot-paths like querying distance of two logical qubits on the device (via dist_on_device method).

All public methods of this class expect logical qubits (or corresponding integers that the logical qubits are mapped to, via self.logical_qid_to_int map).

device_graph connectivity graph of qubits in the hardware device.
initial_mapping the initial mapping of logical (keys) to physical qubits (values).

induced_subgraph_int Induced subgraph on physical qubit integers present in self.logical_to_physical.
int_to_logical_qid Inverse mapping of unique integers to corresponding physical qubits.

self.logical_qid_to_int[self.int_to_logical_qid[i]] == i for each i.

int_to_physical_qid Inverse mapping of unique integers to corresponding physical qubits.

self.physical_qid_to_int[self.int_to_physical_qid[i]] == i for each i.

logical_qid_to_int Mapping of logical qubits, that were part of the initial mapping, to unique integers.
logical_to_physical The mapping of logical qubit integers to physical qubit integers.

Let lq: cirq.Qid be a logical qubit. Then the corresponding physical qubit that it maps to can be obtained by: self.int_to_physical_qid[self.logical_to_physical[self.logical_qid_to_int[lq]]]

physical_qid_to_int Mapping of physical qubits, that were part of the initial mapping, to unique integers.
physical_to_logical The mapping of physical qubits integers to logical qubits integers.

Let pq: cirq.Qid be a physical qubit. Then the corresponding logical qubit that it maps to can be obtained by: self.int_to_logical_qid[self.physical_to_logical[self.physical_qid_to_int[pq]]]

Methods

apply_swap

View source

Updates the mapping to simulate inserting a swap operation between lq1 and lq2.

Args
lq1 integer corresponding to the first logical qubit.
lq2 integer corresponding to the second logical qubit.

Raises
ValueError whenever lq1 and lq2 are not adjacent on the device.

dist_on_device

View source

Finds distance between logical qubits 'lq1' and 'lq2' on the device.

Args
lq1 integer corresponding to the first logical qubit.
lq2 integer corresponding to the second logical qubit.

Returns
The shortest path distance.

is_adjacent

View source

Finds whether logical qubits lq1 and lq2 are adjacent on the device.

Args
lq1 integer corresponding to the first logical qubit.
lq2 integer corresponding to the second logical qubit.

Returns
True, if physical qubits corresponding to lq1 and lq2 are adjacent on the device.

mapped_op

View source

Transforms the given logical operation to act on corresponding physical qubits.

Args
op logical operation acting on logical qubits.

Returns
The same operation acting on corresponding physical qubits.

shortest_path

View source

Find the shortest path between two logical qubits on the device, given their mapping.

Args
lq1 integer corresponding to the first logical qubit.
lq2 integer corresponding to the second logical qubit.

Returns
A sequence of logical qubit integers on the shortest path from lq1 to lq2.