adaptive icon indicating copy to clipboard operation
adaptive copied to clipboard

Suggestion: callback feature for learners (or runners)

Open emascot opened this issue 5 years ago • 5 comments

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)
    ...

emascot avatar May 08 '19 18:05 emascot

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.

basnijholt avatar May 10 '19 01:05 basnijholt

Thanks @basnijholt. I had the same idea. I haven't been able to come up with other applications.

emascot avatar May 11 '19 18:05 emascot

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

emascot avatar Jul 09 '19 21:07 emascot

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?

basnijholt avatar Jul 09 '19 23:07 basnijholt

Thanks @basnijholt, I will do this.

emascot avatar Jul 10 '19 17:07 emascot