# SparseOccupationOperators

Source: https://docs.q-ctrl.com/references/fire-opal/fireopal/fireopal.types.SparseOccupationOperators

```python
class fireopal.types.SparseOccupationOperators(operators, coefficients)
```

A dataclass representing sparse occupation operators.

This class handles observables by accepting a list of terms, where each
term is itself a list of (spin, site) tuples. A 1-point observable is
represented as a list of length 1, while multi-point observables are
lists of length > 1.

### Parameters
* **operators** (*list* *[* *list* *[* *tuple* *[* *str* *,* *int* *]* *]* *]*) – A list of terms making up the operator. Each term is a list of tuples.
  1-point observable example: [[(“Nup”, 3)]]
  Multi-point observable example: [[(“Ndn”, 7), (“Nup”, 9), (“Nup”, 4)]]
* **coefficients** (*list* *[* *float* *]*) – A list of coefficients corresponding to each operator term in operators.
  Must be the exact same length as operators.
### Raises
* `ValueError` – If the lengths of operators and coefficients do not match, if an operator
      tuple does not have exactly 2 elements, or if the spin is not “Nup” or “Ndn”.
* `TypeError` – If the types within the lists are incorrect (e.g., coefficient is
      not a number, spin is not a string, or site is not an integer).

## Examples

```pycon
>>> # Case 1: 1-point observables (lists of length 1)
>>> operator_1 = SparseOccupationOperators(
...     operators=[[("Nup", 3)], [("Ndn", 7)]],
...     coefficients=[+1/4, -4/5]
... )
```

```pycon
>>> # Case 2: Mixed multi-point and 1-point observables
>>> operator_2 = SparseOccupationOperators(
...     operators=[[("Nup", 3)], [("Ndn", 7), ("Nup", 9), ("Nup", 4)]],
...     coefficients=[+1.0, -1.0]
... )
```

## Methods

|||
|---------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| [from_dict](https://docs.q-ctrl.com/references/fire-opal/fireopal/fireopal.types.SparseOccupationOperators.from_dict.md#fireopal.types.SparseOccupationOperators.from_dict)   | Create a SparseOccupationOperators instance from a dictionary.                 |
| [to_dict](https://docs.q-ctrl.com/references/fire-opal/fireopal/fireopal.types.SparseOccupationOperators.to_dict.md#fireopal.types.SparseOccupationOperators.to_dict)         | Convert the SparseOccupationOperators instance to a dictionary representation. |

## Attributes

|||
|----------------------------------------------------------------------------------------------------------------------------------|----|
| [operators](https://docs.q-ctrl.com/references/fire-opal/fireopal/fireopal.types.SparseOccupationOperators.operators.md#fireopal.types.SparseOccupationOperators.operators)          |    |
| [coefficients](https://docs.q-ctrl.com/references/fire-opal/fireopal/fireopal.types.SparseOccupationOperators.coefficients.md#fireopal.types.SparseOccupationOperators.coefficients) |    |
