---
title: LayerModel (latest version)
description: API reference for qiskit_addon_mpf.backends.tenpy_layers.LayerModel in the latest version of qiskit-addon-mpf
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit-addon-mpf/backends-tenpy-layers-layer-model
---

# LayerModel

*class* `LayerModel(model_params)`

[GitHub](https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L26-L162)

Bases: [`CouplingMPOModel`](https://tenpy.readthedocs.io/en/latest/reference/tenpy.models.model.CouplingMPOModel.html#tenpy.models.model.CouplingMPOModel "(in TeNPy v1.0.5)"), [`NearestNeighborModel`](https://tenpy.readthedocs.io/en/latest/reference/tenpy.models.model.NearestNeighborModel.html#tenpy.models.model.NearestNeighborModel "(in TeNPy v1.0.5)")

A model for representing a layer of time-evolution interactions.

Essentially, this class is a simple wrapper of [`tenpy.models.model.CouplingMPOModel`](https://tenpy.readthedocs.io/en/latest/reference/tenpy.models.model.CouplingMPOModel.html#tenpy.models.model.CouplingMPOModel "(in TeNPy v1.0.5)") and [`tenpy.models.model.NearestNeighborModel`](https://tenpy.readthedocs.io/en/latest/reference/tenpy.models.model.NearestNeighborModel.html#tenpy.models.model.NearestNeighborModel "(in TeNPy v1.0.5)"). Its main purpose is to provide a simple interface for constructing a TeNPy-compatible Hamiltonian from Qiskit objects.

## Methods

### calc\_H\_bond

`calc_H_bond(tol_zero=1e-15)`

[GitHub](https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L70-L99)

Calculate the interaction Hamiltonian based on the coupling and onsite terms.

Essentially, this class overwrites [`calc_H_bond()`](https://tenpy.readthedocs.io/en/latest/reference/tenpy.models.model.CouplingModel.html#tenpy.models.model.CouplingModel.calc_H_bond "(in TeNPy v1.0.5)") and takes care of removing even or odd bond interaction Hamiltonians depending on the value of `keep_only_odd` (see [`tenpy_layers`](/docs/api/qiskit-addon-mpf/backends-tenpy-layers#module-qiskit_addon_mpf.backends.tenpy_layers "qiskit_addon_mpf.backends.tenpy_layers") for more details).

**Parameters**

**tol\_zero** ([*float*](https://docs.python.org/3/library/functions.html#float)) – the threshold for values considered to be zero.

**Returns**

The list of interaction Hamiltonians for all bonds.

**Return type**

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

### from\_quantum\_circuit

*classmethod* `from_quantum_circuit(circuit, **kwargs)`

[GitHub](https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L101-L162)

Construct a [`LayerModel`](#qiskit_addon_mpf.backends.tenpy_layers.LayerModel "qiskit_addon_mpf.backends.tenpy_layers.LayerModel") from a [`QuantumCircuit`](/docs/api/qiskit/qiskit.circuit.QuantumCircuit).

You can see an example of this function in action in the docs of `tenpy_layers`.

> **Note**
>
> By default, TeNPy tries to enforce spin-conservation and, thus, some operations may not be available. If you encounter an error stating that some operator (e.g. `Sx`) is not available, try specifying `conserve="None"`. If that still does not work, converting your specific `QuantumCircuit` is currently not possible using this implementation.

**Parameters**

- **circuit** ([*QuantumCircuit*](/docs/api/qiskit/qiskit.circuit.QuantumCircuit)) – the quantum circuit to parse.
- **kwargs** – any additional keyword arguments to pass to the [`LayerModel`](#qiskit_addon_mpf.backends.tenpy_layers.LayerModel "qiskit_addon_mpf.backends.tenpy_layers.LayerModel") constructor.

**Returns**

A new LayerModel instance.

**Raises**

[**NotImplementedError**](https://docs.python.org/3/library/exceptions.html#NotImplementedError) – if an unsupported quantum gate is encountered.

**Return type**

[*LayerModel*](#qiskit_addon_mpf.backends.tenpy_layers.LayerModel "qiskit_addon_mpf.backends.tenpy_layers.model.LayerModel")

### init\_sites

`init_sites(model_params)`

[GitHub](https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L35-L49)

Initializes the sites of this Hamiltonian.

See [`init_sites()`](https://tenpy.readthedocs.io/en/latest/reference/tenpy.models.model.CouplingMPOModel.html#tenpy.models.model.CouplingMPOModel.init_sites "(in TeNPy v1.0.5)") for more details.

**Parameters**

**model\_params** ([*Config*](https://tenpy.readthedocs.io/en/latest/reference/tenpy.tools.params.Config.html#tenpy.tools.params.Config "(in TeNPy v1.0.5)")) – the model parameters.

**Returns**

The site to be used internally.

**Return type**

[*Site*](https://tenpy.readthedocs.io/en/latest/reference/tenpy.networks.site.Site.html#tenpy.networks.site.Site "(in TeNPy v1.0.5)")

### init\_terms

`init_terms(model_params)`

[GitHub](https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L51-L68)

Initializes the terms of this Hamiltonian.

See [`init_terms()`](https://tenpy.readthedocs.io/en/latest/reference/tenpy.models.model.CouplingMPOModel.html#tenpy.models.model.CouplingMPOModel.init_terms "(in TeNPy v1.0.5)") for more details.

**Parameters**

**model\_params** ([*Config*](https://tenpy.readthedocs.io/en/latest/reference/tenpy.tools.params.Config.html#tenpy.tools.params.Config "(in TeNPy v1.0.5)")) – the model parameters.

**Return type**

None
