facebookresearch / nevergrad

A Python toolbox for performing gradient-free optimization
https://facebookresearch.github.io/nevergrad/
MIT License
3.92k stars 352 forks source link

TypeError: HiPlot generation failing when optimizing TransitionChoice #1466

Open akorb opened 2 years ago

akorb commented 2 years ago

Steps to reproduce

Execute the script below.

Observed Results

Expected Results

Relevant Code

from hiplot import Experiment
import nevergrad as ng
from nevergrad.optimization.callbacks import ParametersLogger
from math import cos

parametrization = ng.p.Instrumentation(
    ng.p.TransitionChoice(10)
)

optimizer = ng.optimizers.NGOpt(parametrization=parametrization, budget=10)

logger = ParametersLogger("log.json")
optimizer.register_callback("tell",  logger)

recommendation = optimizer.minimize(cos)
print("Recommendation: ", recommendation.value)

exp: Experiment = logger.to_hiplot_experiment()
exp.to_html("plot.html")

Notes

The reason that it crashes is that exp.datapoints[0].values['0.indices#0'] is a np.int64 instead of a simple native int.

TransitionChoice has the layer _datalayers.Int. And its _layered_get_value function returns an np.int64.

https://github.com/facebookresearch/nevergrad/blob/8403d6c9659f40fec2a3cf7f474b3d8610f0f2e4/nevergrad/parametrization/_layering.py#L269-L285

Not sure if this is the source of the problem, I'm not familiar with the guts of nevergrad