Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-12 08:24:58

0001 """Smoke tests for canonical full configurations built in-memory."""
0002 
0003 from pathlib import Path
0004 import py_compile
0005 
0006 import yaml
0007 
0008 from aid2e.utilities.configurations import load_config
0009 
0010 
0011 def test_canonical_full_config_loads(tmp_path):
0012     """Canonical full configs should load and preserve objective directions."""
0013     output_dir = tmp_path / "output"
0014     work_dir = tmp_path / "work"
0015     output_dir.mkdir()
0016     work_dir.mkdir()
0017 
0018     cfg_path = tmp_path / "full.yml"
0019     cfg_path.write_text(
0020         yaml.safe_dump(
0021             {
0022                 "problem": {
0023                     "name": "Smoke Problem",
0024                     "problem_type": "toy",
0025                     "output_location": str(output_dir),
0026                     "work_location": str(work_dir),
0027                     "inline_design": {
0028                         "design_space" : {
0029                             "design_parameters": {
0030                                 "group": {
0031                                     "parameters": {
0032                                         "x": {"value": 0.5, "bounds": [0.0, 1.0]},
0033                                         "label": {
0034                                             "value": "a",
0035                                             "choices": ["a", "b"],
0036                                         }
0037                                     }
0038                                 }
0039                             },
0040                             "parameter_constraints": [
0041                                 {"name": "bound", "rule": "group.x <= 1.0"}
0042                             ]
0043                         }
0044                     },
0045                     "objectives": [
0046                         {"name": "f1", "direction": "minimize"},
0047                         {"name": "f2", "direction": "maximize"},
0048                     ]
0049                 },
0050                 "optimizer": {
0051                     "name": "MOBO",
0052                     "type": "Bayesian",
0053                     "parameters": {"n_iterations": 3},
0054                 }
0055             }
0056         )
0057     )
0058 
0059     config = load_config(str(cfg_path))
0060     assert config.problem.objectives
0061     assert [obj.to_directive() for obj in config.problem.objectives] == [
0062         "minimize:f1",
0063         "maximize:f2",
0064     ]
0065 
0066 
0067 def test_optimizer_only_example_configs_load() -> None:
0068     """New optimizer-only example YAMLs should load as canonical full configs."""
0069     example_paths = [
0070         Path("examples/optimizers/dtlz2_ax_optimizer_only.yml"),
0071         Path("examples/optimizers/dtlz2_pymoo_optimizer_only.yml"),
0072     ]
0073 
0074     for cfg_path in example_paths:
0075         config = load_config(str(cfg_path))
0076         assert config.problem.problem_type == "toy"
0077         assert config.problem.design_config.get_parameter_names()
0078         assert config.optimizer.parameters
0079 
0080 
0081 def test_optimizer_only_example_scripts_compile() -> None:
0082     """New optimizer-only example scripts should compile cleanly."""
0083     script_paths = [
0084         Path("examples/optimizers/run_ax_optimizer_only_example.py"),
0085         Path("examples/optimizers/run_pymoo_optimizer_only_example.py"),
0086     ]
0087 
0088     for script_path in script_paths:
0089         py_compile.compile(str(script_path), doraise=True)