qiskit-documentation/docs/api/qiskit-addon-mpf/backends-tenpy-layers-layer...

106 lines
6.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: LayerModel (latest version)
description: API reference for qiskit_addon_mpf.backends.tenpy_layers.LayerModel in the latest version of qiskit-addon-mpf
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit_addon_mpf.backends.tenpy_layers.LayerModel
---
# LayerModel
<Class id="qiskit_addon_mpf.backends.tenpy_layers.LayerModel" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L26-L162" signature="LayerModel(model_params)" modifiers="class">
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
<Function id="qiskit_addon_mpf.backends.tenpy_layers.LayerModel.calc_H_bond" github="https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L70-L99" signature="calc_H_bond(tol_zero=1e-15)">
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`](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 "(in Python v3.13)")) 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 "(in Python v3.13)")
</Function>
### from\_quantum\_circuit
<Function id="qiskit_addon_mpf.backends.tenpy_layers.LayerModel.from_quantum_circuit" github="https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L101-L162" signature="from_quantum_circuit(circuit, **kwargs)" modifiers="classmethod">
Construct a [`LayerModel`](#qiskit_addon_mpf.backends.tenpy_layers.LayerModel "qiskit_addon_mpf.backends.tenpy_layers.LayerModel") from a [`QuantumCircuit`](/api/qiskit/qiskit.circuit.QuantumCircuit "(in Qiskit v1.4)").
You can see an example of this function in action in the docs of `tenpy_layers`.
<Admonition title="Note" type="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.
</Admonition>
**Parameters**
* **circuit** ([*QuantumCircuit*](/api/qiskit/qiskit.circuit.QuantumCircuit "(in Qiskit v1.4)")) 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 "(in Python v3.13)") 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")
</Function>
### init\_sites
<Function id="qiskit_addon_mpf.backends.tenpy_layers.LayerModel.init_sites" github="https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L35-L49" signature="init_sites(model_params)">
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)")
</Function>
### init\_terms
<Function id="qiskit_addon_mpf.backends.tenpy_layers.LayerModel.init_terms" github="https://github.com/Qiskit/qiskit-addon-mpf/tree/stable/0.3/qiskit_addon_mpf/backends/tenpy_layers/model.py#L51-L68" signature="init_terms(model_params)">
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
</Function>
</Class>