Parallel Execution and Optuna Optimization Tools for AHC
Project description
titan23 が使用している、AHC のツールです。 ありえないバグがあるかもしれません。ご注意ください。
使い方
初期設定
作業ディレクトリで以下のコマンドを実行し、設定ファイル ahc_settings ファイルを生成します
python3 -m ahclib setup
並列実行
njobs 数のスレッドを立ち上げて実行します。結果を記録した csv ファイルと実行ソースファイルが ./ahclib_results/ ディレクトリに保存されます
コマンドは以下です
python3 -m ahclib test [-c] [-v] [-r]
オプション
-c : コンパイルします
-v : ログを表示します(推奨)
-r : 標準出力と標準エラー出力をすべて保存します
Optuna を用いたパラメータ探索
コマンドは以下です
python3 -m ahclib opt
設定ファイル
設定ファイル ahc_settings 中の AHCSettings クラスに以下の情報を書いてください
スレッド数 (njobs)
(パソコンの最大スレッド数-1)との min がとられる
ファイル名 (filename)
コンパイルコマンド (compile_command)
コンパイルする必要が無いときは、None とする
実行コマンド (execute_command)
入力ファイル (input_file_names)
list[str] の形式で書く
制限時間 (timeout)
ms 単位で指定する
指定しないときは None とする
各テストでメモリを多く使う場合など、正確さに欠けることがある点に注意
集計関数 (get_score)
例: 平均など
例:
njobs = 127
filename = "./main.cpp"
compile_command = "g++ ./main.cpp -O2 -std=c++20 -o a.out -I./../../../Library_cpp"
execute_command = "./a.out"
input_file_names = [f"./in/{str(i).zfill(4)}.txt" for i in range(100)]
timeout = None
def get_score(scores: list[float]) -> float:
return sum(scores) / len(scores)
Optuna を用いたパラメータ探索用の設定
study_name
study_name が既にある場合、そのデータベースが利用される
direction
minimize か maximize
optuna の試行回数 (n_trials)
optuna のスレッド数 (n_jobs_optuna)
推定するもの
def objective(trial: optuna.trial.Trial) -> tuple:返り値のタプルはコマンドライン引数として渡す順番にする
例: 初期温度を探索する
study_name = "test"
direction = "minimize"
n_trials = 50
n_jobs_optuna = 1
def objective(trial: optuna.trial.Trial) -> tuple:
start_temp = trial.suggest_float("start_temp", 1, 1e9, log=True)
return start_temp, # タプルで返す
double start_temp;
int main(int argc, char *argv[]) {
start_temp = std::stod(argv[1]); // argv[1], ... に objective で返した値が格納されている
solve();
return 0;
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ahclib-0.1.0.tar.gz.
File metadata
- Download URL: ahclib-0.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b537288b1ed12555059feb270ab12e6bd7a3d1ac8c725b873a704f520e5445aa
|
|
| MD5 |
1ae45b3894febe37ffb96af9625afc99
|
|
| BLAKE2b-256 |
3cdcad050b14d5d191cbb22fd47f91d5fa128a4c6999b77b3209825dc32c86c0
|
File details
Details for the file ahclib-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ahclib-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40f54ae07d9cb6028801a5527ed61de7481523f8a4da5082ef2642c6737c9e04
|
|
| MD5 |
a59427aabc172ca847494531f6bb81f7
|
|
| BLAKE2b-256 |
cc67db375bb1c579e4d06c61530051ad5016910b2a91a6aeb1098c55bebbd7ea
|