Open Ne-oL opened 2 years ago
I'm not sure if this fixes it, but optimizer.enable_pickling
should be optimizer.enable_pickling()
.
Can you replace the callback with a proper function?
So
early_stopping = ng.callbacks.EarlyStopping(lambda opt: opt.current_bests["minimum"].mean < -0.95)
Becomes
def callback(opt):
return opt.current_bests["minimum"].mean < -0.95
early_stopping = ng.callbacks.EarlyStopping(callback)
I'm not sure if this fixes it, but
optimizer.enable_pickling
should beoptimizer.enable_pickling()
.
This didn't fix it but i have no idea if it would create any problems in the future so i changed it to the suggested.
Can you replace the callback with a proper function?
So
early_stopping = ng.callbacks.EarlyStopping(lambda opt: opt.current_bests["minimum"].mean < -0.95)
Becomes
def callback(opt): return opt.current_bests["minimum"].mean < -0.95 early_stopping = ng.callbacks.EarlyStopping(callback)
This did the Job, now its working fine. i knew that python couldn't pickle lambda functions as there can be many, but i never noticed that lambda was used in the EarlyStopping callback. i thought it was used internally in one of the underlying functions... thank you very much.
I would like to close the issue now, but i wanted to point out a few things that can help alleviate similar future issues and leave it up to you to close it at your own convenience:
Steps to reproduce
This is the code:
when i try to dump the optimizer using either of these codes:
the dumping process happens inside the optimized function as to dump the optimizer after each trial.
Observed Results
PicklingError: Can't pickle <function <lambda> at 0x2aab03ecf820>: attribute lookup <lambda> on __main__ failed
Expected Results
Relevant Code