basnijholt / adaptive

:chart_with_upwards_trend: Tools for adaptive and parallel samping of mathematical functions
http://adaptive.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Balancing learner does not work with Integrator learner #67

Closed basnijholt closed 5 years ago

basnijholt commented 5 years ago

(original issue on GitLab)

opened by tlaeven ([gitlab:@tlaeven](https://gitlab.kwant-project.org/tlaeven))) at 2018-07-12T15:41:39.141Z

basnijholt commented 5 years ago

originally posted by Joseph Weston ([gitlab:@jbweston](https://gitlab.kwant-project.org/jbweston))) at 2018-07-13T11:16:03.002Z on GitLab

More details please

basnijholt commented 5 years ago

originally posted by Jorn Hoofwijk ([gitlab:@Jorn](https://gitlab.kwant-project.org/Jorn))) at 2018-07-13T11:30:09.676Z on GitLab

I told him to report this, however, here is an actual example:

import numpy as np
import adaptive
adaptive.notebook_extension()
def f(x):
    return x

learner = adaptive.IntegratorLearner(f, (0,1), tol=1e-8)
runner = adaptive.Runner(learner, lambda l: l.done()) # runs perfect
runner.live_info()
learner1 = adaptive.IntegratorLearner(f, (0,1), tol=1e-8)
learner2 = adaptive.IntegratorLearner(f, (0,1), tol=1e-8)

balancer = adaptive.BalancingLearner([learner1, learner2])

runner = adaptive.Runner(balancer, lambda l: l.loss() < 0.1) # fails
runner = adaptive.Runner(balancer, lambda l: l.done())       # fails
runner = adaptive.Runner(balancer, lambda bl: all(l.done() for l in bl.learners)) # fails
runner.live_info()

especially the last one, i don't know why it fails yet

basnijholt commented 5 years ago

originally posted by Jorn Hoofwijk ([gitlab:@Jorn](https://gitlab.kwant-project.org/Jorn))) at 2018-07-13T11:33:02.163Z on GitLab

got it:

Traceback (most recent call last):
  File "test5.py", line 14, in <module>
    runner = adaptive.BlockingRunner(balancer, lambda l: l.loss() < 0.1) # fails
  File "/home/jorn/natk/bep/adaptive/adaptive/runner.py", line 152, in __init__
    self._run()
  File "/home/jorn/natk/bep/adaptive/adaptive/runner.py", line 175, in _run
    points, _ = self.learner.ask(n_new_tasks)
  File "/home/jorn/natk/bep/adaptive/adaptive/learner/balancing_learner.py", line 89, in ask
    return self._ask_and_tell(n)
  File "/home/jorn/natk/bep/adaptive/adaptive/learner/balancing_learner.py", line 73, in _ask_and_tell
    n=1, add_data=False)
TypeError: ask() got an unexpected keyword argument 'add_data'
basnijholt commented 5 years ago

originally posted by Bas Nijholt ([gitlab:@basnijholt](https://gitlab.kwant-project.org/basnijholt))) at 2018-07-18T18:20:14.013Z on GitLab

Thanks for reporting, I've added some code to raise a NotImplementedError when add_data=False in the IntegratorLearner here: https://gitlab.kwant-project.org/qt/adaptive/commit/8640b8d58006b634e278709fd185a6ed2d05bfcb.

This doesn't fix the issue but at least makes it clear as to why it happens.

basnijholt commented 5 years ago

originally posted by Jorn Hoofwijk ([gitlab:@Jorn](https://gitlab.kwant-project.org/Jorn))) at 2018-09-25T11:47:55.034Z on GitLab

we could do it similarly as with the LearnerND: add a with restore(self) to allow not adding the data.

Also this would be solved if we would switch to a new BalancingLearner: gitlab:!113