python-adaptive / adaptive

:chart_with_upwards_trend: Adaptive: parallel active learning of mathematical functions
http://adaptive.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.13k stars 58 forks source link

LearnerND not loading properly #461

Open MrCheatak opened 1 month ago

MrCheatak commented 1 month ago

Consider a problem, where one would like to save an intermediate learning result and continue later. i.e. to increase accuracy.

Saving and loading Learner2D works like charm and I can continue where I left off, but loading a LearnerND throws an error: learner.function cannot be pickled.

Here is a reproducible example for a notebook:

from adaptive import LearnerND, Runner, notebook_extension
notebook_extension()

def sphere(xyz):
    x, y, z = xyz
    return x**2 + y**2 + z**2

fname = r'sphere_learned.pkl'
learner = LearnerND(sphere, bounds=[(-3, 3), (-3, 3), (-3, 3)])
runner = Runner(learner, loss_goal=0.01, ntasks=4)
runner.live_info()
runner.start_periodic_saving(save_kwargs=dict(fname=fname), interval=10)
learner = LearnerND(sphere, bounds=[(-3, 3), (-3, 3), (-3, 3)])
learner.load(fname)
runner = Runner(learner, loss_goal=0.001)
basnijholt commented 1 month ago

Thank you for reporting this! I will look into it ASAP.