> ## Documentation Index
> Fetch the complete documentation index at: https://prod-mint.classiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Variational Data Encoding

<Card title="View on GitHub" icon="github" href="https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/variational_data_encoding/variational_data_encoding.ipynb">
  Open this notebook in GitHub to run it yourself
</Card>

Encoding classical data on quantum states is an important subroutine in variational quantum circuits, such as Quantum Singular Vector Machine (QSVM) and Quantum Neural Networks (QNN).

## Encode in angle

This function encodes $n$ data points on $n$ qubits, mapping the data point $x_i$ to a RY rotation on the $i$-th qubit with a $\pi x_i$ angle.

Function: `encode_in_angle`

Arguments:

* `data`: `CArray[Creal]`
* `qba`: `Output[QArray[QBit]]`

The `qba` quantum argument is the quantum state on which we encode the classical array `data`.

## Example

```python theme={null}
from classiq import *


@qfunc
def main(data: CArray[CReal, 4], x: Output[QArray[QBit]]):
    encode_in_angle(data, x)


qmod = create_model(main)
```

```python theme={null}

from classiq import synthesize

qprog = synthesize(qmod)
```

<img src="https://mintcdn.com/classiq/sA-J-h8chQJV9OAG/qmod-reference/library-reference/open-library-functions/variational_data_encoding/figures/angle_encoding_circuit.png?fit=max&auto=format&n=sA-J-h8chQJV9OAG&q=85&s=fcb9b2b75a1ce7366b15eda4533cf769" alt="png" width="557" height="266" data-path="qmod-reference/library-reference/open-library-functions/variational_data_encoding/figures/angle_encoding_circuit.png" />

<Frame caption="Angle encoding." />

## Encode on Bloch

This function encodes $n$ data points on $\lceil n/2 \rceil$, mapping pairs of data points $(x_{2i}, x_{2i+1})$ to the bloch sphere via RX rotation with an angle $\pi x_{2i}$ followed by a RZ rotation with an angle $\pi x_{2i+1}$. If the number of data points is odd then a single RX rotation is applied to the last qubit, with an angle of $2\pi x_n$.

Function: `encode_on_bloch`

Arguments:

* `data`: `CArray[Creal]`
* `qba`: `Output[QArray[QBit]]`

The `qba` quantum argument is the quantum state on which we encode the classical array `data`.

## Example

```python theme={null}
from classiq import *


@qfunc
def main(data: CArray[CReal, 7], x: Output[QArray[QBit]]):
    encode_on_bloch(data, x)


qmod = create_model(main)
```

```python theme={null}

from classiq import synthesize

qprog = synthesize(qmod)
```

<img src="https://mintcdn.com/classiq/sA-J-h8chQJV9OAG/qmod-reference/library-reference/open-library-functions/variational_data_encoding/figures/dense_angle_encoding_circuit.png?fit=max&auto=format&n=sA-J-h8chQJV9OAG&q=85&s=b11ac98907e66f31972f2def94a98920" alt="png" width="1652" height="548" data-path="qmod-reference/library-reference/open-library-functions/variational_data_encoding/figures/dense_angle_encoding_circuit.png" />

<Frame caption="Dense angle (Bloch sphere) encoding." />
