First commit to add modelbridge module and its test. #515
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feature/modelbridge Update Guide
このドキュメントは
feature/modelbridgeブランチで導入したモデルブリッジ設計の概要とレビュー時に押さえるべきポイントをまとめたものです。1. 全体像と目的
2. 主要モジュールと役割
aiaccel/hpo/modelbridgeapp.py:aiaccel-hpo modelbridgeの CLI エントリ。設定を Omegaconf 経由で読み込み、run_pipelineを呼び出します。config.py: 再設計仕様で定義した dataclass 群とload_bridge_configによる型付きバリデーション。マクロ/ミクロ両方のパラメータ空間を区別して管理します。runner.py: 実行フローの中心。マクロ・ミクロ各フェーズのトライアル実行、サンプル構築、回帰の学習・評価・成果物出力をまとめています。optimizers.py: Optuna を用いた最適化フェーズ実行(マクロ、ミクロ共通)。TrialContextに統一情報を詰めてevaluators.pyの Strategy へ渡します。evaluators.py: 設定から評価関数を動的ロードするための薄いラッパ。Python callable / 外部コマンドの両方をサポートします。regression.py: マクロ→ミクロを多出力線形モデルとして表現。RegressionSampleから NumPy の最小二乗で係数を推定し、predictions.csvに出力できる dict 形式の予測を返します。io.py,summary.py,logging.py,types.py: 結果ファイルの書き出し、サマリ集計、ロギング補助といった共通処理をコンパクトに提供します。exceptions.py: 設計上の不正状態(設定不備、評価失敗など)を表す独自例外。examples/hpo/modelbridgesimple_benchmark.py: 単一シナリオ(平滑な二変数関数)を使った極小例。マクロとミクロが同じ関数空間を探索し、回帰モデルを通じた推論・比較まで一周させます。multi_function_benchmark.py:modelbridge-ccの Simple Benchmark を着想源に、Sphere / Rastrigin / Griewank 間の橋渡しを複数シナリオで行います。SCENARIOS定義により各ケースのマクロ・ミクロ関数や回帰設定、トライアル数を切り替えています。3. 既存 aiaccel との関係
aiaccel/launcher.pyがaiaccel.hpo.modelbridge.appを呼び出すため、既存のaiaccel-hpo <subcommand>流儀と整合します。aiaccel.configのload_config,resolve_inherit,print_configをそのまま利用し、既存プロジェクトと同じ Config パターンでモデルブリッジを設定できます。4. 新機能・挙動の要点
RegressionSample(features=macro_params, target=micro_params)を生成。NumPy の最小二乗で複数パラメータを一度に回帰します。regression.jsonに学習済みパラメータを保存し、predictions.csvに実測値と推論値を併記。summary.jsonにはシナリオごとの試行回数・ベストパラメータ・評価値を集約します。BridgeSettings.seedでマクロ・ミクロ両フェーズの乱数を固定。run_pipelineが設定されたシードをフェーズ毎に使い分けている点も確認済みです。5. テストと検証
tests/hpo/test_modelbridge/に新たに軽量テストを整備。test_config.py: 設定のバリデーション挙動を検証。test_evaluators.py: Python callable とコマンド評価の双方が利用できることを確認。test_optimizers.py: Optuna フェーズの実行結果と最良パラメータ取得をチェック。test_regression.py: 多出力回帰の学習/不正入力時の例外を確認。test_runner.py: パイプラインの成果物(summary, trials, predictions)生成を一通り確認。6. サンプル実行方法
simple_benchmark
work/modelbridge/simple/配下にsummary.json,scenarios/simple/...が生成されます。predictions.csvで対比。multi_function_benchmark
work/modelbridge/multi_function/配下に、各シナリオ(sphere_to_rastriginなど)の成果物ディレクトリが作成されます。predictions.csvで比較が可能です。