---
title: map_edge_vertex_generators (latest version)
description: API reference for qiskit_fermions.mappers.map_edge_vertex_generators in the latest version of qiskit-fermions
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit-fermions/mappers-map-edge-vertex-generators
---

# map\_edge\_vertex\_generators

`map_edge_vertex_generators(operator, map_action, identity, compose=None)`

Map a [`EdgeVertexOperator`](/docs/api/qiskit-fermions/operators-edge-vertex-operator "qiskit_fermions.operators.EdgeVertexOperator") to another operator type.

This is a generic function to aid in implementing new mappers for [`EdgeVertexOperator`](/docs/api/qiskit-fermions/operators-edge-vertex-operator "qiskit_fermions.operators.EdgeVertexOperator") instances. At its core, it simply iterates over the terms of the operator, mapping each encountered [`EdgeAction`](/docs/api/qiskit-fermions/operators-edge-action-edge-action "qiskit_fermions.operators.edge_action.EdgeAction") with the user-provided `map_action` function. In combination with the user-provided `identity` generator, this allows mapping to arbitrary output types.

> **Note**
>
> The output type `T` must support multiplication by a scalar via `__mul__`. If `compose=None` it must also support composition of two instances via `__and__`.

```pycon
>>> from qiskit_fermions.mappers import map_edge_vertex_generators
>>> from qiskit_fermions.operators import EdgeAction, EdgeVertexOperator
>>> from qiskit.quantum_info import SparsePauliOp
>>>
>>> def jordan_wigner_nearest_neighbor(mode: EdgeAction) -> SparsePauliOp:
...     match abs(mode[0] - mode[1]):
...         case 0:
...             pauli = "Z"
...             qubits = [mode[0]]
...         case 1:
...             pauli = "XY"
...             qubits = [mode[0], mode[1]]
...         case _:
...             raise NotImplementedError(
...                 "This mapping only handles nearest neighbor interactions"
...             )
...
...     return SparsePauliOp.from_sparse_list([(pauli, qubits, 1.0)], num_qubits=num_qubits)
>>>
>>> num_qubits = 4
>>> def identity() -> SparsePauliOp:
...     return SparsePauliOp.from_sparse_list([("", [], 1)], num_qubits)
>>>
>>> op = EdgeVertexOperator.from_dict({
...     ((0, 0),): 2.0,
...     ((0, 1),): 0.5,
...     ((1, 1), (1, 2)): 1.0,
... })
>>> qop = map_edge_vertex_generators(op, jordan_wigner_nearest_neighbor, identity)
>>> print([(label, complex(coeff)) for label, coeff in sorted(qop.label_iter())])
[('IIII', 0j), ('IIIZ', (2+0j)), ('IIYX', (0.5+0j)), ('IYYI', 1j)]
```

**Parameters**

- **operator** ([*EdgeVertexOperator*](/docs/api/qiskit-fermions/operators-edge-vertex-operator "qiskit_fermions.operators.edge_vertex_operator.EdgeVertexOperator")) – the operator to be mapped.
- **map\_action** ([*Callable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)*\[\[*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*,* [*int*](https://docs.python.org/3/library/functions.html#int)*]], T]*) – the function to map a single [`EdgeAction`](/docs/api/qiskit-fermions/operators-edge-action-edge-action "qiskit_fermions.operators.edge_action.EdgeAction") to the desired output type.
- **identity** ([*Callable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)*\[\[], T]*) – the function to generate the multiplicative identity instance of the output type.
- **compose** ([*Callable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)*\[\[T, T], T] | None*) – an optional function to implement the compositiion logic of two output type instances. If this is not provided, it will default to using [`operator.and_()`](https://docs.python.org/3/library/operator.html#operator.and_).

**Returns**

The mapped operator.

**Return type**

*T*
