hqnr
eigenkit.torch.estimators.hqnr
eigenkit.torch.estimators.hqnr.HQNR
Bases: ModelAccessMixin, BaseQuantumRegressor
Hybrid quantum neural network regressor (HQNR).
It is the regression counterpart of HQNC. The model is
MinMaxNorm -> quantum_layer -> nn.Linear(q_out, 1). If the number of
features of the data differs from the resolved input size of the quantum
layer, an nn.Linear adapter is added in front automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
The number of input features. |
required |
in_quantum
|
int | None
|
The number of inputs that the quantum layer expects. It
defaults to |
None
|
n_qubits
|
int | None
|
The number of qubits in each circuit. It defaults to
|
None
|
depth
|
int
|
The number of repetitions of the variational layer. |
2
|
layer_type
|
str
|
The quantum layer. It is one of |
'Basic'
|
enc_rotation
|
Literal['RX', 'RY', 'RZ'] | None
|
The encoding rotation: |
None
|
var_rotation
|
Literal['RX', 'RY', 'RZ'] | None
|
The variational rotation of the |
None
|
variational_type
|
Literal['basic', 'strong'] | None
|
The type of variational block: |
None
|
basis
|
Literal['X', 'Y', 'Z'] | None
|
The measurement basis: |
None
|
provider
|
ProviderSpec
|
The backend. It takes the same options as
|
'numpy'
|
lr
|
float
|
The learning rate of the optimiser. |
0.01
|
optimizer
|
str
|
The name of the optimiser. The supported names are |
'adam'
|
optimizer_kwargs
|
dict | None
|
Extra keyword arguments passed to the optimiser. |
None
|
epochs
|
int
|
The number of training epochs. |
50
|
batch_size
|
int
|
The size of each mini-batch. |
32
|
show_progress
|
bool
|
If True, a tqdm progress bar is shown. |
True
|
loss_func
|
str
|
The regression loss: |
'mse'
|
huber_delta
|
float
|
The threshold of the Huber loss. |
1.0
|
huber_reduction
|
str
|
The reduction of the Huber loss: |
'mean'
|
random_state
|
int | None
|
The seed. |
42
|
Attributes:
| Name | Type | Description |
|---|---|---|
train_losses_ |
The training loss of each epoch, set by |
|
validation_losses_ |
The validation loss of each epoch, set by |
Example
fit(X, y, X_val=None, y_val=None)
Fit the regressor on training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The samples, of shape |
required |
y
|
ndarray
|
The real-valued targets, of shape |
required |
X_val
|
ndarray | None
|
Optional validation samples, used to compute the validation loss of each epoch. |
None
|
y_val
|
ndarray | None
|
Optional validation targets, used to compute the validation loss of each epoch. |
None
|
Returns:
| Type | Description |
|---|---|
HQNR
|
This estimator, so that calls can be chained. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
load(path, *, provider=None)
classmethod
Load a fitted model from a .eigenkit bundle.
Load only bundles that you trust. A bundle can contain joblib pickles, and
unpickling runs code, as with torch.load or joblib.load.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The path of the bundle. |
required |
provider
|
ProviderSpec | None
|
A provider that replaces the saved one. |
None
|
Returns:
| Type | Description |
|---|---|
'BaseQuantumEstimator'
|
The loaded estimator. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the method is called on a subclass and the bundle holds
a different class. |
predict(X)
Predict the continuous targets of X. It returns a float32 array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The samples, of shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
One prediction for each sample. |
save(path)
Save a fitted model to a .eigenkit bundle.
The bundles of models that hold scikit-learn objects (QSVC, QSVR, the
reservoir estimators and the time-series estimators) contain joblib
pickles, so loading one can run code. Share them only with people who
trust you.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The path of the bundle. The suffix |
required |