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

evaluators.py: Allow MultiprocessingEvaluator to initialize with cpu_count minus N processes #140

Merged
merged 1 commit into from
Jun 1, 2022

Conversation

EwoutH
Copy link
Collaborator

@EwoutH EwoutH commented May 31, 2022

This commit allows inputting negative integers for n_processes in the MultiprocessingEvaluator. This way the number of logical CPU cores minus that negative number would be used. For example, on a 12 thread processor, -2 results in using 10 threads. There is a guard around the function that always at least one process.

The main advantage is that when inputting a negative number, there is always some CPU power available for system and background tasks, which means the system would lag way less. When working in teams or on different devices, you can just leave it to -1 or -2 and always have some computing power to spare.

This commit allows inputting negative integers for n_processes in the MultiprocessingEvaluator defined in evaluators.py. This way the number of logical CPU cores minus that negative number would be used. For example, on a 12 thread processor, -2 results in using 10 threads. There is a guard around the function that always at least one process.

The main advantage is that when inputting a negative number, there is always some CPU power available for system and background tasks, which means the system would lag way less. When working in teams or on different devices, you can just leave it to -1 or -2 and always have some computing power to spare.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 80.355% when pulling 904b287 on EwoutH:patch-10 into d4464a3 on quaquel:master.

@EwoutH EwoutH mentioned this pull request May 31, 2022
@quaquel quaquel merged commit 7464a70 into quaquel:master Jun 1, 2022
@EwoutH
Copy link
Collaborator Author

EwoutH commented Jun 3, 2022

Another option is was thinking about is allowing a float between 0 and 1, which would indicate the fraction of logical GPU cores that the evaluator is allowed to use. So 0.5 would mean at most half of the cores, and 0.8 at most 80%, etc. The number of cores is rounded down, so that with 0.8 at least 20% of logical cores are still available.

@quaquel
Copy link
Owner

quaquel commented Jun 3, 2022

I would prefer to stay as close as possible to how this is handled in e.g. concurrent.futures and multiprocessing. The negative indexing is already a deviation, although a convenient one and in line with negative indexing. Giving a special meaning to floats between 0 and 1 would only confuse in my view.

@EwoutH
Copy link
Collaborator Author

EwoutH commented Jun 3, 2022

That was what I wanted to check, I agree.

@quaquel
Copy link
Owner

quaquel commented Jun 3, 2022

I just pushed the next step for #124. The main question is whether we want to address the visualization also at this stage or leave that for a future release.

@EwoutH
Copy link
Collaborator Author

EwoutH commented Jun 3, 2022

I would suggest moving that to 2.3.0, that we also have some time to discuss what the optimal form is.

EwoutH added a commit to EwoutH/EMAworkbench that referenced this pull request Oct 5, 2022
PR quaquel#140 introduced a feature for the MultiprocessingEvaluator to take a negative input for n_processes, which initialize the evaluator with the cpu_count minus that negative integer, leaving that number of cores free.

In 7dd1610 this code was refactored, introducing a bug that broke the negative-integer input functionality. When a negative integer is inputted, a AttributeError: 'MultiprocessingEvaluator' object has no attribute 'n_processes' was created.

The bug was caused by self.n_processes begin used instead of n_processes, where in earlier code self.n_processes was set equal to n_processes earlier in the process.

This commit fixes this behaviour by using n_processes to calculate self.n_processes.

Unfortunately this bug landed in the EMAworkbench 2.2.0 release. A cherry pick and new patch release should be considered.
EwoutH added a commit that referenced this pull request Oct 5, 2022
PR #140 introduced a feature for the MultiprocessingEvaluator to take a negative input for n_processes, which initialize the evaluator with the cpu_count minus that negative integer, leaving that number of cores free.

In 7dd1610 this code was refactored, introducing a bug that broke the negative-integer input functionality. When a negative integer is inputted, a AttributeError: 'MultiprocessingEvaluator' object has no attribute 'n_processes' was created.

The bug was caused by self.n_processes begin used instead of n_processes, where in earlier code self.n_processes was set equal to n_processes earlier in the process.

This commit fixes this behaviour by using n_processes to calculate self.n_processes.
EwoutH added a commit that referenced this pull request Oct 6, 2022
PR #140 introduced a feature for the MultiprocessingEvaluator to take a negative input for n_processes, which initialize the evaluator with the cpu_count minus that negative integer, leaving that number of cores free.

In 7dd1610 this code was refactored, introducing a bug that broke the negative-integer input functionality. When a negative integer is inputted, a AttributeError: 'MultiprocessingEvaluator' object has no attribute 'n_processes' was created.

The bug was caused by self.n_processes begin used instead of n_processes, where in earlier code self.n_processes was set equal to n_processes earlier in the process.

This commit fixes this behaviour by using n_processes to calculate self.n_processes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants