Skip to content

Optimizer option (readability) #83

Description

@Sam-XiaoyueLi

In train_vqe in main.py, the optimizer options are given by argument optimizer_options. However, the description in the help documentation is unclear (without example code, a general user wouldn't know what to put there) and the default value for nepochs is unrealistic (100000) and tol does not help terminate the code.

For example, when optimizer='sgd', tol=1e-2 and we run the following code

niter = 3
# define the qibo loss function
objective_boost = partial(vqe_loss)
# logging history
params_history, loss_history, grads_history, fluctuations = [], [], [], []
# set optimizer
optimizer = 'sgd'
tol = 1e-2

# train vqe
(
    partial_results,
    partial_params_history,
    partial_loss_history,
    partial_grads_history,
    partial_fluctuations,
    vqe,
) = train_vqe(
    deepcopy(ansatz_circ),
    ham_boost,  # Fixed hamiltonian
    optimizer,
    initial_params,
    tol=tol,
    niterations=1,
    nmessage=1,
    loss=objective_boost,
)
params_history = np.array(partial_params_history)
loss_history = np.array(partial_loss_history)
grads_history = np.array(partial_grads_history)

which does not specify optimizer_options, the code runs almost indefinitely, like so:
image

In the scenario where optimizer='cma' (backend='tensorflow'), the loss function fluctuates largely (changes sign)
image

In summary, the default value for nepochs in the optimizers.optimize function in ansazte.py may need to be more realistic for the general user. It may also be helpful if the help documentation has more detailed descriptions of the optimizer_options. Moreover, we may need to see if 'cma' is running correctly?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions