Hi @Dhawal_Verma,
I’m sorry to hear you weren’t able to get the badge. But don’t worry, other badges will come in the future!
Actually several changes are needed in your code. store_params doesn’t need to be an np.array. This will cause errors to show up.
I see other issues in your optimization loop. Basically you’re using a very basic optimization method that’s converging very slowly and it can’t get to the desired answer quickly. You will need to change the optimizer or the stepsize, plus increase the maximum number of iterations, and reduce the tolerance to about 1e-7.
Finally, there’s a very important thing to learn when using step_and_cost
. The first output is actually a list containing all of the arguments of your cost function, which in this case is circuit
. So the way to obtain the new iteration for the parameters is actually as shown below.
[I_PARAM,hamiltonian], prev_cost = opt.step_and_cost(circuit, I_PARAM,hamiltonian)
Now with all of these changes you should be able to solve the challenge. I hope this helps!