Skip to content

Commit

Permalink
Feature/v2 patch 1 (#407)
Browse files Browse the repository at this point in the history
* change resumable

* fix test

* fix resume test

* Update documents (#402)

* Update index.rst

* Update docs

* Fix dependencies

* Added docs for v2 (#403)

* updated contribution_guide.md

* Split contribution_guide.md

---------

Co-authored-by: Yoshiaki Bando <[email protected]>

* Update aiaccel logo to a transparent one (#404)

* Update logo

* Update conf.py

* rollback .github/workflows/ci.yaml

* fix --config setting

* reafctoring: aiaccel/hpo/apps/optimize.py

---------

Co-authored-by: Yoshiaki Bando <[email protected]>
Co-authored-by: 3bisuoka <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent 31dd240 commit 828ed8b
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 29 deletions.
Empty file.
13 changes: 13 additions & 0 deletions aiaccel/hpo/apps/config/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
study:
_target_: optuna.create_study
direction: minimize
storage:
_target_: optuna.storages.InMemoryStorage
study_name: aiaccel_study
load_if_exists: false

params:
_convert_: partial
_target_: aiaccel.hpo.apps.optimize.HparamsManager

n_max_jobs: 1
8 changes: 8 additions & 0 deletions aiaccel/hpo/apps/config/resumable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
study:
study_name: aiaccel_study
storage:
_target_: optuna.storages.RDBStorage
url: sqlite:///aiaccel.db
engine_kwargs:
connect_args:
timeout: 30
21 changes: 11 additions & 10 deletions aiaccel/hpo/apps/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
from collections.abc import Callable
import importlib.resources
from pathlib import Path
import pickle as pkl

Expand All @@ -12,6 +13,7 @@

from aiaccel.hpo.job_executors import AbciJobExecutor, BaseJobExecutor, LocalJobExecutor
from aiaccel.hpo.optuna.suggest_wrapper import Const, Suggest, SuggestFloat, T
from aiaccel.utils import print_config


class HparamsManager:
Expand Down Expand Up @@ -112,26 +114,25 @@ def main() -> None:

parser = argparse.ArgumentParser()
parser.add_argument("job_filename", type=Path, help="The shell script to execute.")
parser.add_argument("--config", nargs="?", default=None)
parser.add_argument("--config", help="Configuration file path")
parser.add_argument("--executor", nargs="?", default="local")
parser.add_argument("--resume", action="store_true", default=False)
parser.add_argument("--resumable", action="store_true", default=False)

args, unk_args = parser.parse_known_args()
config = oc.merge(oc.load(args.config), oc.from_cli(unk_args))

if "storage" not in config.study:
config.study.storage = {
"_target_": "optuna.storages.RDBStorage",
"url": "sqlite:///optuna.db",
"engine_kwargs": {"connect_args": {"timeout": 30}},
}
default_config = oc.load(importlib.resources.open_text("aiaccel.hpo.apps.config", "default.yaml"))
config = oc.merge(default_config, oc.load(args.config) if args.config is not None else {})
config = oc.merge(config, oc.from_cli(unk_args))

if "study_name" not in config.study:
config.study.study_name = "aiaccel_study"
if (args.resumable or args.resume) and ("storage" not in config.study or args.config is None):
config = oc.merge(config, oc.load(importlib.resources.open_text("aiaccel.hpo.apps.config", "resumable.yaml")))

if args.resume:
config.study.load_if_exists = True

print_config(config)

jobs: BaseJobExecutor

if args.executor.lower() == "local":
Expand Down
19 changes: 0 additions & 19 deletions examples/job/optuna/config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
storage:
_target_: optuna.storages.RDBStorage
url: sqlite:///example.db
engine_kwargs:
connect_args:
timeout: 30

study:
_target_: optuna.create_study
direction: minimize
storage: ${storage}
study_name: my_study
load_if_exists: false
sampler:
_target_: optuna.samplers.TPESampler
seed: 0

params:
_convert_: partial
_target_: aiaccel.hpo.apps.optimize.HparamsManager
Expand All @@ -28,5 +11,3 @@ params:

n_trials: 30
n_max_jobs: 4

group: gaa50000
32 changes: 32 additions & 0 deletions tests/hpo/apps/main/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
storage:
_target_: optuna.storages.RDBStorage
url: sqlite:///aiaccel_storage.db
engine_kwargs:
connect_args:
timeout: 30

study:
_target_: optuna.create_study
direction: minimize
storage: ${storage}
study_name: my_study
load_if_exists: false
sampler:
_target_: optuna.samplers.TPESampler
seed: 0

params:
_convert_: partial
_target_: aiaccel.hpo.apps.optimize.HparamsManager
x1: [0, 1]
x2:
_target_: aiaccel.hpo.optuna.suggest_wrapper.SuggestFloat
name: x2
low: 0.0
high: 1.0
log: false

n_trials: 30
n_max_jobs: 1

group: gaa50000
24 changes: 24 additions & 0 deletions tests/hpo/apps/main/in_memory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
study:
_target_: optuna.create_study
direction: minimize
study_name: my_study
load_if_exists: false
sampler:
_target_: optuna.samplers.TPESampler
seed: 0

params:
_convert_: partial
_target_: aiaccel.hpo.apps.optimize.HparamsManager
x1: [0, 1]
x2:
_target_: aiaccel.hpo.optuna.suggest_wrapper.SuggestFloat
name: x2
low: 0.0
high: 1.0
log: false

n_trials: 30
n_max_jobs: 1

group: gaa50000
10 changes: 10 additions & 0 deletions tests/hpo/apps/main/objective.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

#$-l rt_C.small=1
#$-cwd

source /etc/profile.d/modules.sh
module load gcc/13.2.0
module load python/3.10/3.10.14

python objective_for_test.py $@
22 changes: 22 additions & 0 deletions tests/hpo/apps/main/objective_for_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from argparse import ArgumentParser
from pathlib import Path
import pickle as pkl


def main() -> None:
parser = ArgumentParser()
parser.add_argument("dst_filename", type=Path)
parser.add_argument("--x1", type=float)
parser.add_argument("--x2", type=float)
args = parser.parse_args()

x1, x2 = args.x1, args.x2

y = (x1**2) - (4.0 * x1) + (x2**2) - x2 - (x1 * x2)

with open(args.dst_filename, "wb") as f:
pkl.dump(y, f)


if __name__ == "__main__":
main()
Loading

0 comments on commit 828ed8b

Please sign in to comment.