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

Timeout parameter to limit time (in seconds) of the search process (fmin) #533

Merged
merged 17 commits into from Dec 12, 2019

Conversation

vladkar
Copy link
Contributor

@vladkar vladkar commented Sep 3, 2019

max_time parameter was added to fmin:

  • stops searching process when allowed time is passed, works similar to max_evals parameter, but limits time of search instead of number of trials
  • can work together with max_evals
  • max_time=60 means that search process will be stopped after 60 seconds since its start with respect to last trial (if trial requires 10 seconds and it was started at second 59, then search process takes 69 second)
  • unit tests were prepared to check new parameter
  • progress bar was not changed (it works based on number of trials)

Update 11 Dec 2019:

  • max_time parameter was renamed to timeout to keep consistency with recent update
  • timeout parameter was added to fmin function for spark implementation as well (to keep configuration of timeout and max_evals in one place)

Copy link
Member

@marctorsoc marctorsoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments. You should also merge with master as now there are conflicts

hyperopt/fmin.py Outdated
@@ -9,6 +9,7 @@
import os
import sys
import time
import timeit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given you only use default_timer, what do you think about changing this to from timeit import default_timer as timer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

hyperopt/fmin.py Outdated
qlen = get_queue_len()
while qlen < self.max_queue_len and n_queued < N:
while qlen < self.max_queue_len and n_queued < N and (timeit.default_timer() - self.start_time) < self.max_time:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are u sure u need to check the time twice? can line 205 take long to run?

Copy link
Contributor Author

@vladkar vladkar Dec 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One is not required, condition was optimized

@@ -212,3 +214,36 @@ def test_generate_trials_to_calculate(self):
)
assert best['x'] == 0.0
assert best['y'] == 0.0


def test_max_time():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably can be written in a for loop. Ideally with pytest it would be with pytest.mark.parametrize but hyperopt doesn't use pytest yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it could be a cycle, but I intentionally keep it like this to make test readable and fast (taking into account that we literally need to wait to test timeout) as possible.

@marctorsoc
Copy link
Member

see #311. It seems to me the aim is the same, so it'd be nice to work together and close 2 PRs in 1 effort, if possible

Karbovskii Vladislav added 8 commits December 10, 2019 18:11
@vladkar vladkar changed the title max_time parameter to limit time (in seconds) of the search process (fmin) Timeout parameter to limit time (in seconds) of the search process (fmin) Dec 11, 2019
@vladkar
Copy link
Contributor Author

vladkar commented Dec 11, 2019

Pull request was updated:

  • max_time parameter was renamed to timeout to keep consistency with recent update
  • timeout parameter was added to fmin function (to keep configuration of timeout and max_evals in one place)

There are some failed tests at spark functionality, I am still working on it.

hyperopt/fmin.py Outdated
@@ -234,7 +239,8 @@ def get_n_unfinished():
) as progress_ctx:

all_trials_complete = False
while n_queued < N or (block_until_done and not all_trials_complete):
while (n_queued < N or (block_until_done and not all_trials_complete)) and \
(self.timeout is None or (timer() - self.start_time) < self.timeout):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be timer() - self.start_time < (self.timeout or float('inf')). Also, please use black to format code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, but version I used (a) subjectively more readable, (b) objectively faster

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black was applied

hyperopt/base.py Outdated
if timeout is not None and (
not isinstance(timeout, numbers.Number)
or timeout <= 0
or isinstance(timeout, bool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is redundant. If it's not a number, you don't need to check if it's a bool

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, if the docstring says int, then I think better to check here is int, rather than any number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not my code segment, I used check from spark implementation, but since I use the same parameter I just moved this check to separate method to base file. To not break something by accident I did not change the logic of this validation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. if you can reuse code from somwhere else, do it. Do not duplicate
  2. Either the docstring or check need to be changed, to match. The check allows for floats and has a check for bool that seems useless to me, while the docstring states int. I would change this code as I don't think we need float precision for a timeout in seconds

Copy link
Contributor Author

@vladkar vladkar Dec 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It was reused, not duplicated. As I mention, this check was just moved to base.
  2. I think this should have been discussed when this check was introduced to spark implementation. Again, I prefer to reuse it than make (almost) the same new check. And I do not want to influence existing logic, where this check is already used.

hyperopt/fmin.py Outdated
@@ -371,6 +378,10 @@ def fmin(
max_evals : int
Allow up to this many function evaluations before returning.

timeout : int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use style from other params :

timeout: None or int.
Limits ...
If None, then the search process has no time constraint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


def test_timeout():
fn = lambda x: [time.sleep(1), x][1]
space = hp.choice('x', range(20))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use black

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@vladkar
Copy link
Contributor Author

vladkar commented Dec 11, 2019

Ok, stuff was resolved

@vladkar
Copy link
Contributor Author

vladkar commented Dec 11, 2019

I guess there is issue with test 'test_task_maxFailures_warning', its result is inconsistent (sometimes it is ok, sometimes it is failed) even on pure master branch. See log as an example: build was ok, then it fails after cosmetic commit.

@marctorsoc
Copy link
Member

I don't know about that test. Could you please make it deterministic?

@marctorsoc
Copy link
Member

I don't know about that test. Could you please make it deterministic?

forget about it, seems to work. Ok, will review when I can and approve. @maxpumperla can you take a look at this?

@maxpumperla
Copy link
Contributor

@marctorrellas we need to look at unrelated tests separately

@vladkar great work, I have nothing to add. moving that check to base is fair, you don't have to clean up other PRs here. 👍

anything else you wanted to change or are we good to go from your side?

@vladkar
Copy link
Contributor Author

vladkar commented Dec 12, 2019

@marctorrellas @maxpumperla thank you for your feedback, that is it from my side for this PR.

@maxpumperla maxpumperla merged commit 11632b2 into hyperopt:master Dec 12, 2019
@marctorsoc
Copy link
Member

@vladkar good job, thanks for your contribution

@marctorsoc
Copy link
Member

@maxpumperla when is the next release expected? this and the functionality about verbosity are cool things I would like see soon :) count on me if you need a hand

@maxpumperla
Copy link
Contributor

@marctorrellas I want to fix that (apparently still around) BSON issue (#547) and look into lower/upper bounds for randint (#536) as a minimum here. got time to look at any one of these?

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

Successfully merging this pull request may close these issues.

None yet

3 participants