-
Notifications
You must be signed in to change notification settings - Fork 354
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
The user can modify NG_CPUS_PER_TASK #1336
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,10 +7,12 @@ | |||||
import time | ||||||
import random | ||||||
import numbers | ||||||
import os | ||||||
import warnings | ||||||
import traceback | ||||||
import typing as tp | ||||||
import numpy as np | ||||||
from concurrent import futures | ||||||
from nevergrad.parametrization import parameter as p | ||||||
from nevergrad.common import decorators | ||||||
from nevergrad.common import errors | ||||||
|
@@ -57,15 +59,20 @@ def __init__( | |||||
self.optimizer = optimizer | ||||||
self.budget = budget | ||||||
self.num_workers = num_workers | ||||||
self.executor = execution.MockedTimedExecutor(batch_mode) | ||||||
ng_cpus_per_task = int(os.getenv("NG_CPUS_PER_TASK", "1")) | ||||||
if ng_cpus_per_task > 1: | ||||||
self.executor: tp.Any = futures.ThreadPoolExecutor(max_workers=ng_cpus_per_task) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still very much against this since it
Can you quantify the speed gain? |
||||||
assert not batch_mode | ||||||
else: | ||||||
self.executor = execution.MockedTimedExecutor(batch_mode) | ||||||
|
||||||
@property | ||||||
def name(self) -> str: | ||||||
return self.optimizer if isinstance(self.optimizer, str) else repr(self.optimizer) | ||||||
|
||||||
@property | ||||||
def batch_mode(self) -> bool: | ||||||
return self.executor.batch_mode | ||||||
return hasattr(self.executor, "batch_mode") and self.executor.batch_mode | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checking hasattr is not safe, if we update the code that could break without notice, it's much safer to test against a class |
||||||
|
||||||
def __repr__(self) -> str: | ||||||
return f"Experiment: {self.name}<budget={self.budget}, num_workers={self.num_workers}, batch_mode={self.batch_mode}>" | ||||||
|
@@ -207,7 +214,9 @@ def run(self) -> tp.Dict[str, tp.Any]: | |||||
def _log_results(self, pfunc: fbase.ExperimentFunction, t0: float, num_calls: int) -> None: | ||||||
"""Internal method for logging results before handling the error""" | ||||||
self.result["elapsed_time"] = time.time() - t0 | ||||||
self.result["pseudotime"] = self.optimsettings.executor.time | ||||||
self.result["pseudotime"] = ( | ||||||
self.optimsettings.executor.time if hasattr(self.optimsettings.executor, "time") else float("nan") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
# make a final evaluation with oracle (no noise, but function may still be stochastic) | ||||||
opt = self._optimizer | ||||||
assert opt is not None | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only for benchmark so let's make it clear