Skip to content
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

Argument of SMAC_optimizer.minimize() must be a top-level function #21

Open
angellandros opened this issue Apr 15, 2017 · 1 comment
Open

Comments

@angellandros
Copy link

Because of the use of multiprocessing library of Python, the first argument of minimize() must be a top-level function to become pickle-able. Hence, Smac library cannot be used in a class.

@sfalkner
Copy link
Owner

This is true. The reasoning behind that is that each call to the function is executed in a separate subprocess. This way, the resources used by the call (like CPU-time, memory etc...) can be limited.

Depending on your use-case, you have two (potentially more) options:

  1. wrap whatever class method you want to minimize by a function that instantiates the class object (it could create it from scratch, or load a pickled version from disk) and then calls the method. This would be feasible, if you class is small/fast to construct compared to the execution.
  2. if your class is large and cannot be instantiated for every call, you could let pySMAC minimize a function that communicates via IPC (sockets, queue or similar) to a separate process that hosts your class object. This requires more code on your end, and limiting the resources inside pySMAC becomes useless, as the process that might exceed any limit wasn't created by SMAC. It would be your responsibility to ensure that the host process stops after a time limit has been reached or too much memory was allocated.
    Let me know if you have any other questions or comments on that.
    Best,
    Stefan

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

No branches or pull requests

2 participants