---
title: Layout (v1.0)
description: API reference for qiskit.transpiler.Layout in qiskit v1.0
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/1.0/qiskit.transpiler.Layout
---

# Layout

*class* `qiskit.transpiler.Layout(input_dict=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L30-L369)

Bases: [`object`](https://docs.python.org/3/library/functions.html#object)

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](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L161-L184)

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**

- **virtual\_bit** ([*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)) – A (qu)bit. For example, (QuantumRegister(3, ‘qr’), 2).
- **physical\_bit** ([*int*](https://docs.python.org/3/library/functions.html#int)) – A physical bit. For example, 3.

### add\_register

`add_register(reg)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L186-L195)

Adds at the end physical\_qubits that map each bit in reg.

**Parameters**

**reg** ([*Register*](/docs/api/qiskit/1.0/qiskit.circuit.Register "qiskit.circuit.Register")) – A (qu)bit Register. For example, QuantumRegister(3, ‘qr’).

### combine\_into\_edge\_map

`combine_into_edge_map(another_layout)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L234-L264)

Combines self and another\_layout into an “edge map”.

For example:

```python
   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*](#qiskit.transpiler.Layout "qiskit.transpiler.Layout")) – The other layout to combine.

**Returns**

A “edge map”.

**Return type**

[dict](https://docs.python.org/3/library/stdtypes.html#dict)

**Raises**

[**LayoutError**](/docs/api/qiskit/1.0/transpiler#qiskit.transpiler.LayoutError "qiskit.transpiler.LayoutError") – another\_layout can be bigger than self, but not smaller. Otherwise, raises.

### copy

`copy()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L151-L159)

Returns a copy of a Layout instance.

### from\_dict

`from_dict(input_dict)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L55-L88)

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*](https://docs.python.org/3/library/stdtypes.html#dict)) –

e.g.:

```python
{(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](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L303-L339)

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*](https://docs.python.org/3/library/stdtypes.html#list)) – A list of integers.
- **\*qregs** (*QuantumRegisters*) – The quantum registers to apply the layout to.

**Returns**

The corresponding Layout object.

**Return type**

[Layout](#qiskit.transpiler.Layout "qiskit.transpiler.Layout")

**Raises**

[**LayoutError**](/docs/api/qiskit/1.0/transpiler#qiskit.transpiler.LayoutError "qiskit.transpiler.LayoutError") – Invalid input layout.

### from\_qubit\_list

*static* `from_qubit_list(qubit_list, *qregs)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L341-L369)

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

**Parameters**

- **qubit\_list** ([*list*](https://docs.python.org/3/library/stdtypes.html#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**

[Layout](#qiskit.transpiler.Layout "qiskit.transpiler.Layout")

**Raises**

[**LayoutError**](/docs/api/qiskit/1.0/transpiler#qiskit.transpiler.LayoutError "qiskit.transpiler.LayoutError") – If the elements are not Qubit or None

### generate\_trivial\_layout

*static* `generate_trivial_layout(*regs)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L286-L301)

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](#qiskit.transpiler.Layout "qiskit.transpiler.Layout")

### get\_physical\_bits

`get_physical_bits()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L212-L217)

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

### get\_registers

`get_registers()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L197-L203)

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](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L205-L210)

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

### order\_based\_on\_type

*static* `order_based_on_type(value1, value2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L90-L104)

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

### reorder\_bits

`reorder_bits(bits)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L266-L284)

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*](https://docs.python.org/3/library/stdtypes.html#list)*\[*[*Bit*](/docs/api/qiskit/1.0/qiskit.circuit.Bit "qiskit.circuit.Bit")*]*) – the bits to reorder.

**Returns**

ordered bits.

**Return type**

List

### swap

`swap(left, right)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/transpiler/layout.py#L219-L232)

Swaps the map between left and right.

**Parameters**

- **left** ([*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)  *or*[*int*](https://docs.python.org/3/library/functions.html#int)) – Item to swap with right.
- **right** ([*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)  *or*[*int*](https://docs.python.org/3/library/functions.html#int)) – Item to swap with left.

**Raises**

[**LayoutError**](/docs/api/qiskit/1.0/transpiler#qiskit.transpiler.LayoutError "qiskit.transpiler.LayoutError") – If left and right have not the same type.
