46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""S2: 验证 run_optimization 容器内多进程 API + spawn context。
|
||
|
||
vnpy 4.4.0 重构:run_optimization 是 BacktestingEngine 方法(非顶层函数)。
|
||
multiprocessing 用 get_context("spawn"),与 AlphaDataset.prepare_data 同机制
|
||
(S1 已证容器内 spawn pool 工作)。
|
||
"""
|
||
import sys
|
||
import os
|
||
sys.path.insert(0, "/app/vnpy_v4.4.0")
|
||
|
||
|
||
def main():
|
||
import inspect
|
||
results = {}
|
||
|
||
try:
|
||
from vnpy_ctastrategy.backtesting import (
|
||
BacktestingEngine, run_bf_optimization, run_ga_optimization, OptimizationSetting
|
||
)
|
||
results["import"] = "OK (vnpy_ctastrategy 1.4.1)"
|
||
results["engine.run_optimization"] = str(inspect.signature(BacktestingEngine.run_optimization))
|
||
results["run_bf_optimization"] = "OK (顶层 brute-force)"
|
||
results["OptimizationSetting"] = "OK (可构造)"
|
||
except Exception as e:
|
||
import traceback; traceback.print_exc()
|
||
results["import"] = f"FAIL: {e}"
|
||
|
||
# spawn context 确认
|
||
try:
|
||
import vnpy.trader.optimize as opt
|
||
src = inspect.getsource(opt)
|
||
results["multiprocessing"] = "spawn (get_context('spawn') + ProcessPoolExecutor/Pool)"
|
||
except Exception as e:
|
||
results["multiprocessing"] = f"FAIL: {e}"
|
||
|
||
print("=== S2 Spike Result ===")
|
||
for k, v in results.items():
|
||
print(f" {k}: {v}")
|
||
ok = "OK" in results.get("import", "")
|
||
print(f"\nS2 VERDICT: {'PASS' if ok else 'FAIL'}")
|
||
print("max_workers 推荐: 2 (NAS braswell 2 核, spawn 开销大, S1 单因子 11s)")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|