Hey,
I am having issues with the RMSPropOptimzer.steps() Method, which is not optimizing my parameters.
I am trying to run this notebook on my local machine:
Tutorial Embedding Generalization
This is the cost function:
def cost(weights, A=None, B=None):
aa = overlaps(weights, X1=A, X2=A)
bb = overlaps(weights, X1=B, X2=B)
ab = overlaps(weights, X1=A, X2=B)
d_hs = -2 * ab + (aa + bb)
print("cost: ", 1 - 0.5 * d_hs)
return 1 - 0.5 * d_hs
And this is how the optimizer is called:
optimizer = qml.RMSPropOptimizer(stepsize=0.01)
batch_size = 5
pars = init_pars
cost_list = []
for i in range(400):
# Sample a batch of training inputs from each class
selectA = np.random.choice(range(len(A)), size=(batch_size,), replace=True)
selectB = np.random.choice(range(len(B)), size=(batch_size,), replace=True)
A_batch = [A[s] for s in selectA]
B_batch = [B[s] for s in selectB]
# Walk one optimization step
pars = optimizer.step(lambda w: cost(w, A=A_batch, B=B_batch), pars)
print(pars)
pars
is initalized like:
# generate initial parameters for the quantum component, such that
# the resulting number of trainable quantum parameters is equal to
# the product of the elements that make up the 'size' attribute
# (4 * 3 = 12).
init_pars_quantum = np.random.normal(loc=0, scale=0.1, size=(4, 3))
# generate initial parameters for the classical component, such that
# the resulting number of trainable classical parameters is equal to
# the product of the elements that make up the 'size' attribute.
init_pars_classical = np.random.normal(loc=0, scale=0.1, size=(2, 4))
pars = [init_pars_classical, init_pars_quantum]
When printing out the pars
variable after every optimization step, they are just staying the same, even though the cost function evaluates different loss values in every step. I also receive the following warning: /home/user/.local/lib/python3.11/site-packages/pennylane/_grad.py:110: UserWarning: Attempted to differentiate a function with no trainable parameters. If this is unintended, please add trainable parameters via the 'requires_grad' attribute or 'argnum' keyword.
I am using Pennylane 0.33.1.
Thanks for your help!