---
title: SupportsApplyUnitary (latest version)
description: API reference for qiskit_fermions.protocols.SupportsApplyUnitary in the latest version of qiskit-fermions
source: https://quantum.cloud.ibm.com/docs/en/api/qiskit-fermions/protocols-supports-apply-unitary
---

# SupportsApplyUnitary

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

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

A mirror of the [`ffsim.SupportsApplyUnitary`](https://qiskit-community.github.io/ffsim/api/stubs/ffsim.SupportsApplyUnitary.html#ffsim.SupportsApplyUnitary "(in ffsim)") protocol.

See [`apply_unitary()`](/docs/api/qiskit-fermions/linalg-apply-unitary "qiskit_fermions.linalg.apply_unitary") for the type-agnostic helper function dispatching to the method below.

```pycon
>>> import numpy as np
>>> from qiskit_fermions.circuit.library import OrbitalRotation
>>> gate = OrbitalRotation(np.eye(2))
>>> vec = np.array([1.0, 0.0], dtype=complex)
>>> gate._apply_unitary_(vec, norb=2, nelec=1, copy=True)
array([1.+0.j, 0.+0.j])
```

**Protocol Methods**

### \_apply\_unitary\_

`_apply_unitary_(vec, norb, nelec, copy)`

Applies a unitary transformation to a state vector.

**Parameters**

- **vec** (*np.ndarray*) – the state vector to apply the unitary transformation to.

- **norb** ([*int*](https://docs.python.org/3/library/functions.html#int)) – the number of spatial orbitals.

- **nelec** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*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)*]*) – either a single integer representing the number of fermions for a spinless system, or a pair of integers storing the numbers of spin alpha and spin beta fermions.

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

  whether to copy the vector before operating on it.

  - If `copy=True` then this method always returns a newly allocated vector and the original vector is left untouched.
  - If `copy=False` then this method may still return a newly allocated vector, but the original vector may have its data overwritten. It is also possible that the original vector is returned, modified in-place.

**Returns**

The transformed vector.

**Return type**

np.ndarray
