From 30d08bb4127afa33c9443d776b36c746c7c6f2a1 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 11:40:19 +0900 Subject: [PATCH 01/23] add description --- ml_interfaces/bayesopt_interfaces/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml_interfaces/bayesopt_interfaces/setup.py b/ml_interfaces/bayesopt_interfaces/setup.py index 290dbe0..d13c984 100644 --- a/ml_interfaces/bayesopt_interfaces/setup.py +++ b/ml_interfaces/bayesopt_interfaces/setup.py @@ -9,7 +9,7 @@ def _requires_from_file(filename): version='0.1.0', author='Yuki Asano', author_email='yasano@g.ecc.u-tokyo.ac.jp', - description='', + description='Interface for Bayesian Optimization', packages=find_packages(), install_requires = _requires_from_file('requirements.txt') ) From 2fea4d7b5d7633848185370f93ad018bdef28d6b Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 11:45:47 +0900 Subject: [PATCH 02/23] add ci --- .github/workflows/bayesopt_interfaces.yaml | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/bayesopt_interfaces.yaml diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml new file mode 100644 index 0000000..b0e94bc --- /dev/null +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -0,0 +1,28 @@ +name: test + +on: + push: + pull_request: + +jobs: + build: + name: Run tests with pytest + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: [3.8] + os: [ubuntu-20.04] + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools + pip install pytest + - name: Run pytest + run: pytest -v ml_interfaces/bayesopt_interfaces/tests From 3f36036e37bee7e8d9739093e313e6b30f7e18d6 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 11:48:40 +0900 Subject: [PATCH 03/23] mod --- .github/workflows/bayesopt_interfaces.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index b0e94bc..32196d5 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -24,5 +24,6 @@ jobs: run: | python -m pip install --upgrade pip setuptools pip install pytest + pip install -r ml_interfaces/bayesopt_interfaces/requirements.txt - name: Run pytest run: pytest -v ml_interfaces/bayesopt_interfaces/tests From ab84d2753884b05a98851bddc277926d037df985 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 11:51:37 +0900 Subject: [PATCH 04/23] mod --- .github/workflows/bayesopt_interfaces.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index 32196d5..755d3cc 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -1,5 +1,3 @@ -name: test - on: push: pull_request: @@ -24,6 +22,9 @@ jobs: run: | python -m pip install --upgrade pip setuptools pip install pytest - pip install -r ml_interfaces/bayesopt_interfaces/requirements.txt + #pip install -r ml_interfaces/bayesopt_interfaces/requirements.txt + - name: Install bayesopt_interfaces + run: | + pip install ml_interfaces/bayesopt_interfaces - name: Run pytest run: pytest -v ml_interfaces/bayesopt_interfaces/tests From f4d3882c1b2a0cba229b24edc263ae9b5b48dcb7 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 12:00:27 +0900 Subject: [PATCH 05/23] mod --- .github/workflows/bayesopt_interfaces.yaml | 2 +- ml_interfaces/bayesopt_interfaces/requirements.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index 755d3cc..3c82758 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -27,4 +27,4 @@ jobs: run: | pip install ml_interfaces/bayesopt_interfaces - name: Run pytest - run: pytest -v ml_interfaces/bayesopt_interfaces/tests + run: pytest -v ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py diff --git a/ml_interfaces/bayesopt_interfaces/requirements.txt b/ml_interfaces/bayesopt_interfaces/requirements.txt index 5a7eca9..4000a06 100644 --- a/ml_interfaces/bayesopt_interfaces/requirements.txt +++ b/ml_interfaces/bayesopt_interfaces/requirements.txt @@ -1,2 +1,3 @@ matplotlib +pandas physbo From ce59a39a6764f3139c26896e22511acc922f46c6 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 12:02:46 +0900 Subject: [PATCH 06/23] mod --- ml_interfaces/bayesopt_interfaces/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ml_interfaces/bayesopt_interfaces/requirements.txt b/ml_interfaces/bayesopt_interfaces/requirements.txt index 4000a06..a3b25d0 100644 --- a/ml_interfaces/bayesopt_interfaces/requirements.txt +++ b/ml_interfaces/bayesopt_interfaces/requirements.txt @@ -1,3 +1,4 @@ matplotlib pandas physbo +pyyaml From 84305a6d6625f965e60a75dc4c63b7a1653e8893 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 12:32:16 +0900 Subject: [PATCH 07/23] mod test_physbo_interface files --- .../examples/data/candidates.csv | 21 ++++++++ .../examples/data/results.csv | 21 ++++++++ .../bayesopt_interfaces/examples/run_combo.py | 38 ++++++++++++++ .../examples/run_physbo.py | 50 +++++++++++++++++++ .../tests/data/candidates-correct.csv | 21 ++++++++ .../tests/test_physbo_interface.py | 13 +++-- 6 files changed, 157 insertions(+), 7 deletions(-) create mode 100644 ml_interfaces/bayesopt_interfaces/examples/data/candidates.csv create mode 100644 ml_interfaces/bayesopt_interfaces/examples/data/results.csv create mode 100755 ml_interfaces/bayesopt_interfaces/examples/run_combo.py create mode 100755 ml_interfaces/bayesopt_interfaces/examples/run_physbo.py create mode 100644 ml_interfaces/bayesopt_interfaces/tests/data/candidates-correct.csv diff --git a/ml_interfaces/bayesopt_interfaces/examples/data/candidates.csv b/ml_interfaces/bayesopt_interfaces/examples/data/candidates.csv new file mode 100644 index 0000000..2a1b71f --- /dev/null +++ b/ml_interfaces/bayesopt_interfaces/examples/data/candidates.csv @@ -0,0 +1,21 @@ +p1,p2,p3,p4,y +180,0,100,200, +180,0,200,200, +180,0,300,200, +180,0,400,200, +180,100,100,200, +180,100,200,200, +180,100,300,200, +180,100,400,200, +180,200,100,200, +180,200,200,200, +180,200,300,200, +180,200,400,200, +180,300,100,200, +180,300,200,200, +180,300,300,200, +180,300,400,200, +180,400,100,200, +180,400,200,200, +180,400,300,200, +180,400,400,200, diff --git a/ml_interfaces/bayesopt_interfaces/examples/data/results.csv b/ml_interfaces/bayesopt_interfaces/examples/data/results.csv new file mode 100644 index 0000000..be0f592 --- /dev/null +++ b/ml_interfaces/bayesopt_interfaces/examples/data/results.csv @@ -0,0 +1,21 @@ +y +0.001 +0.401 +0.398 +0.305 +0.001 +0.352 +0.350 +0.237 +0.350 +0.374 +0.288 +0.262 +0.290 +0.250 +0.245 +0.204 +0.216 +0.129 +0.151 +0.091 diff --git a/ml_interfaces/bayesopt_interfaces/examples/run_combo.py b/ml_interfaces/bayesopt_interfaces/examples/run_combo.py new file mode 100755 index 0000000..bca9c10 --- /dev/null +++ b/ml_interfaces/bayesopt_interfaces/examples/run_combo.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import random +import sys + +import combo +from bayesopt_if.combo_interface import ComboInterface + + +def main(): + # dir setting + candidates_path = './data/candidates.csv' + policy_load_dir = './data/load' + policy_save_dir = './data/result' + + # Generate combo + ci = ComboInterface(combo, candidates_path, policy_load_dir, policy_save_dir, use_saved_policy=False) + ci.start_bayesopt() + + # Write combo operation below + ## Following procedure is important for correct generation of result data. + ## search -> write(and update -> visualize) + for i in range(1): + ci.search_next_param_random() + ci.write_result(random.random()) # write result + for i in range(1): + ci.search_next_param_bayes() + ci.write_result(random.random()) # write result + + raw_input('Press enter to save and finish\n') + + ci.save_data(policy_save_dir) + + +if __name__ == '__main__': + main() diff --git a/ml_interfaces/bayesopt_interfaces/examples/run_physbo.py b/ml_interfaces/bayesopt_interfaces/examples/run_physbo.py new file mode 100755 index 0000000..1b97ff5 --- /dev/null +++ b/ml_interfaces/bayesopt_interfaces/examples/run_physbo.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import csv +import os +import sys + +from bayesopt_if.physbo_interface import PhysboInterface + + +def get_data_from_result_list(index): + with open('./data/results.csv') as f: + reader = csv.reader(f) + l = [row for row in reader] + + return float(l[index+1][0]) + + +def main(): + # dir setting + candidates_path = './data/candidates.csv' + policy_load_dir = './data/load' + policy_save_dir = './data/result' + + # Generate physbo + pi = PhysboInterface(candidates_path, policy_load_dir, policy_save_dir, use_saved_policy=False, search_score='EI') + pi.start_bayesopt() + + # Procedure of search and register data to PHYSBO + # - Following procedure is important for correct generation of result data. + # - search -> write (and update -> visualize) + + # Search with Random search for initial step + for i in range(3): + pi.search_next_param_random() + result = get_data_from_result_list(pi.get_next_index()) # get result/evaluation data from experiment. (Result list is used for this test program). + pi.write_result(result) # write result to PHYSBO + # Search with Bayesian optimization + for i in range(3): + pi.search_next_param_bayes() + result = get_data_from_result_list(pi.get_next_index()) + pi.write_result(result) + + input('Press enter to save and finish\n') + + pi.save_data(policy_save_dir) + + +if __name__ == '__main__': + main() diff --git a/ml_interfaces/bayesopt_interfaces/tests/data/candidates-correct.csv b/ml_interfaces/bayesopt_interfaces/tests/data/candidates-correct.csv new file mode 100644 index 0000000..67d7216 --- /dev/null +++ b/ml_interfaces/bayesopt_interfaces/tests/data/candidates-correct.csv @@ -0,0 +1,21 @@ +p1,p2,p3,p4,y +180,0,100,200,0.001 +180,0,200,200,0.401 +180,0,300,200,0.398 +180,0,400,200,0.305 +180,100,100,200,0.001 +180,100,200,200,0.352 +180,100,300,200,0.35 +180,100,400,200,0.237 +180,200,100,200,0.35 +180,200,200,200,0.374 +180,200,300,200,0.288 +180,200,400,200,0.262 +180,300,100,200,0.29 +180,300,200,200,0.25 +180,300,300,200,0.245 +180,300,400,200,0.204 +180,400,100,200,0.216 +180,400,200,200,0.129 +180,400,300,200,0.151 +180,400,400,200,0.091 diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py index 1b97ff5..b3b9741 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import csv +import filecmp import os import sys @@ -16,9 +17,10 @@ def get_data_from_result_list(index): return float(l[index+1][0]) -def main(): +def test_physbo_interface(): # dir setting candidates_path = './data/candidates.csv' + correct_candidates_path = './data/candidates-correct.csv' policy_load_dir = './data/load' policy_save_dir = './data/result' @@ -36,15 +38,12 @@ def main(): result = get_data_from_result_list(pi.get_next_index()) # get result/evaluation data from experiment. (Result list is used for this test program). pi.write_result(result) # write result to PHYSBO # Search with Bayesian optimization - for i in range(3): + for i in range(17): pi.search_next_param_bayes() result = get_data_from_result_list(pi.get_next_index()) pi.write_result(result) - input('Press enter to save and finish\n') - + #input('Press enter to save and finish\n') pi.save_data(policy_save_dir) - -if __name__ == '__main__': - main() + assert filecmp.cmp(candidates_path, correct_candidates_path) From e610f08fc7b595553e1d9eadd6c7ed06bd4c733f Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 12:49:58 +0900 Subject: [PATCH 08/23] fix path --- .../tests/test_physbo_interface.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py index b3b9741..b1ef838 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py @@ -8,6 +8,9 @@ from bayesopt_if.physbo_interface import PhysboInterface +file_dir = os.path.dirname(__file__) +data_dir = os.path.join(file_dir, 'data') + def get_data_from_result_list(index): with open('./data/results.csv') as f: @@ -19,10 +22,10 @@ def get_data_from_result_list(index): def test_physbo_interface(): # dir setting - candidates_path = './data/candidates.csv' - correct_candidates_path = './data/candidates-correct.csv' - policy_load_dir = './data/load' - policy_save_dir = './data/result' + candidates_path = os.path.join(data_dir, 'candidates.csv') + correct_candidates_path = os.path.join(data_dir, 'candidates-correct.csv') + policy_load_dir = os.path.join(data_dir, 'load') + policy_save_dir = os.path.join(data_dir, 'result') # Generate physbo pi = PhysboInterface(candidates_path, policy_load_dir, policy_save_dir, use_saved_policy=False, search_score='EI') From 67a5a6c2ca69d702701cfa13ad2cf1d4a955f73b Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 12:52:58 +0900 Subject: [PATCH 09/23] fix path --- .../bayesopt_interfaces/tests/test_physbo_interface.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py index b1ef838..e2dabb5 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py @@ -13,7 +13,8 @@ def get_data_from_result_list(index): - with open('./data/results.csv') as f: + results_path = os.path.join(data_dir, 'results.csv') + with open(results_path) as f: reader = csv.reader(f) l = [row for row in reader] From 512f5bbc52911e7ef21f27f6c64e350f84514a88 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 13:09:20 +0900 Subject: [PATCH 10/23] add test for combo_interface --- .github/workflows/bayesopt_interfaces.yaml | 37 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index 3c82758..2fd18d8 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -3,14 +3,13 @@ on: pull_request: jobs: - build: - name: Run tests with pytest + tests_physbo_interface: + name: Run tests for physbo_interface runs-on: ${{ matrix.os }} strategy: matrix: python-version: [3.8] os: [ubuntu-20.04] - steps: - name: Checkout uses: actions/checkout@v3 @@ -22,9 +21,39 @@ jobs: run: | python -m pip install --upgrade pip setuptools pip install pytest - #pip install -r ml_interfaces/bayesopt_interfaces/requirements.txt - name: Install bayesopt_interfaces run: | pip install ml_interfaces/bayesopt_interfaces - name: Run pytest run: pytest -v ml_interfaces/bayesopt_interfaces/tests/test_physbo_interface.py + + tests_combo_interface: + name: Run tests for combo_interface + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: [2.7] + os: [ubuntu-20.04] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools + pip install pytest + - name: Install combo + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git clone https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/tsudalab/combo.git + cd combo + python setup.py install + - name: Install bayesopt_interfaces + run: | + pip install ml_interfaces/bayesopt_interfaces + - name: Run pytest + run: pytest -v ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py From 4905b5cfc7d0b6f8a80fabb129c87a0db167e869 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 13:28:56 +0900 Subject: [PATCH 11/23] use python2 image --- .github/workflows/bayesopt_interfaces.yaml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index 2fd18d8..2b53e71 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -32,15 +32,18 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: [2.7] + #python-version: [2.7] os: [ubuntu-20.04] + container: + image: python:2.7.18-buster steps: - name: Checkout uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} + + #- name: Set up Python ${{ matrix.python-version }} + # uses: actions/setup-python@v5 + # with: + # python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip setuptools From d52021d51f43a28a61f3306bca7a5ebbe1f461cc Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 13:34:15 +0900 Subject: [PATCH 12/23] add cython --- .github/workflows/bayesopt_interfaces.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index 2b53e71..460d20d 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -47,7 +47,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip setuptools - pip install pytest + pip install pytest cython - name: Install combo env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 8261336fe387b0a9f4d02dfe8e0d35edd6f236fb Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 13:35:29 +0900 Subject: [PATCH 13/23] add numpy --- .github/workflows/bayesopt_interfaces.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index 460d20d..c1a38f8 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -47,7 +47,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip setuptools - pip install pytest cython + pip install pytest cython numpy - name: Install combo env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b6068cead40cb69de7130167b0316e49bfb528aa Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 13:42:30 +0900 Subject: [PATCH 14/23] mod test for combo_interface --- .../tests/test_combo_interface.py | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py index bca9c10..9dc06eb 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import csv +import filecmp import os import random import sys @@ -8,12 +10,25 @@ import combo from bayesopt_if.combo_interface import ComboInterface +file_dir = os.path.dirname(__file__) +data_dir = os.path.join(file_dir, 'data') -def main(): + +def get_data_from_result_list(index): + results_path = os.path.join(data_dir, 'results.csv') + with open(results_path) as f: + reader = csv.reader(f) + l = [row for row in reader] + + return float(l[index+1][0]) + + +def test_combo_interface(): # dir setting - candidates_path = './data/candidates.csv' - policy_load_dir = './data/load' - policy_save_dir = './data/result' + candidates_path = os.path.join(data_dir, 'candidates.csv') + correct_candidates_path = os.path.join(data_dir, 'candidates-correct.csv') + policy_load_dir = os.path.join(data_dir, 'load') + policy_save_dir = os.path.join(data_dir, 'result') # Generate combo ci = ComboInterface(combo, candidates_path, policy_load_dir, policy_save_dir, use_saved_policy=False) @@ -22,17 +37,20 @@ def main(): # Write combo operation below ## Following procedure is important for correct generation of result data. ## search -> write(and update -> visualize) - for i in range(1): + for i in range(3): ci.search_next_param_random() - ci.write_result(random.random()) # write result - for i in range(1): + result = get_data_from_result_list(ci.get_next_index()) # get result/evaluation data from experiment. (Result list is used for this test program). + ci.write_result(result) # write result + for i in range(17): ci.search_next_param_bayes() - ci.write_result(random.random()) # write result - - raw_input('Press enter to save and finish\n') + result = get_data_from_result_list(ci.get_next_index()) + ci.write_result(result) # write result + #raw_input('Press enter to save and finish\n') ci.save_data(policy_save_dir) + assert filecmp.cmp(candidates_path, correct_candidates_path) + if __name__ == '__main__': - main() + test_combo_interface() From 948a9c41c14dbac6adddf7aaea3351bb52a4dd7d Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 14:08:57 +0900 Subject: [PATCH 15/23] display --- .github/workflows/bayesopt_interfaces.yaml | 8 +++++++- .../bayesopt_interfaces/tests/test_combo_interface.py | 4 ---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index c1a38f8..fd91624 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -59,4 +59,10 @@ jobs: run: | pip install ml_interfaces/bayesopt_interfaces - name: Run pytest - run: pytest -v ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py + run: | + disp=:99 + screen=0 + geom=640x480x24 + exec Xvfb $disp -screen $screen $geom 2>/tmp/Xvfb.log & + export DISPLAY=:99 + pytest -v ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py index 9dc06eb..a08c16a 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py @@ -50,7 +50,3 @@ def test_combo_interface(): ci.save_data(policy_save_dir) assert filecmp.cmp(candidates_path, correct_candidates_path) - - -if __name__ == '__main__': - test_combo_interface() From 2b055b67f5c9d5681e6a9f8d69a7086a2c19459f Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 14:32:46 +0900 Subject: [PATCH 16/23] fix viaulization --- .github/workflows/bayesopt_interfaces.yaml | 10 +++++----- .../bayesopt_if/combo_interface.py | 13 ++++++++----- .../bayesopt_if/physbo_interface.py | 3 ++- .../tests/test_combo_interface.py | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index fd91624..bab8e75 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -60,9 +60,9 @@ jobs: pip install ml_interfaces/bayesopt_interfaces - name: Run pytest run: | - disp=:99 - screen=0 - geom=640x480x24 - exec Xvfb $disp -screen $screen $geom 2>/tmp/Xvfb.log & - export DISPLAY=:99 + #disp=:99 + #screen=0 + #geom=640x480x24 + #exec Xvfb $disp -screen $screen $geom 2>/tmp/Xvfb.log & + #export DISPLAY=:99 pytest -v ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py diff --git a/ml_interfaces/bayesopt_interfaces/bayesopt_if/combo_interface.py b/ml_interfaces/bayesopt_interfaces/bayesopt_if/combo_interface.py index 592ae83..bf74711 100755 --- a/ml_interfaces/bayesopt_interfaces/bayesopt_if/combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/bayesopt_if/combo_interface.py @@ -20,7 +20,7 @@ class ComboInterface(): - def __init__(self, bayesopt, candidates_path='candidates.csv', policy_load_dir='.', policy_save_dir='.', use_saved_policy=False, search_score='PI'): + def __init__(self, bayesopt, candidates_path='candidates.csv', policy_load_dir='.', policy_save_dir='.', use_saved_policy=False, visualize=True, search_score='PI'): self.data = None self.X = None self.actions = None @@ -32,6 +32,7 @@ def __init__(self, bayesopt, candidates_path='candidates.csv', policy_load_dir=' self.policy_load_dir = policy_load_dir self.policy_save_dir = policy_save_dir self.use_saved_policy = use_saved_policy + self.visualize = visualize self.search_mode = 0 # 0: random search, 1: bayes self.search_score = search_score # score: PI, EI, TS self.is_write_completed = False @@ -54,10 +55,11 @@ def start_bayesopt(self): self.generate_policy() # for visualization - self.fig, self.ax = plt.subplots(2, 1, tight_layout=True) # avoid overlap of labels + if self.visualize: + self.fig, self.ax = plt.subplots(2, 1, tight_layout=True) # avoid overlap of labels - # visualize - self.visualize() + # visualize + self.visualize() def load_dataset(self): @@ -214,7 +216,8 @@ def save_candidates_with_scores(self, policy_save_dir='.'): def save_plt(self, policy_save_dir='.'): # update before save - self.visualize() + if self.visualize: + self.visualize() # save plot plt_save_path_png = os.path.join(policy_save_dir, 'plt.png') plt_save_path_pdf = os.path.join(policy_save_dir, 'plt.pdf') diff --git a/ml_interfaces/bayesopt_interfaces/bayesopt_if/physbo_interface.py b/ml_interfaces/bayesopt_interfaces/bayesopt_if/physbo_interface.py index d3d347e..c295a54 100755 --- a/ml_interfaces/bayesopt_interfaces/bayesopt_if/physbo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/bayesopt_if/physbo_interface.py @@ -10,7 +10,7 @@ class PhysboInterface(ComboInterface): - def __init__(self, candidates_path='candidates.csv', policy_load_dir='.', policy_save_dir='.', use_saved_policy=False, search_score='PI'): + def __init__(self, candidates_path='candidates.csv', policy_load_dir='.', policy_save_dir='.', use_saved_policy=False, visualize=True, search_score='PI'): self.candidates_path = candidates_path self.policy_load_dir = policy_load_dir self.policy_save_dir = policy_save_dir @@ -24,6 +24,7 @@ def __init__(self, candidates_path='candidates.csv', policy_load_dir='.', policy self.policy_load_dir, self.policy_save_dir, self.use_saved_policy, + self.visualize, self.search_score) # python3 description diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py index a08c16a..5889622 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py @@ -31,7 +31,7 @@ def test_combo_interface(): policy_save_dir = os.path.join(data_dir, 'result') # Generate combo - ci = ComboInterface(combo, candidates_path, policy_load_dir, policy_save_dir, use_saved_policy=False) + ci = ComboInterface(combo, candidates_path, policy_load_dir, policy_save_dir, use_saved_policy=False, visualize=False) ci.start_bayesopt() # Write combo operation below From 95bf741779998ec4fc8818de066e04213d95ff26 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 14:43:04 +0900 Subject: [PATCH 17/23] fix --- ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py index 5889622..952754e 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py @@ -41,7 +41,7 @@ def test_combo_interface(): ci.search_next_param_random() result = get_data_from_result_list(ci.get_next_index()) # get result/evaluation data from experiment. (Result list is used for this test program). ci.write_result(result) # write result - for i in range(17): + for i in range(16): ci.search_next_param_bayes() result = get_data_from_result_list(ci.get_next_index()) ci.write_result(result) # write result From 604cd141eb3c3b36eb3c738fe668c80699eab71d Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 15:01:32 +0900 Subject: [PATCH 18/23] mod --- .github/workflows/bayesopt_interfaces.yaml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/bayesopt_interfaces.yaml b/.github/workflows/bayesopt_interfaces.yaml index bab8e75..1aee45d 100644 --- a/.github/workflows/bayesopt_interfaces.yaml +++ b/.github/workflows/bayesopt_interfaces.yaml @@ -32,18 +32,12 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - #python-version: [2.7] os: [ubuntu-20.04] container: image: python:2.7.18-buster steps: - name: Checkout uses: actions/checkout@v3 - - #- name: Set up Python ${{ matrix.python-version }} - # uses: actions/setup-python@v5 - # with: - # python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip setuptools @@ -60,9 +54,4 @@ jobs: pip install ml_interfaces/bayesopt_interfaces - name: Run pytest run: | - #disp=:99 - #screen=0 - #geom=640x480x24 - #exec Xvfb $disp -screen $screen $geom 2>/tmp/Xvfb.log & - #export DISPLAY=:99 pytest -v ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py From 2341f16fddde03825d081b5a5f0f31f9785ca78e Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 15:02:28 +0900 Subject: [PATCH 19/23] mod --- .../bayesopt_interfaces/tests/test_combo_interface.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py index 952754e..b0a8932 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py @@ -23,6 +23,7 @@ def get_data_from_result_list(index): return float(l[index+1][0]) +@pytest.mark.filterwarnings("ignore:SettingWithCopyWarning") def test_combo_interface(): # dir setting candidates_path = os.path.join(data_dir, 'candidates.csv') @@ -41,10 +42,10 @@ def test_combo_interface(): ci.search_next_param_random() result = get_data_from_result_list(ci.get_next_index()) # get result/evaluation data from experiment. (Result list is used for this test program). ci.write_result(result) # write result - for i in range(16): + for i in range(17): ci.search_next_param_bayes() result = get_data_from_result_list(ci.get_next_index()) - ci.write_result(result) # write result + ci.write_result(result) #raw_input('Press enter to save and finish\n') ci.save_data(policy_save_dir) From 78dd9e05cc85ae2032a39d9e3c5a4ac76097f263 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 15:09:18 +0900 Subject: [PATCH 20/23] mod --- ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py index b0a8932..42c050b 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py @@ -4,6 +4,7 @@ import csv import filecmp import os +import pytest import random import sys From c12540aa7b732da9dfab6bfc172fe8498070252c Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 15:15:36 +0900 Subject: [PATCH 21/23] mod --- .../bayesopt_interfaces/bayesopt_if/combo_interface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ml_interfaces/bayesopt_interfaces/bayesopt_if/combo_interface.py b/ml_interfaces/bayesopt_interfaces/bayesopt_if/combo_interface.py index bf74711..a7cb755 100755 --- a/ml_interfaces/bayesopt_interfaces/bayesopt_if/combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/bayesopt_if/combo_interface.py @@ -171,7 +171,8 @@ def save_data(self, policy_save_dir='.'): self.save_policy(self.policy_save_dir) self.save_candidates_and_actions(self.policy_save_dir) # csv self.save_candidates_with_scores(self.policy_save_dir) # csv - self.save_plt(self.policy_save_dir) + if self.visualize: + self.save_plt(self.policy_save_dir) def save_policy(self, policy_save_dir='.'): @@ -216,8 +217,7 @@ def save_candidates_with_scores(self, policy_save_dir='.'): def save_plt(self, policy_save_dir='.'): # update before save - if self.visualize: - self.visualize() + self.visualize() # save plot plt_save_path_png = os.path.join(policy_save_dir, 'plt.png') plt_save_path_pdf = os.path.join(policy_save_dir, 'plt.pdf') From 42be4ecdb6e06860c6e1319a2599299a9211e3f1 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 15:18:02 +0900 Subject: [PATCH 22/23] mod --- ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py index 42c050b..78221b2 100755 --- a/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py +++ b/ml_interfaces/bayesopt_interfaces/tests/test_combo_interface.py @@ -4,7 +4,6 @@ import csv import filecmp import os -import pytest import random import sys @@ -24,7 +23,6 @@ def get_data_from_result_list(index): return float(l[index+1][0]) -@pytest.mark.filterwarnings("ignore:SettingWithCopyWarning") def test_combo_interface(): # dir setting candidates_path = os.path.join(data_dir, 'candidates.csv') From 86110a305bd7ad0c34f849584f6a2a286e45e4c5 Mon Sep 17 00:00:00 2001 From: Yuki Asano Date: Wed, 12 Feb 2025 15:18:10 +0900 Subject: [PATCH 23/23] mod gitignore --- ml_interfaces/bayesopt_interfaces/.gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ml_interfaces/bayesopt_interfaces/.gitignore b/ml_interfaces/bayesopt_interfaces/.gitignore index ff043ed..6dfb7ca 100644 --- a/ml_interfaces/bayesopt_interfaces/.gitignore +++ b/ml_interfaces/bayesopt_interfaces/.gitignore @@ -1,2 +1,6 @@ *.~ -*.pyc \ No newline at end of file +*.pyc +examples/data/chosen_actions.csv +examples/data/result +tests/data/chosed_actions.csv +tests/data/result