# qiskit.transpiler.Layout¶

class Layout(input_dict=None)[소스]

Two-ways dict to represent a Layout.

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

__init__(input_dict=None)[소스]

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

Methods

 __init__([input_dict]) construct a Layout from a bijective dictionary, mapping virtual qubits to physical qubits add(virtual_bit[, physical_bit]) Adds a map element between bit and physical_bit. Adds at the end physical_qubits that map each bit in reg. combine_into_edge_map(another_layout) Combines self and another_layout into an 《edge map》. Returns a copy of a Layout instance. from_dict(input_dict) Populates a Layout from a dictionary. from_intlist(int_list, *qregs) Converts a list of integers to a Layout mapping virtual qubits (index of the list) to physical qubits (the list values). from_qubit_list(qubit_list) Populates a Layout from a list containing virtual qubits, Qubit or None. Creates a trivial (《one-to-one》) Layout with the registers in regs. Returns the dictionary where the keys are physical (qu)bits and the values are virtual (qu)bits. Returns the registers in the layout [QuantumRegister(2, 〈qr0〉), QuantumRegister(3, 〈qr1〉)] :returns: A list of Register in the layout :rtype: List Returns the dictionary where the keys are virtual (qu)bits and the values are physical (qu)bits. order_based_on_type(value1, value2) decides which one is physical/virtual based on the type. reorder_bits(bits) Given an ordered list of bits, reorder them according to this layout. swap(left, right) Swaps the map between left and right.
add(virtual_bit, physical_bit=None)[소스]

Adds a map element between bit and physical_bit. If physical_bit is not defined, bit will be mapped to a new physical bit (extending the length of the layout by one.)

매개변수
• virtual_bit (tuple) – A (qu)bit. For example, (QuantumRegister(3, 〈qr〉), 2).

• physical_bit (int) – A physical bit. For example, 3.

add_register(reg)[소스]

Adds at the end physical_qubits that map each bit in reg.

매개변수

reg (Register) – A (qu)bit Register. For example, QuantumRegister(3, 〈qr〉).

combine_into_edge_map(another_layout)[소스]

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.

매개변수

another_layout (Layout) – The other layout to combine.

반환값

A 《edge map》.

반환 형식

dict

예외

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

copy()[소스]

Returns a copy of a Layout instance.

from_dict(input_dict)[소스]

Populates a Layout from a dictionary.

The dictionary must be a bijective mapping between virtual qubits (tuple) and physical qubits (int).

매개변수

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)[소스]

Converts a list of integers to a Layout mapping virtual qubits (index of the list) to physical qubits (the list values).

매개변수
• int_list (list) – A list of integers.

• *qregs (QuantumRegisters) – The quantum registers to apply the layout to.

반환값

The corresponding Layout object.

반환 형식

Layout

예외

LayoutError – Invalid input layout.

static from_qubit_list(qubit_list)[소스]

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

매개변수

qubit_list (list) – e.g.: [qr[0], None, qr[2], qr[3]]

반환값

the corresponding Layout object

반환 형식

Layout

예외

LayoutError – If the elements are not Qubit or None

static generate_trivial_layout(*regs)[소스]

Creates a trivial (《one-to-one》) Layout with the registers in regs.

매개변수

*regs (Registers) – registers to include in the layout.

반환값

A layout with all the regs in the given order.

반환 형식

Layout

get_physical_bits()[소스]

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

get_registers()[소스]

Returns the registers in the layout [QuantumRegister(2, 〈qr0〉), QuantumRegister(3, 〈qr1〉)] :returns: A list of Register in the layout :rtype: List

get_virtual_bits()[소스]

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

static order_based_on_type(value1, value2)[소스]

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

reorder_bits(bits)[소스]

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.

매개변수

bits (list[Bit]) – the bits to reorder.

반환값

ordered bits.

반환 형식

List

swap(left, right)[소스]

Swaps the map between left and right.

매개변수
• left (tuple or int) – Item to swap with right.

• right (tuple or int) – Item to swap with left.

예외

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