Mapping#

class iqm.qaoa.transpiler.routing.Mapping(qpu, problem_bqm, partial_initial_mapping=None)[source]#

Bases: object

This class is responsible for a mapping between logical and hardware qubits.

It maintains two dictionaries: log2hard and hard2log which are mappings between logical and hardware qubits. They are automatically 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 partial_initial_mapping is provided, but it’s not bijective.

Attributes

hard2log

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

log2hard

The dictionary log2hard is calculated lazily from hard2log.

Methods

move_hard(source_qubit, target_qubit)

Moves a logical qubit from a one hardware qubit to a different hardware qubit on the QPU which is not part of the mapping.

swap_hard(gate)

Swap association between a pair of hardware qubits.

swap_log(gate)

Swap association between a pair of logical qubits.

update(layer)

Convenience function that updates the mapping based on the swap gates found in a Layer object.

property hard2log: dict[HardQubit, LogQubit]#

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

property log2hard: dict[LogQubit, HardQubit]#

The dictionary log2hard is calculated lazily from hard2log.

swap_log(gate)[source]#

Swap association between a pair of logical qubits.

Updates the dictionary hard2log (log2hard gets updated automatically).

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 dictionary hard2log (log2hard gets updated automatically).

Parameters:

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

Return type:

None

move_hard(source_qubit, target_qubit)[source]#

Moves a logical qubit from a one hardware qubit to a different hardware qubit on the QPU which is not part of the mapping.

Updates the dictionary hard2log (log2hard gets updated automatically). The dictionary is changed as follows:

  • If the dictionary hard2log has a key source_qubit (but not target_qubit), this method removes the key source_qubit, creates a new key target_qubit and gives it the value formerly associated to 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.

Return type:

None

update(layer)[source]#

Convenience function that updates the mapping based on the swap gates found in a Layer object.

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