Mapping#
- class iqm.qaoa.transpiler.routing.Mapping(qpu, problem_bqm, partial_initial_mapping=None)[source]#
Bases:
objectMapping between logical and hardware qubits.
It maintains two dictionaries:
log2hardandhard2logwhich are mappings between logical and hardware qubits. They are always kept in sync. The names for the hardware and logical qubits are extracted fromqpuandproblem_bqmat initialization.- Parameters:
qpu (QPU) – a
QPUobject describing the topology of the QPU, used to get hardware qubits.problem_bqm (BinaryQuadraticModel) – The
BinaryQuadraticModelof 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
HardQubitand the valuesLogQubit.
- Raises:
ValueError – If
partial_initial_mappingis provided, but it’s not bijective.
Attributes
The dictionary containing the mapping from hardware qubits to logical qubits.
The dictionary containing the mapping from logical qubits to hardware qubits.
Methods
move_hard(source_qubit, target_qubit)Move a logical qubit from a one hardware qubit to a an unassigned hardware qubit on the QPU.
swap_hard(gate)Swap association between a pair of hardware qubits.
swap_log(gate)Swap association between a pair of logical qubits.
update(layer)Update the mapping based on the swap gates found in a
Layerobject.- property hard2log: dict[HardQubit, LogQubit]#
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
hard2logandlog2hard.- 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
hard2logandlog2hard.- 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_qubitmust not be part of theMapping. Updates the dictionarieshard2logandlog2hard. The dictionaries are changed as follows:If the dictionary
hard2loghas a keysource_qubit(but nottarget_qubit), this method removes the keysource_qubit, creates a new keytarget_qubitand gives it the value formerly associated tosource_qubitThe dictionary
log2hardis modified correspondingly. The valuesource_qubitis changed totarget_qubit.
- Parameters:
- Raises:
ValueError – If the
target_qubitis already assigned to a different logical qubit.- Return type:
None
- update(layer)[source]#
Update the mapping based on the swap gates found in a
Layerobject.A convenience function that iterates over the gates in a
Layerobject and swaps the hardware qubits corresponding to swap gates.- Parameters:
layer (Layer) – The layer whose swap gates are used.
- Return type:
None