Layout¶
- class qiskit.transpiler.Layout(input_dict=None)[source]¶
Bases:
object
Two-ways dict to represent a Layout.
construct a Layout from a bijective dictionary, mapping virtual qubits to physical qubits
Methods
- add(virtual_bit, physical_bit=None)[source]¶
Adds a map element between bit and physical_bit. If physical_bit is not defined, bit will be mapped to a new physical bit.
- add_register(reg)[source]¶
Adds at the end physical_qubits that map each bit in reg.
- Parameters:
reg (Register) – A (qu)bit Register. For example, QuantumRegister(3, ‘qr’).
- combine_into_edge_map(another_layout)[source]¶
Combines self and another_layout into an “edge map”.
For example:
self another_layout resulting edge map qr_1 -> 0 0 <- q_2 qr_1 -> q_2 qr_2 -> 2 2 <- q_1 qr_2 -> q_1 qr_3 -> 3 3 <- q_0 qr_3 -> q_0
The edge map is used to compose dags via, for example, compose.
- Parameters:
another_layout (Layout) – The other layout to combine.
- Returns:
A “edge map”.
- Return type:
- Raises:
LayoutError – another_layout can be bigger than self, but not smaller. Otherwise, raises.
- from_dict(input_dict)[source]¶
Populates a Layout from a dictionary.
The dictionary must be a bijective mapping between virtual qubits (tuple) and physical qubits (int).
- Parameters:
input_dict (dict) –
e.g.:
{(QuantumRegister(3, 'qr'), 0): 0, (QuantumRegister(3, 'qr'), 1): 1, (QuantumRegister(3, 'qr'), 2): 2} Can be written more concisely as follows: * virtual to physical:: {qr[0]: 0, qr[1]: 1, qr[2]: 2} * physical to virtual:: {0: qr[0], 1: qr[1], 2: qr[2]}
- static from_intlist(int_list, *qregs)[source]¶
Converts a list of integers to a Layout mapping virtual qubits (index of the list) to physical qubits (the list values).
- Parameters:
int_list (list) – A list of integers.
*qregs (QuantumRegisters) – The quantum registers to apply the layout to.
- Returns:
The corresponding Layout object.
- Return type:
- Raises:
LayoutError – Invalid input layout.
- static from_qubit_list(qubit_list, *qregs)[source]¶
Populates a Layout from a list containing virtual qubits, Qubit or None.
- Parameters:
qubit_list (list) – e.g.: [qr[0], None, qr[2], qr[3]]
*qregs (QuantumRegisters) – The quantum registers to apply the layout to.
- Returns:
the corresponding Layout object
- Return type:
- Raises:
LayoutError – If the elements are not Qubit or None
- static generate_trivial_layout(*regs)[source]¶
Creates a trivial (“one-to-one”) Layout with the registers and qubits in regs.
- Parameters:
*regs (Registers, Qubits) – registers and qubits to include in the layout.
- Returns:
A layout with all the regs in the given order.
- Return type:
- get_physical_bits()[source]¶
Returns the dictionary where the keys are physical (qu)bits and the values are virtual (qu)bits.
- get_registers()[source]¶
Returns the registers in the layout [QuantumRegister(2, ‘qr0’), QuantumRegister(3, ‘qr1’)] :returns: A set of Registers in the layout :rtype: Set
- get_virtual_bits()[source]¶
Returns the dictionary where the keys are virtual (qu)bits and the values are physical (qu)bits.
- static order_based_on_type(value1, value2)[source]¶
decides which one is physical/virtual based on the type. Returns (virtual, physical)