---
title: LayoutTransformation (latest version)
description: API reference for qiskit.transpiler.passes.LayoutTransformation in the latest version of qiskit
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/qiskit.transpiler.passes.LayoutTransformation
---

# LayoutTransformation

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

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/transpiler/passes/routing/layout_transformation.py#L26-L119)

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

Adds a Swap circuit for a given (partial) permutation to the circuit.

This circuit is found by a 4-approximation algorithm for Token Swapping. More details are available in the routing code.

LayoutTransformation initializer.

**Parameters**

- **coupling\_map** – Directed graph representing a coupling map.
- **from\_layout** (*Union\[*[*Layout*](/docs/api/qiskit/qiskit.transpiler.Layout "qiskit.transpiler.Layout")*,* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*]*) – The starting layout of qubits onto physical qubits. If the type is str, look up property\_set when this pass runs.
- **to\_layout** (*Union\[*[*Layout*](/docs/api/qiskit/qiskit.transpiler.Layout "qiskit.transpiler.Layout")*,* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*]*) – The final layout of qubits on physical qubits. If the type is str, look up `property_set` when this pass runs.
- **seed** (*Union\[*[*int*](https://docs.python.org/3/library/functions.html#int)*, np.random.default\_rng]*) – Seed to use for random trials.
- **trials** ([*int*](https://docs.python.org/3/library/functions.html#int)) – How many randomized trials to perform, taking the best circuit as output.

## 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.5/qiskit/transpiler/basepasses.py#L162-L181)

Execute optimization task for input Qiskit IR.

**Parameters**

- **passmanager\_ir** ([*DAGCircuit*](/docs/api/qiskit/qiskit.dagcircuit.DAGCircuit "qiskit._accelerate.circuit.DAGCircuit")) – Qiskit IR to optimize.
- **state** ([*DAGCircuit*](/docs/api/qiskit/qiskit.dagcircuit.DAGCircuit "qiskit._accelerate.circuit.DAGCircuit")) – State associated with workflow execution by the pass manager itself.
- **callback** ([*Callable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)*\[\[*[*Task*](/docs/api/qiskit/qiskit.passmanager.Task "qiskit.passmanager.base_tasks.Task")*,* [*DAGCircuit*](/docs/api/qiskit/qiskit.dagcircuit.DAGCircuit "qiskit._accelerate.circuit.DAGCircuit")*,* [*PropertySet*](/docs/api/qiskit/qiskit.passmanager.PropertySet "qiskit.passmanager.compilation_status.PropertySet")*,* [*float*](https://docs.python.org/3/library/functions.html#float)*,* [*int*](https://docs.python.org/3/library/functions.html#int)*], None] | 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)\[[*DAGCircuit*](/docs/api/qiskit/qiskit.dagcircuit.DAGCircuit "qiskit._accelerate.circuit.DAGCircuit"), [*PassManagerState*](/docs/api/qiskit/qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")]

### name

`name()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/passmanager/base_tasks.py#L72-L74)

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.5/qiskit/transpiler/passes/routing/layout_transformation.py#L76-L119)

Apply the specified partial permutation to the circuit.

**Parameters**

**dag** ([*DAGCircuit*](/docs/api/qiskit/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")) – DAG to transform the layout of.

**Returns**

The DAG with transformed layout.

**Return type**

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

**Raises**

[**TranspilerError**](/docs/api/qiskit/transpiler#qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") – if the coupling map or the layout are not compatible with the DAG. Or if either of string from/to\_layout is not found in property\_set.

### update\_status

`update_status(state, run_state)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/transpiler/basepasses.py#L183-L191)

Update workflow status.

**Parameters**

- **state** ([*PassManagerState*](/docs/api/qiskit/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/qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")
