---
title: ApplyLayout (v2.3)
description: API reference for qiskit.transpiler.passes.ApplyLayout in qiskit v2.3
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/2.3/qiskit.transpiler.passes.ApplyLayout
---

# ApplyLayout

*class* `qiskit.transpiler.passes.ApplyLayout(*args, **kwargs)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.3/qiskit/transpiler/passes/layout/apply_layout.py#L28-L107)

Bases: [`TransformationPass`](/docs/api/qiskit/2.3/qiskit.transpiler.TransformationPass "qiskit.transpiler.basepasses.TransformationPass")

Apply or update the mapping of virtual qubits to physical qubits in the [`DAGCircuit`](/docs/api/qiskit/2.3/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit").

A “layout” in Qiskit is a mapping of virtual qubits (as the user typically creates circuits in terms of) to the physical qubits used to represent them on hardware.

This pass has two modes of operation, depending on the state of the `layout` and `post_layout` keys in the [`PropertySet`](/docs/api/qiskit/2.3/qiskit.passmanager.PropertySet "qiskit.passmanager.PropertySet"):

1. Standard operation: `post_layout` is not set. This takes in a [`DAGCircuit`](/docs/api/qiskit/2.3/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit") defined over virtual qubits, and rewrites it in terms of physical qubits. In this case, the `layout` field must have been chosen by a layout pass (for example [`SetLayout`](/docs/api/qiskit/2.3/qiskit.transpiler.passes.SetLayout "qiskit.transpiler.passes.SetLayout") or [`VF2Layout`](/docs/api/qiskit/2.3/qiskit.transpiler.passes.VF2Layout "qiskit.transpiler.passes.VF2Layout")), and both it and the [`DAGCircuit`](/docs/api/qiskit/2.3/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit") must have been expanded with ancillas (see [`EnlargeWithAncilla`](/docs/api/qiskit/2.3/qiskit.transpiler.passes.EnlargeWithAncilla "qiskit.transpiler.passes.EnlargeWithAncilla") and [`FullAncillaAllocation`](/docs/api/qiskit/2.3/qiskit.transpiler.passes.FullAncillaAllocation "qiskit.transpiler.passes.FullAncillaAllocation")).

2. Improving a layout: `post_layout` is set (such as by [`VF2PostLayout`](/docs/api/qiskit/2.3/qiskit.transpiler.passes.VF2PostLayout "qiskit.transpiler.passes.VF2PostLayout")). In this case, the `post_layout` must already be the correct size. It is interpreted as an \_additional\_ relabelling on top of the relabelling that is already applied to the input [`DAGCircuit`](/docs/api/qiskit/2.3/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit").

   After the pass runs, the `layout` field will be updated to represent the composition of the two relabellings, as will the [`DAGCircuit`](/docs/api/qiskit/2.3/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit") and any final permutation. The `post_layout` field will be removed.

## Attributes

### is\_analysis\_pass

Check if the pass is an analysis pass.

If the pass is an AnalysisPass, that means that the pass can analyze the DAG and write the results of that analysis in the property set. Modifications on the DAG are not allowed by this kind of pass.

### is\_transformation\_pass

Check if the pass is a transformation pass.

If the pass is a TransformationPass, that means that the pass can manipulate the DAG, but cannot modify the property set (but it can be read).

## Methods

### execute

`execute(passmanager_ir, state, callback=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.3/qiskit/transpiler/basepasses.py#L161-L180)

Execute optimization task for input Qiskit IR.

**Parameters**

- **passmanager\_ir** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) – Qiskit IR to optimize.
- **state** ([*PassManagerState*](/docs/api/qiskit/2.3/qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")) – State associated with workflow execution by the pass manager itself.
- **callback** ([*Callable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable) *| None*) – A callback function which is called per execution of optimization task.

**Returns**

Optimized Qiskit IR and state of the workflow.

**Return type**

[tuple](https://docs.python.org/3/library/stdtypes.html#tuple)\[[*Any*](https://docs.python.org/3/library/typing.html#typing.Any), [qiskit.passmanager.compilation\_status.PassManagerState](/docs/api/qiskit/2.3/qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")]

### name

`name()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.3/qiskit/passmanager/base_tasks.py#L68-L70)

Name of the pass.

**Return type**

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

### run

`run(dag)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.3/qiskit/transpiler/passes/layout/apply_layout.py#L53-L67)

Run the ApplyLayout pass on `dag`.

**Parameters**

**dag** ([*DAGCircuit*](/docs/api/qiskit/2.3/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")) – DAG to map.

**Returns**

A mapped DAG (with physical qubits).

**Return type**

[DAGCircuit](/docs/api/qiskit/2.3/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")

**Raises**

[**TranspilerError**](/docs/api/qiskit/2.3/transpiler#qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") – if no layout is found in `property_set` or no full physical qubits.

### update\_status

`update_status(state, run_state)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.3/qiskit/transpiler/basepasses.py#L182-L190)

Update workflow status.

**Parameters**

- **state** ([*PassManagerState*](/docs/api/qiskit/2.3/qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")) – Pass manager state to update.
- **run\_state** (*RunState*) – Completion status of current task.

**Returns**

Updated pass manager state.

**Return type**

[*PassManagerState*](/docs/api/qiskit/2.3/qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")
