G.4 Steps and speedups

I have a difficulty to get the soultion correct. ‘local_max_arg’ is not from Pennylane and no much resource about it. Any idea. Here is my attemp:

n_list = range(3,7)
opt_steps = []
dic ={}
for n_bits in n_list:
    combo = "0"*n_bits # A simple combination
    step_list = range(1,10) # Try out some large number of steps
    ##################
    # YOUR CODE HERE #
    ##################
    for step in step_list:
        dic[step] = max(grover_iter(combo, step))
    opt_steps.append(max(zip(dic.values(), dic.keys()))[1])
    pass

print("The optimal number of Grover steps for qubits in", [3,4,5,6], "is", opt_steps, ".")

Hi @Afrah,

local_max_arg(num_list) is a function that helps you find the first local maximum in a list of numbers num_list. An important detail is that this function tells you the position of the maximum, not the value of the maximum. This is why it’s useful for determining the number of steps.

For instance, local_max_arg([2,1,5,4,2]) will output 3 since the local (and in this case global) maximum is the third element in the list.

You can probably debug your code by using print statements. For instance, print the output of grover_iter(combo, step) and decide if you need all of the information that is output here or only one part of it :slight_smile:

I hope this can help you debug your code and find the solution!