I am trying to implement the example in https://pennylane.ai/qml/demos/tutorial_data_reuploading_classifier.html with QNGOptimizer
because I learned that QNGOptimizer
is faster. Then I got the error, The QNG optimizer supports single QNodes or ExpvalCost
objects as objective functions. Alternatively, the metric tensor can directly be provided to the step()
method of the optimizer, using the metric_tensor_fn
argument.
By searching the doc and forum, I also learn that QNGOptimizer
cannot work with hybrid cost function.
The cost function in the tutorial is
def cost(params, x, y, state_labels=None):
"""Cost function to be minimized.
Args:
params (array[float]): array of parameters
x (array[float]): 2-d array of input vectors
y (array[float]): 1-d array of targets
state_labels (array[float]): array of state representations for labels
Returns:
float: loss value to be minimized
"""
# Compute prediction for each input in data batch
loss = 0.0
dm_labels = [density_matrix(s) for s in state_labels]
for i in range(len(x)):
f = qcircuit(params, x[i], dm_labels[y[i]])
loss = loss + (1 - f) ** 2
return loss / len(x)
In terms of this cost function, does it mean there are 2 Qnodes considering the two types of observable?
Also, could you shed light on combing data_reuploading_classifier
with QNGOptimizer
?
Thank you in advance.
Ban