squlearn.qnn.lowlevel_qnn_pennylane.LowLevelQNNPennyLane

class squlearn.qnn.lowlevel_qnn_pennylane.LowLevelQNNPennyLane(parameterized_quantum_circuit: EncodingCircuitBase, observable: ObservableBase | list, executor: Executor, caching: bool = True)

Low level implementation of QNNs and its derivatives based on PennyLane.

Parameters:
  • pqc (EncodingCircuitBase) – parameterized quantum circuit in encoding circuit format

  • operator (Union[ObservableBase,list]) – Operator that is used in the expectation value of the QNN. Can be a list for multiple outputs.

  • executor (Executor) – Executor that is used for the evaluation of the QNN

  • caching – Caching of the result for each x, param, param_op combination (default = True)

Attributes:

num_qubits

Number of qubits of the QNN

Type:

int

num_features

Dimension of the features of the PQC

Type:

int

num_parameters

Number of trainable parameters of the PQC

Type:

int

num_operator

Number of outputs

Type:

int

num_parameters_observable

Number of trainable parameters of the expectation value operator

Type:

int

multiple_output

True if multiple outputs are used

Type:

bool

parameters

Parameter vector of the PQC

Type:

ParameterVector

features

Feature vector of the PQC

Type:

ParameterVector

parameters_operator

Parameter vector of the cost operator

Type:

ParameterVector

Methods:

evaluate(x: float | ndarray, param: float | ndarray, param_obs: float | ndarray, *values: str | DirectEvaluation | PostProcessingEvaluation | ParameterVector | ParameterVectorElement | tuple) dict

General function for evaluating the output of derivatives of the QNN.

Evaluation works for given combination of input features x and parameters param and param_op. The function includes caching of results

If x, param, and/or param_op are given as a nested list (for example multiple sets of parameters), the values are returned in a nested list.

Parameters:
  • x (np.ndarray) – Values of the input feature data.

  • param (np.ndarray) – Parameter values of the PQC parameters

  • param_op (np.ndarray) – Parameter values of the operator parameters

  • values – Derivatives (or values) of the QNN that are evaluated. Higher order derivatives are given as tuples of parameters or vectors.

Results:

Returns a dictionary with the computed values. The keys of the dictionary are given by the entries in the values tuple

get_params(deep: bool = True) dict

Returns the dictionary of the hyper-parameters of the QNN.

In case of multiple outputs, the hyper-parameters of the operator are prefixed with op0__, op1__, etc.

gradient(x: float | ndarray, param: float | ndarray, param_obs: float | ndarray)

Return the gradient wrt. trainable parameters of the QNN.

Parameters:
  • x (Union[float, np.ndarray]) – Input data.

  • param (Union[float, np.ndarray]) – Parameters of the PQC.

  • param_obs (Union[float, np.ndarray]) – Parameters of the observable.

Returns:

Gradient of the QNN.

Return type:

np.ndarray

set_params(**params) None

Sets the hyper-parameters of the QNN

In case of multiple outputs, the hyper-parameters of the operator are prefixed with op0__, op1__, etc.

Parameters:

params – Hyper-parameters that are adjusted, e.g. num_qubits=4