Mapping#

Module: iqm.qaoa.transpiler.routing

class iqm.qaoa.transpiler.routing.Mapping(*args, **kwargs)[source]#

Bases: BaseMapping

Mapping between logical and hardware qubits.

It maintains two dictionaries: log2hard and hard2log which are mappings between logical and hardware qubits. They are always kept in sync. The names for the hardware and logical qubits are extracted from qpu and problem_bqm at initialization.

Parameters:
  • qpu (QPU) – a QPU object describing the topology of the QPU, used to get hardware qubits.

  • problem_bqm (BinaryQuadraticModel) – The BinaryQuadraticModel of the problem we’re trying to solve, used to get logical qubits.

  • partial_initial_mapping (dict[HardQubit, LogQubit] | None) – An optional dictionary that contains a partial mapping to use as a starting point. The keys should be HardQubit and the values LogQubit.

Raises:
  • ValueError – If there are more logical qubits than hardware qubits.

  • ValueError – If partial_initial_mapping is provided, but it’s not bijective.

  • ValueError – If partial_initial_mapping is provided, but it contains qubits not existing on the QPU.

Attributes

hard2log

The dictionary containing the mapping from hardware qubits to logical qubits.

log2hard

The dictionary containing the mapping from logical qubits to hardware qubits.

Methods

move_hard

Move a logical qubit from a one hardware qubit to a an unassigned hardware qubit on the QPU.

swap_hard

Swap association between a pair of hardware qubits.

swap_log

Swap association between a pair of logical qubits.

update

Update the mapping based on the swap gates found in a Layer object.

property hard2log: dict[HardQubit, LogQubit | None]#

The dictionary containing the mapping from hardware qubits to logical qubits.

property log2hard: dict[LogQubit, HardQubit]#

The dictionary containing the mapping from logical qubits to hardware qubits.

swap_log(gate)[source]#

Swap association between a pair of logical qubits.

Updates the dictionaries hard2log and log2hard.

Parameters:

gate (LogEdge) – The pair of logical qubits to swap.

Return type:

None

swap_hard(gate)[source]#

Swap association between a pair of hardware qubits.

Updates the dictionaries hard2log and log2hard.

Parameters:

gate (HardEdge) – The pair of hardware qubits to swap.

Return type:

None

move_hard(source_qubit, target_qubit)[source]#

Move a logical qubit from a one hardware qubit to a an unassigned hardware qubit on the QPU.

The target target_qubit must be mapped to None in hard2log and (correspondingly) it must not appear among the values of log2hard. The mapping dictionaries hard2log and log2hard are changed as follows:

  • The value assigned to the key source_qubit in hard2log changes to None. The value assigned to target_qubit changes to the previous value of source_qubit.

  • The dictionary log2hard is modified correspondingly. The value source_qubit is changed to target_qubit.

Parameters:
Raises:
  • ValueError – If the target_qubit is already assigned to a different logical qubit.

  • ValueError – If the source_qubit is not assigned to any logical qubit.

Return type:

None

update(layer)[source]#

Update the mapping based on the swap gates found in a Layer object.

A convenience function that iterates over the gates in a Layer object and swaps the hardware qubits corresponding to swap gates.

Parameters:

layer (Layer) – The layer whose swap gates are used.

Return type:

None

Inheritance

Inheritance diagram of iqm.qaoa.transpiler.routing.Mapping