Skip to main contentIBM Quantum Documentation

Layout

class qiskit.transpiler.Layout(input_dict=None)

GitHub(opens in a new tab)

Bases: object(opens in a new tab)

Two-ways dict to represent a Layout.

construct a Layout from a bijective dictionary, mapping virtual qubits to physical qubits


Methods

add

add(virtual_bit, physical_bit=None)

GitHub(opens in a new tab)

Adds a map element between bit and physical_bit. If physical_bit is not defined, bit will be mapped to a new physical bit.

Parameters

add_register

add_register(reg)

GitHub(opens in a new tab)

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

combine_into_edge_map(another_layout)

GitHub(opens in a new tab)

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

dict(opens in a new tab)

Raises

LayoutError – another_layout can be bigger than self, but not smaller. Otherwise, raises.

compose

compose(other, qubits)

GitHub(opens in a new tab)

Compose this layout with another layout.

If this layout represents a mapping from the P-qubits to the positions of the Q-qubits, and the other layout represents a mapping from the Q-qubits to the positions of the R-qubits, then the composed layout represents a mapping from the P-qubits to the positions of the R-qubits.

Parameters

  • other (Layout) – The existing Layout to compose this Layout with.
  • qubits (List(opens in a new tab)[Qubit]) – A list of Qubit objects over which other is defined, used to establish the correspondence between the positions of the other qubits and the actual qubits.

Returns

A new layout object the represents this layout composed with the other layout.

Return type

Layout

copy

copy()

GitHub(opens in a new tab)

Returns a copy of a Layout instance.

from_dict

from_dict(input_dict)

GitHub(opens in a new tab)

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(opens in a new tab)) –

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]}

from_intlist

static from_intlist(int_list, *qregs)

GitHub(opens in a new tab)

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(opens in a new tab)) – A list of integers.
  • *qregs (QuantumRegisters) – The quantum registers to apply the layout to.

Returns

The corresponding Layout object.

Return type

Layout

Raises

LayoutError – Invalid input layout.

from_qubit_list

static from_qubit_list(qubit_list, *qregs)

GitHub(opens in a new tab)

Populates a Layout from a list containing virtual qubits, Qubit or None.

Parameters

  • qubit_list (list(opens in a new tab)) – 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

Layout

Raises

LayoutError – If the elements are not Qubit or None

generate_trivial_layout

static generate_trivial_layout(*regs)

GitHub(opens in a new tab)

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

Layout

get_physical_bits

get_physical_bits()

GitHub(opens in a new tab)

Returns the dictionary where the keys are physical (qu)bits and the values are virtual (qu)bits.

get_registers

get_registers()

GitHub(opens in a new tab)

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

get_virtual_bits()

GitHub(opens in a new tab)

Returns the dictionary where the keys are virtual (qu)bits and the values are physical (qu)bits.

inverse

inverse(source_qubits, target_qubits)

GitHub(opens in a new tab)

Finds the inverse of this layout.

This is possible when the layout is a bijective mapping, however the input and the output qubits may be different (in particular, this layout may be the mapping from the extended-with-ancillas virtual qubits to physical qubits). Thus, if this layout represents a mapping from the P-qubits to the positions of the Q-qubits, the inverse layout represents a mapping from the Q-qubits to the positions of the P-qubits.

Parameters

Returns

A new layout object the represents the inverse of this layout.

order_based_on_type

static order_based_on_type(value1, value2)

GitHub(opens in a new tab)

decides which one is physical/virtual based on the type. Returns (virtual, physical)

reorder_bits

reorder_bits(bits)

GitHub(opens in a new tab)

Given an ordered list of bits, reorder them according to this layout.

The list of bits must exactly match the virtual bits in this layout.

Parameters

bits (list(opens in a new tab)[Bit]) – the bits to reorder.

Returns

ordered bits.

Return type

List

swap

swap(left, right)

GitHub(opens in a new tab)

Swaps the map between left and right.

Parameters

Raises

LayoutError – If left and right have not the same type.

to_permutation

to_permutation(qubits)

GitHub(opens in a new tab)

Creates a permutation corresponding to this layout.

This is possible when the layout is a bijective mapping with the same source and target qubits (for instance, a “final_layout” corresponds to a permutation of the physical circuit qubits). If this layout is a mapping from qubits to their new positions, the resulting permutation describes which qubits occupy the positions 0, 1, 2, etc. after applying the permutation.

For example, suppose that the list of qubits is [qr_0, qr_1, qr_2], and the layout maps qr_0 to 2, qr_1 to 0, and qr_2 to 1. In terms of positions in qubits, this maps 0 to 2, 1 to 0 and 2 to 1, with the corresponding permutation being [1, 2, 0].

Was this page helpful?
Report a bug or request content on GitHub.