Skip to content

reupload

eigenkit.torch.layers.reupload

The data-reuploading layer.

It encodes the input depth times, with new variational weights between the encodings. Optionally, it adds to each encoding rotation a trainable scale for each pair of layer and feature (Schuld et al. 2021).

In this layer, in_features == n_qubits.

Reupload

Bases: Module

The data-reuploading layer (Perez-Salinas 2020; Schuld 2021).

It supports two patterns:

  • Standard reuploading (the default). The same input is encoded depth times, with new variational weights between the encodings.
  • Trainable feature scaling (trainable_scale=True). Each encoding rotation becomes R(lambda * x), with a trainable lambda for each pair of layer and feature.

Parameters:

Name Type Description Default
n_qubits int

The number of qubits, which is also the number of input features.

required
depth int

The number of times the input is encoded.

required
enc_rotation Literal['RX', 'RY', 'RZ']

The encoding rotation: "RX", "RY" or "RZ". Default: "RY".

'RY'
var_rotation Literal['RX', 'RY', 'RZ']

The variational rotation. It is used only when variational_type="basic". Default: "RY".

'RY'
variational_type Literal['basic', 'strong']

"basic" or "strong". Default: "basic".

'basic'
basis Literal['X', 'Y', 'Z']

The Pauli measurement basis: "X", "Y" or "Z". Default: "Z".

'Z'
trainable_scale bool

If True, each encoding rotation gets a trainable scale for each pair of layer and feature. The CUDA Quantum backend does not support it, because its QuakeValue arithmetic is limited. Default: False.

False
provider ProviderSpec

The backend that runs the circuit. Default: "numpy".

'numpy'
Example
import torch
from eigenkit import Reupload

layer = Reupload(n_qubits=4, depth=3, trainable_scale=True)
out = layer(torch.randn(8, 4))  # shape (8, 4)

provider property

The backend that the circuit of this layer was compiled for.

The constructor takes provider= in the same forms as Circuit (a registered name, a configuration or a backend object) and turns it into one Provider. This property returns it. The registered name is provider.name.

Returns:

Name Type Description
provider Provider

The backend that the circuit runs on.

forward(x)

Run the layer.

Parameters:

Name Type Description Default
x Tensor

The input batch, of shape (batch, in_features).

required

Returns:

Name Type Description
out Tensor

The output of the layer for that batch.