prevision_quantum_nn.models.qnn
¶
Quantum Neural Network module provides with the base class of Quantum Neural Networks from which all models should inherit
Module Contents¶
Classes¶
Quantum Neural Network |
-
class
prevision_quantum_nn.models.qnn.
QuantumNeuralNetwork
(params)¶ - Quantum Neural Network
base class for all quantum neural networks
-
params
¶ contains the parameters of the model
- Type
dictionnary
-
use_early_stopper
¶ if True, early stopping will be activated, default: True
- Type
bool
-
early_stopper
¶ early stopper that stops the run when the validation loss increases
- Type
-
early_stopper_patience
¶ number of iterations during which the early stopper module will save the weights and restore them when triggered
- Type
int
-
postprocessor
¶ postprocessor to be called as a callback during the run
- Type
-
built
¶ True if the model has been built, it False, fit won’t start
- Type
bool
-
running_mode
¶ default, “simulation”, but could also be “computation”once the access to quantum computers will be effective
- Type
str
-
architecture
¶ architecture of the quantum computer - can be: 1. qubit 2. cv
- Type
str
-
num_q
¶ number of qubits/qumodes
- Type
int
-
num_categories
¶ number of categories/classes/labels of the problem only the first num_categories qubits/qumodes will be measured
- Type
int
-
num_actions
¶ number of actions in the case of a reinforcement learning mode
- Type
int
-
max_iterations
¶ maximum number of iteration that the fitting phase needs to perform
- Type
int
-
num_layers
¶ number of layers of the quantum neural network
- Type
int
-
snapshot_frequency
¶ frequency in number of iterations at which the model needs to snapshot
- Type
int
-
type_problem
¶ problem that is being solved, can be: 1. classifiation 2. multiclassificaiton 3. regression 4. reinforcement_learning
- Type
str
-
batch_size
¶ batch size to be used for one fitting iteration
- Type
int
-
save
¶ if True, the model will save at the end of fit
- Type
bool
-
prefix
¶ name of the file to which the output should go to
- Type
str
-
build
(self)¶ build the model: initializes the weights
-
check_model
(self)¶ Checks the model’s parameters consistency.
- Raises
ValueError when needed –
-
build_early_stopper
(self)¶ Builds the early stoppe.
-
get_random_batch
(self, features, labels, batch_size)¶ Get random batch. :param features: features to be randomly selected :type features: numpy array :param labels: labels to be randomly selected :type labels: numpy array
- Returns
- numpy array
randomized batched features
- labels: numpy array
randomized batched labels
- Return type
features
-
logging_iteration
(self, val_features, val_labels, train_loss, val_loss)¶ Dumps information during training.
- Parameters
val_features (array) – validation features
val_labels (array) – validation labels
train_loss (float) – loss of the current iteration
val_loss (float) – validation loss of the current iteration