prevision_quantum_nn.models.pennylane_backend.qnn_pennylane

Pennylane module contains the base class of quantum neural networks based on pennylane

Module Contents

Classes

PennylaneNeuralNetwork Class PennylaneNeuralNetwork.
prevision_quantum_nn.models.pennylane_backend.qnn_pennylane.OPTIMIZER_NAMES = ['SGD', 'Adagrad', 'Adam', 'RMSProp']
class prevision_quantum_nn.models.pennylane_backend.qnn_pennylane.PennylaneNeuralNetwork(params)

Bases: prevision_quantum_nn.models.qnn.QuantumNeuralNetwork

Class PennylaneNeuralNetwork.

params

dictionary containing the main parameters of the model

Type:dict
optimizer

Optimizer of the quantum circuit. Can be AdamOptimizer or NesterovMomentumOptimizer

Type:Optimizer
batch_size

size of the batch with which the training should be perfomed

Type:int
verbose

sets the verbosity to on if True and off if False

Type:bool
interface

interface of the pennylane backend. Can be tf or autograd

Type:str
learning_rate

learning rate at which the fitting phase needs to be performed

encode_data(self, x)

needs to be overridden by child class

layer(self, v)

needs to be overridden by child class

output_layer(self, v)

needs to be overridden by child class

neural_network(self, var, features=None)

Main method that is decorated by the qml.qnode decorator. This will set the structure of the neural network

cost(self, var, features, labels)

cost function to be optimized

initialize_weights(self, weights_file=None)

initialize weights

to be implemented depending on the architecture used

build(self, weights_file=None)

builds the optimizer and initializes weights

build_optimizer(self)

Builds the optimizer according to its name and to the interface used.

snapshot(self)

Snapshots the model to a file.

load_weights(self, weights_file)

Loads weights from file.

Parameters:weights_file (string) – file name containing the weights
cost(self, var, features, labels)

Cost to be optimized during training.

Parameters:
  • var (list) – weights of the model
  • features (array) – obervations to be evalueated by the model
  • labels (array) – labels associated to features
Returns:

float

loss of the model given x

Return type:

loss

step(self, features, labels, var)

Performs one step of training.

Parameters:
  • features (array) – observations
  • labels (array) – labels
  • var (array) – weights of the model
fit(self, train_features, train_labels, plotter_callback, val_features=None, val_labels=None, verbose=True)

Fits data with model.

Parameters:
  • train_features (array) – training features
  • train_labels (array) – training labels
  • val_features (array) – validation features
  • val_labels (array) – validation labels
  • verbose (bool) – if True, verbosity will be activated
predict(self, features)

Predicts certain obervations.

Parameters:features (array) – observations to be predicted
Returns:
float or int
prediction of the model
Return type:preds