---
title: OperatorTrait (latest version)
description: API reference for qiskit_fermions.operators.OperatorTrait in the latest version of qiskit-fermions
source: https://quantum.cloud.ibm.com/docs/en/api/qiskit-fermions/operators-operator-trait
---

# OperatorTrait

*class* `OperatorTrait(*args, **kwargs)`

Bases: [`Protocol`](https://docs.python.org/3/library/typing.html#typing.Protocol)

A protocol indicating all methods implemented by operator classes.

## Attributes

### groups

Returns the groups indices.

## Methods

### adjoint

`adjoint()`

Returns the adjoint of this operator.

**Return type**

[*Self*](https://docs.python.org/3/library/typing.html#typing.Self)

### equiv

`equiv(other, atol)`

Checks this operator with another for equivalence up to the specified absolute tolerance.

**Parameters**

- **other** ([*Self*](https://docs.python.org/3/library/typing.html#typing.Self))
- **atol** ([*float*](https://docs.python.org/3/library/functions.html#float))

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

### from\_terms

*classmethod* `from_terms(terms)`

Constructs a new operator from an iterator (see also [`iter_terms()`](#qiskit_fermions.operators.OperatorTrait.iter_terms "qiskit_fermions.operators.OperatorTrait.iter_terms")).

**Parameters**

**terms** ([*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable))

**Return type**

[*Self*](https://docs.python.org/3/library/typing.html#typing.Self)

### from\_terms\_with\_groups

*classmethod* `from_terms_with_groups(terms)`

Constructs a new operator from an iterator (see also [`iter_terms_with_groups()`](#qiskit_fermions.operators.OperatorTrait.iter_terms_with_groups "qiskit_fermions.operators.OperatorTrait.iter_terms_with_groups")).

**Parameters**

**terms** ([*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable))

**Return type**

[*Self*](https://docs.python.org/3/library/typing.html#typing.Self)

### get\_coeffs

`get_coeffs()`

Returns the term coefficients.

**Return type**

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

### get\_support

`get_support()`

Returns the set of mode indices which this operator acts upon.

**Return type**

[frozenset](https://docs.python.org/3/library/stdtypes.html#frozenset)\[[int](https://docs.python.org/3/library/functions.html#int)]

### group\_weights

`group_weights()`

Returns the mean absolute coefficient magnitude of each group.

This is equivalent to (but cheaper than) reducing [`get_coeffs()`](#qiskit_fermions.operators.OperatorTrait.get_coeffs "qiskit_fermions.operators.OperatorTrait.get_coeffs") and [`groups`](#qiskit_fermions.operators.OperatorTrait.groups "qiskit_fermions.operators.OperatorTrait.groups") down to one value per group in NumPy, because it does not copy one value per *ungrouped* term out of the operator just to aggregate it away again.

**Return type**

[list](https://docs.python.org/3/library/stdtypes.html#list)\[[float](https://docs.python.org/3/library/functions.html#float)] | None

### has\_groups

`has_groups()`

Returns whether this operator tracks group indices.

This is equivalent to (but cheaper than) checking `op.groups is not None`, because it does not copy the group indices out of the operator in order to inspect them.

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

### ichop

`ichop(atol)`

Trims coefficients below the absolute tolerance from this operator.

**Parameters**

**atol** ([*float*](https://docs.python.org/3/library/functions.html#float))

### iter\_terms

`iter_terms()`

Iterates over the terms of this operator.

**Return type**

[*Iterator*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterator)

### iter\_terms\_with\_groups

`iter_terms_with_groups()`

Iterates over the terms of this operator with their group indices.

**Return type**

[*Iterator*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterator)

### normal\_ordered

`normal_ordered(*args, **kwargs)`

Returns the normal-ordered form of this operator.

> **Note**
>
> A specific implementation of this method may take additional arguments.

**Return type**

[*Self*](https://docs.python.org/3/library/typing.html#typing.Self)

### num\_groups

`num_groups()`

Returns the number of groups.

**Return type**

[int](https://docs.python.org/3/library/functions.html#int) | None

### one

*classmethod* `one()`

Constructs the multiplicative identity operator.

**Return type**

[*Self*](https://docs.python.org/3/library/typing.html#typing.Self)

### relabel\_modes

`relabel_modes(permutation)`

Relabels the modes of the operator.

**Parameters**

**permutation** ([*list*](https://docs.python.org/3/library/stdtypes.html#list)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*]*)

**Return type**

[*Self*](https://docs.python.org/3/library/typing.html#typing.Self)

### simplify

`simplify(atol)`

Simplifies the terms of this operator, discarding those below the absolute tolerance.

**Parameters**

**atol** ([*float*](https://docs.python.org/3/library/functions.html#float))

**Return type**

[*Self*](https://docs.python.org/3/library/typing.html#typing.Self)

### split\_out\_groups

`split_out_groups(group_indices=None)`

Splits this operator into an optional list of new operators based on its [`groups`](#qiskit_fermions.operators.OperatorTrait.groups "qiskit_fermions.operators.OperatorTrait.groups").

> **Note**
>
> If `group_indices` is omitted, every group is built, in index order. Otherwise, only the requested indices are built, in the given order.

**Parameters**

**group\_indices** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*] | None*)

**Return type**

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

### zero

*classmethod* `zero()`

Constructs the additive identity operator.

**Return type**

[*Self*](https://docs.python.org/3/library/typing.html#typing.Self)
