File indexing completed on 2026-11-09 09:29:52
0001
0002 """Run DTLZ2 evaluations directly through the JobLib scheduler registry.
0003
0004 Run: python examples/dtlz2/python_api/dtlz2_scheduler.py
0005 """
0006
0007 import sys
0008 from pathlib import Path
0009
0010 REPO_ROOT = Path(__file__).resolve().parents[3]
0011 if str(REPO_ROOT) not in sys.path:
0012 sys.path.insert(0, str(REPO_ROOT))
0013
0014 from aid2e.schedulers import get_scheduler
0015 from aid2e.utilities.configurations.scheduler_config import SchedulerConfiguration
0016 from examples.dtlz2.dtlz2_evaluator import dtlz2_both_objectives
0017
0018
0019 def example_stage_execution():
0020 """Configure JobLib, retrieve it from the registry, and run three designs."""
0021 scheduler_config = SchedulerConfiguration(
0022 runner_type="JobLibRunner",
0023 parameters={"n_jobs": 3, "backend": "threading"},
0024 )
0025 scheduler_class = get_scheduler("joblib")
0026 scheduler = scheduler_class(config=scheduler_config.parse_runner_params())
0027
0028 jobs = [
0029 {
0030 "name": f"design_{index}",
0031 "function": dtlz2_both_objectives,
0032 "params": {"x": [x1] + [0.5] * 9},
0033 }
0034 for index, x1 in enumerate((0.2, 0.5, 0.8))
0035 ]
0036 result = scheduler.run_stage(
0037 stage_name="evaluate_designs",
0038 job_definitions=jobs,
0039 parallelism_policy={"max_concurrent": 3},
0040 )
0041
0042 print(f"Scheduler: {scheduler_class.__name__}")
0043 print(f"Stage: {result.stage_name}")
0044 print(f"Success: {result.success}")
0045 print(f"Jobs completed: {sum(status.status == 'completed' for status in result.job_statuses)}")
0046 for status in result.job_statuses:
0047 print(f" {status.job_id}: {status.status} (exit code: {status.return_code})")
0048 print(f" Objectives: {status.outputs}")
0049 return result
0050
0051
0052 if __name__ == "__main__":
0053 raise SystemExit(0 if example_stage_execution().success else 1)