adaptive
adaptive copied to clipboard
Suggestion: callback feature for learners (or runners)
I'm plotting a 2D Brillouin zone with C3 symmetry. Is there a way to add a callback so that after each point is calculated, I can "tell" the learner to add the same point and value but rotated?
I would like to add points and values after one has finished. My idea was something like
def callback(learner, point, value):
learner.tell(transform(point), value)
...
Hi @emascot, thanks for your interest in Adaptive and your suggestion! 😄
I wonder if we could come up with different applications for adding a callback.
For now, I just recommend that you use the LearnerND
where you use a ConvexHull
as the bounds, then, when it's finished you can easily do this transformation yourself by looping over the data in learner.data
.
Thanks @basnijholt. I had the same idea. I haven't been able to come up with other applications.
Another application I could use this for is to save the learner after each point instead of using periodic saving.
Edit: I see that this was brought up in #196
Hmm, the thing with the callback is that it should be very fast because you want it to happen before a new point is suggested. Saving could be slow and this means that your free cores are waiting for new points. You could in principle get a similar result with a coroutine that frequently checks for the number of points, then if a new point is added, save it again.
Currently, it is actually possible to add coroutines to the runner, see this part of the tutorial, that is what #196 is discussing.
Adding a callback to the learner wouldn't be an asynchronous operation I think and would be a bit different.
@akhmerov and @jbweston do you remember what Pablo tried to do with his KPM code and the Learner2D
? IIRC he needed to precalculate something with a bunch of vectors before he could calculate a new point. Could this have been solved by having a learner callback?
Thanks @basnijholt, I will do this.