Open akorb opened 2 years ago
Execute the script below.
TypeError: Object of type int64 is not JSON serializable
plot.html
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")
The reason that it crashes is that exp.datapoints[0].values['0.indices#0'] is a np.int64 instead of a simple native int.
exp.datapoints[0].values['0.indices#0']
np.int64
int
TransitionChoice has the layer _datalayers.Int. And its _layered_get_value function returns an np.int64.
TransitionChoice
_datalayers.Int
_layered_get_value
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
Steps to reproduce
Execute the script below.
Observed Results
TypeError: Object of type int64 is not JSON serializable
Expected Results
plot.html
which shows the HiPlot of the optimization.Relevant Code
Notes
The reason that it crashes is that
exp.datapoints[0].values['0.indices#0']
is anp.int64
instead of a simple nativeint
.TransitionChoice
has the layer_datalayers.Int
. And its_layered_get_value
function returns annp.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