Skip to content

Commit

Permalink
set_search_properties (#595)
Browse files Browse the repository at this point in the history
* update the signature of set_search_properties
  • Loading branch information
sonichi authored Jun 16, 2022
1 parent 4c044e8 commit 1b40b4b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,32 @@ jobs:
pip install -e .
python -c "import flaml"
pip install -e .[test]
- name: If linux or mac, install ray and prophet
- name: If linux or mac, install ray
if: matrix.os == 'macOS-latest' || matrix.os == 'ubuntu-latest'
run: |
pip install -e .[ray]
- name: If linux or mac, install prophet on python < 3.9
if: (matrix.os == 'macOS-latest' || matrix.os == 'ubuntu-latest') && matrix.python-version != '3.9' && matrix.python-version != '3.10'
run: |
pip install -e .[ray,forecast]
pip install 'tensorboardX<=2.2'
pip install -e .[forecast]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
if: ${{ (matrix.python-version != '3.7' || matrix.os == 'macos-latest') && matrix.python-version != '3.10' }}
if: (matrix.python-version != '3.7' || matrix.os == 'macos-latest') && matrix.python-version != '3.10'
run: |
pytest test
- name: Coverage
if: ${{ (matrix.python-version == '3.7') && matrix.os != 'macos-latest' || matrix.python-version == '3.10' }}
if: (matrix.python-version == '3.7') && matrix.os != 'macos-latest' || matrix.python-version == '3.10'
run: |
pip install coverage
coverage run -a -m pytest test
coverage xml
- name: Upload coverage to Codecov
if: ${{ (matrix.python-version == '3.7') && matrix.os != 'macos-latest' || matrix.python-version == '3.10'}}
if: (matrix.python-version == '3.7') && matrix.os != 'macos-latest' || matrix.python-version == '3.10'
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
Expand Down
4 changes: 1 addition & 3 deletions flaml/automl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2992,9 +2992,7 @@ def _search_sequential(self):
search_state.search_alg.searcher.set_search_properties(
metric=None,
mode=None,
setting={
"metric_target": self._state.best_loss,
},
metric_target=self._state.best_loss,
)
start_run_time = time.time()
analysis = tune.run(
Expand Down
16 changes: 8 additions & 8 deletions flaml/searcher/blendsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def set_search_properties(
metric: Optional[str] = None,
mode: Optional[str] = None,
config: Optional[Dict] = None,
setting: Optional[Dict] = None,
**spec,
) -> bool:
metric_changed = mode_changed = False
if metric and self._metric != metric:
Expand Down Expand Up @@ -272,21 +272,21 @@ def set_search_properties(
)
self._gs.space = self._ls.space
self._init_search()
if setting:
if spec:
# CFO doesn't need these settings
if "time_budget_s" in setting:
self._time_budget_s = setting["time_budget_s"] # budget from now
if "time_budget_s" in spec:
self._time_budget_s = spec["time_budget_s"] # budget from now
now = time.time()
self._time_used += now - self._start_time
self._start_time = now
self._set_deadline()
if self._input_cost_attr == "auto":
self.cost_attr = TIME_TOTAL_S
if "metric_target" in setting:
self._metric_target = setting.get("metric_target")
if "num_samples" in setting:
if "metric_target" in spec:
self._metric_target = spec.get("metric_target")
if "num_samples" in spec:
self._num_samples = (
setting["num_samples"]
spec["num_samples"]
+ len(self._result)
+ len(self._trial_proposed_by)
)
Expand Down
2 changes: 1 addition & 1 deletion flaml/tune/tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def easy_objective(config):
setting["time_budget_s"] = time_budget_s
if num_samples > 0:
setting["num_samples"] = num_samples
searcher.set_search_properties(metric, mode, config, setting)
searcher.set_search_properties(metric, mode, config, **setting)
else:
searcher.set_search_properties(metric, mode, config)
if scheduler in ("asha", "asynchyperband", "async_hyperband"):
Expand Down
4 changes: 3 additions & 1 deletion test/tune/test_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ def test_searcher():
points_to_evaluate=[{"a": 1, "b": 0.01}],
)
searcher.set_search_properties(
metric="m2", config=config, setting={"time_budget_s": 0}
metric="m2",
config=config,
time_budget_s=0,
)
c = searcher.suggest("t1")
print("t1", c)
Expand Down

0 comments on commit 1b40b4b

Please sign in to comment.