Skip to content

Does not work with lambda functions #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RafalSkolasinski opened this issue Aug 1, 2019 · 7 comments · Fixed by #210
Closed

Does not work with lambda functions #206

RafalSkolasinski opened this issue Aug 1, 2019 · 7 comments · Fixed by #210
Labels

Comments

@RafalSkolasinski
Copy link

For example, if in the initial example one have

def g(x, offset=offset, wait=True):
    from time import sleep
    from random import random

    a = 0.01
    if wait:
        sleep(random() / 10)
    return x + a**2 / (a**2 + (x - offset)**2)


f = lambda x: g(x)

then execution just hangs.

@basnijholt
Copy link
Member

basnijholt commented Aug 1, 2019

Hi @RafalSkolasinski, that is expected because the function needs to be pickled such that it can be send to the executor. Therefore, lambda functions will never work with the default ProcessPoolExecutor.

edit: From v0.11 you are able to use lambda functions!

@RafalSkolasinski
Copy link
Author

That's a bummer. Any chance you could raise ValueError in such cases and produce a nice warning message?

@basnijholt
Copy link
Member

That makes sense, @jbweston, would you know how to best tackle this?

@RafalSkolasinski
Copy link
Author

Even better would be to find mechanism to make lambda expression pickable.

@basnijholt
Copy link
Member

It's already possible with ipyparallel if you enable dill or cloudpickle.

@akhmerov
Copy link
Contributor

akhmerov commented Aug 7, 2019

@RafalSkolasinski can you please provide the complete code sample?

This likely depends on which runner you are using.

@basnijholt
Copy link
Member

basnijholt commented Aug 26, 2019

@jbweston it is not obvious that this blocks the kernel, but it does hang forever and does not error.

import adaptive
adaptive.notebook_extension()

ring2 = lambda xy: xy[0]**2 + xy[1]**2
learner = adaptive.Learner2D(ring2, bounds=[(-1, 1), (-1, 1)])
runner = adaptive.Runner(learner, goal=lambda l: l.npoints >= 1000)
runner.live_info()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants