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

# VF2Layout

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

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/transpiler/passes/layout/vf2_layout.py#L37-L173)

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

A pass for choosing a Layout of a circuit onto a Coupling graph, as a subgraph isomorphism problem, solved by VF2++.

If a solution is found that means there is a “perfect layout” and that no further swap mapping or routing is needed. If a solution is found the layout will be set in the property set as `property_set['layout']`. However, if no solution is found, no `property_set['layout']` is set. The stopping reason is set in `property_set['VF2Layout_stop_reason']` in all the cases and will be one of the values enumerated in `VF2LayoutStopReason` which has the following values:

> - `"solution found"`: If a perfect layout was found.
> - `"nonexistent solution"`: If no perfect layout was found.
> - `">2q gates in basis"`: If VF2Layout can’t work with basis

By default, this pass will construct a heuristic scoring map based on the error rates in the provided `target` (or `properties` if `target` is not provided). However, analysis passes can be run prior to this pass and set `vf2_avg_error_map` in the property set with a `ErrorMap` instance. If a value is `NaN` that is treated as an ideal edge For example if an error map is created as:

```python
from qiskit.transpiler.passes.layout.vf2_utils import ErrorMap

error_map = ErrorMap(3)
error_map.add_error((0, 0), 0.0024)
error_map.add_error((0, 1), 0.01)
error_map.add_error((1, 1), 0.0032)
```

that represents the error map for a 2 qubit target, where the avg 1q error rate is `0.0024` on qubit 0 and `0.0032` on qubit 1. Then the avg 2q error rate for gates that operate on (0, 1) is 0.01 and (1, 0) is not supported by the target. This will be used for scoring if it’s set as the `vf2_avg_error_map` key in the property set when [`VF2Layout`](#qiskit.transpiler.passes.VF2Layout "qiskit.transpiler.passes.VF2Layout") is run.

Initialize a `VF2Layout` pass instance

**Parameters**

- **coupling\_map** ([*CouplingMap*](/docs/api/qiskit/2.4/qiskit.transpiler.CouplingMap "qiskit.transpiler.CouplingMap")) – Directed graph representing a coupling map.
- **strict\_direction** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If True, considers the direction of the coupling map. Default is False.
- **seed** ([*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – shuffle the labelling of physical qubits to node indices in the coupling graph, using a given pRNG seed. `None` seeds using OS entropy (and so is non-deterministic). Using `-1` disables the shuffling.
- **call\_limit** (*None |* [*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)  *| None,*[*int*](https://docs.python.org/3/library/functions.html#int) *| None]*) – The maximum number of times that the inner VF2 isomorphism search will attempt to extend the mapping. If `None`, then no limit. If a 2-tuple, then the limit starts as the first item, and swaps to the second after the first match is found, without resetting the number of steps taken. This can be used to allow a long search for any mapping, but still terminate quickly with a small extension budget if one is found.
- **time\_limit** ([*float*](https://docs.python.org/3/library/functions.html#float)) – The total time limit in seconds to run `VF2Layout`. This is not completely strict; execution will finish on the first isomorphism found (if any) \_after\_ the time limit has been exceeded. Setting this option breaks determinism of the pass.
- **max\_trials** ([*int*](https://docs.python.org/3/library/functions.html#int)) – If set, the algorithm terminates after this many \_complete\_ layouts have been seen. Since the scoring is done on-the-fly, the vast majority of candidate layouts are pruned out of the search before ever becoming complete, so this option has little meaning. To set a low limit on the amount of time spent improving an initial limit, set a low value for the second item in the `call_limit` 2-tuple form.
- **target** ([*Target*](/docs/api/qiskit/2.4/qiskit.transpiler.Target "qiskit.transpiler.Target")) – A target representing the backend device to run `VF2Layout` on. If specified it will supersede a set value for `coupling_map` if the [`Target`](/docs/api/qiskit/2.4/qiskit.transpiler.Target "qiskit.transpiler.Target") contains connectivity constraints. If the value of `target` models an ideal backend without any constraints then the value of `coupling_map` will be used.

**Raises**

[**TypeError**](https://docs.python.org/3/library/exceptions.html#TypeError) – At runtime, if neither `coupling_map` or `target` are provided.

## 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.4/qiskit/passmanager/base_tasks.py#L71-L117)

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

### name

`name()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/passmanager/base_tasks.py#L67-L69)

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.4/qiskit/transpiler/passes/layout/vf2_layout.py#L129-L173)

run the layout method

### update\_status

`update_status(state, run_state)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/passmanager/base_tasks.py#L119-L137)

Update workflow status.

**Parameters**

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