Skip to content

Commit

Permalink
Move r test runs to own fixtures instead of dynamic fixture for caching
Browse files Browse the repository at this point in the history
If each fixture runs one script we can say it only runs once per test suite,
saving time.
  • Loading branch information
madeline-scyphers committed Oct 11, 2023
1 parent 62cdd4d commit 5244f55
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
52 changes: 19 additions & 33 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,42 +208,28 @@ def moo_main_run(tmp_path_factory, cd_to_root_and_back_session):


@pytest.fixture(scope="session")
def stand_alone_opt_package_run(request, tmp_path_factory, cd_to_root_and_back_session):
# parametrize the test to pass in script options in config as relative and absolute paths
if getattr(request, "param", None) == "absolute":
temp_dir = tmp_path_factory.mktemp("temp_dir")
wrapper_path = (TEST_DIR / "scripts/stand_alone_opt_package/wrapper.py").resolve()
config = {
"objective": {"metrics": [{"metric": "mean", "name": "Mean"}, {"metric": "RMSE", "info_only": True}]},
"generation_strategy": {
"steps": [{"model": "SOBOL", "num_trials": 2}, {"model": "GPEI", "num_trials": -1}]
},
"scheduler": {"total_trials": 5},
"parameters": [
{"bounds": [-5.0, 10.0], "name": "x0", "type": "range"},
{"bounds": [0.0, 15.0], "name": "x1", "type": "range"},
],
"script_options": {
"wrapper_path": str(wrapper_path),
"wrapper_name": "WrapperStandAlone",
"output_dir": str(temp_dir),
"exp_name": "test_experiment",
},
}
config_path = temp_dir / "config.yaml"
with open(Path(config_path), "w") as file:
json.dump(config, file)
args = f"--config-path {config_path}"
else:
config_path = TEST_DIR / "scripts/stand_alone_opt_package/stand_alone_pkg_config.yaml"
args = f"--config-path {config_path} -td"

def stand_alone_opt_package_run(tmp_path_factory, cd_to_root_and_back_session):
config_path = TEST_DIR / "scripts/stand_alone_opt_package/stand_alone_pkg_config.yaml"
args = f"--config-path {config_path} -td"
yield dunder_main.main(split_shell_command(args), standalone_mode=False)


@pytest.fixture(scope="session")
def r_scripts_run(request, tmp_path_factory, cd_to_root_and_back_session):
sub_dir = request.param
config_path = TEST_DIR / f"scripts/other_langs/r_package_{sub_dir}/config.yaml"
def r_full(tmp_path_factory, cd_to_root_and_back_session):
config_path = TEST_DIR / f"scripts/other_langs/r_package_full/config.yaml"

yield dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False)


@pytest.fixture(scope="session")
def r_light(tmp_path_factory, cd_to_root_and_back_session):
config_path = TEST_DIR / f"scripts/other_langs/r_package_light/config.yaml"

yield dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False)


@pytest.fixture(scope="session")
def r_streamlined(tmp_path_factory, cd_to_root_and_back_session):
config_path = TEST_DIR / f"scripts/other_langs/r_package_streamlined/config.yaml"

yield dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False)
7 changes: 3 additions & 4 deletions tests/integration_tests/test_dunder_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,17 @@ def test_calling_command_line_test_script_doesnt_error_out_and_produces_correct_
# or parametrize the test to use the streamlined version (doesn't use trial_status.json, only use output.json)
@pytest.mark.parametrize(
"r_scripts_run",
["full", "light", "streamlined"],
indirect=True,
["r_full", "r_light", "r_streamlined"],
)
@pytest.mark.skipif(not R_INSTALLED, reason="requires R to be installed")
def test_calling_command_line_r_test_scripts(r_scripts_run, request):
scheduler = r_scripts_run
scheduler = request.getfixturevalue(r_scripts_run)
wrapper = scheduler.experiment.runner.wrapper
config = wrapper.config
assert len(scheduler.experiment.trials) == config.trials

assert scheduler
if "r_package_full" in str(wrapper.config_path):
if "r_full" == r_scripts_run:
data = load_jsonlike(get_trial_dir(wrapper.experiment_dir, 0) / "data.json")
assert "param_names" in data
assert "metric_properties" in data
Expand Down

4 comments on commit 5244f55

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__main__.py90594%83, 135, 166, 211, 219
async_opt.py1061883%137, 182, 189, 192, 212–213, 219–220, 222–223, 225, 232–237, 241
ax_instantiation_utils.py47197%123
controller.py71297%73, 166
definitions.py80100% 
instantiation_base.py40197%39
metaclasses.py72395%50–51, 57
plot.py12120%15, 17–18, 20–21, 24, 27, 34, 40–41, 44–45
plotting.py1412880%51–52, 59, 94–95, 251–253, 301–305, 345, 429–432, 434–441, 443, 448
registry.py80100% 
runner.py50492%48, 82–84
scheduler.py811482%38, 128–131, 138–139, 153, 160–161, 168–169, 264–265
storage.py1241587%83, 115–117, 177, 195, 273–281
template.py200100% 
utils.py992079%179, 193–194, 219, 229–233, 235–237, 239, 241, 245–250
config
   __main__.py00100% 
   config.py3073488%33, 211, 217, 221, 223–224, 226, 282, 409, 412, 420–421, 429, 603, 605, 607, 613–617, 619, 690, 723, 744, 751–752, 760, 773, 783–784, 796, 821, 824
   converters.py751382%14, 22, 41, 46–48, 51–52, 65, 67, 71, 79, 95
metrics
   metric_funcs.py34488%58, 80–81, 83
   metrics.py1011585%127, 304–305, 310–311, 314, 320, 331–333, 337–341
   modular_metric.py1202083%38–41, 43–50, 64, 131, 142, 184, 235–236, 255–256
   synthetic_funcs.py39489%31, 35, 58, 65
scripts
   moo.py30196%44
   run_branin.py34197%56
   script_wrappers.py31293%57–58
   synth_func_cli.py210100% 
wrappers
   base_wrapper.py1953084%63–64, 89–92, 94, 102, 110, 115, 147, 156, 167, 215–216, 218, 267, 269, 271, 275, 330, 402, 416, 589, 591–594, 602, 612
   script_wrapper.py103991%193, 204–205, 273, 279, 327, 332, 346, 351
   synthetic_wrapper.py16287%16, 28
   wrapper_utils.py1321092%147–148, 228, 277, 283, 385–387, 395–396
TOTAL220726887% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__main__.py90594%83, 135, 166, 211, 219
async_opt.py1061883%137, 182, 189, 192, 212–213, 219–220, 222–223, 225, 232–237, 241
ax_instantiation_utils.py47197%123
controller.py71297%73, 166
definitions.py80100% 
instantiation_base.py40197%39
metaclasses.py72395%50–51, 57
plot.py12120%15, 17–18, 20–21, 24, 27, 34, 40–41, 44–45
plotting.py1412880%51–52, 59, 94–95, 251–253, 301–305, 345, 429–432, 434–441, 443, 448
registry.py80100% 
runner.py50492%48, 82–84
scheduler.py811482%38, 128–131, 138–139, 153, 160–161, 168–169, 264–265
storage.py1241587%83, 115–117, 177, 195, 273–281
template.py200100% 
utils.py992079%179, 193–194, 219, 229–233, 235–237, 239, 241, 245–250
config
   __main__.py00100% 
   config.py3073488%33, 211, 217, 221, 223–224, 226, 282, 409, 412, 420–421, 429, 603, 605, 607, 613–617, 619, 690, 723, 744, 751–752, 760, 773, 783–784, 796, 821, 824
   converters.py751382%14, 22, 41, 46–48, 51–52, 65, 67, 71, 79, 95
metrics
   metric_funcs.py34488%58, 80–81, 83
   metrics.py1011585%127, 304–305, 310–311, 314, 320, 331–333, 337–341
   modular_metric.py1202083%38–41, 43–50, 64, 131, 142, 184, 235–236, 255–256
   synthetic_funcs.py39489%31, 35, 58, 65
scripts
   moo.py30196%44
   run_branin.py34197%56
   script_wrappers.py31293%57–58
   synth_func_cli.py210100% 
wrappers
   base_wrapper.py1953084%63–64, 89–92, 94, 102, 110, 115, 147, 156, 167, 215–216, 218, 267, 269, 271, 275, 330, 402, 416, 589, 591–594, 602, 612
   script_wrapper.py103991%193, 204–205, 273, 279, 327, 332, 346, 351
   synthetic_wrapper.py16287%16, 28
   wrapper_utils.py1321092%147–148, 228, 277, 283, 385–387, 395–396
TOTAL220726887% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__main__.py90594%83, 135, 166, 211, 219
async_opt.py1061883%137, 182, 189, 194, 212–213, 219–220, 222–223, 225, 232–237, 241
ax_instantiation_utils.py47197%123
controller.py71297%73, 166
definitions.py80100% 
instantiation_base.py40197%39
metaclasses.py72395%50–51, 57
plot.py12120%15, 17–18, 20–21, 24, 27, 34, 40–41, 44–45
plotting.py1412880%51–52, 59, 94–95, 251–253, 301–305, 345, 429–432, 434–441, 443, 448
registry.py80100% 
runner.py50492%48, 82–84
scheduler.py811482%38, 128–131, 138–139, 153, 160–161, 168–169, 264–265
storage.py1241587%83, 115–117, 177, 195, 273–281
template.py200100% 
utils.py992079%179, 193–194, 219, 229–233, 235–237, 239, 241, 245–250
config
   __main__.py00100% 
   config.py3073488%33, 211, 217, 221, 223–224, 226, 282, 409, 412, 420–421, 429, 603, 605, 607, 613–617, 619, 690, 723, 744, 751–752, 760, 773, 783–784, 796, 821, 824
   converters.py751382%14, 22, 41, 46–48, 51–52, 65, 67, 71, 79, 95
metrics
   metric_funcs.py34488%58, 80–81, 83
   metrics.py1011585%127, 304–305, 310–311, 314, 320, 331–333, 337–341
   modular_metric.py1202083%38–41, 43–50, 64, 131, 142, 184, 235–236, 255–256
   synthetic_funcs.py39489%31, 35, 58, 65
scripts
   moo.py30196%44
   run_branin.py34197%56
   script_wrappers.py31293%57–58
   synth_func_cli.py210100% 
wrappers
   base_wrapper.py1953084%63–64, 89–92, 94, 102, 110, 115, 147, 156, 167, 215–216, 218, 267, 269, 271, 275, 330, 402, 416, 589, 591–594, 602, 612
   script_wrapper.py103991%193, 204–205, 273, 279, 327, 332, 346, 351
   synthetic_wrapper.py16287%16, 28
   wrapper_utils.py1321092%147–148, 228, 277, 283, 385–387, 395–396
TOTAL220726887% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__main__.py90594%83, 135, 166, 211, 219
async_opt.py1061883%137, 182, 189, 194, 212–213, 219–220, 222–223, 225, 232–237, 241
ax_instantiation_utils.py47197%123
controller.py71297%73, 166
definitions.py80100% 
instantiation_base.py40197%39
metaclasses.py72395%50–51, 57
plot.py12120%15, 17–18, 20–21, 24, 27, 34, 40–41, 44–45
plotting.py1412880%51–52, 59, 94–95, 251–253, 301–305, 345, 429–432, 434–441, 443, 448
registry.py80100% 
runner.py50492%48, 82–84
scheduler.py811482%38, 128–131, 138–139, 153, 160–161, 168–169, 264–265
storage.py1241587%83, 115–117, 177, 195, 273–281
template.py200100% 
utils.py992079%179, 193–194, 219, 229–233, 235–237, 239, 241, 245–250
config
   __main__.py00100% 
   config.py3073488%33, 211, 217, 221, 223–224, 226, 282, 409, 412, 420–421, 429, 603, 605, 607, 613–617, 619, 690, 723, 744, 751–752, 760, 773, 783–784, 796, 821, 824
   converters.py751382%14, 22, 41, 46–48, 51–52, 65, 67, 71, 79, 95
metrics
   metric_funcs.py34488%58, 80–81, 83
   metrics.py1011585%127, 304–305, 310–311, 314, 320, 331–333, 337–341
   modular_metric.py1202083%38–41, 43–50, 64, 131, 142, 184, 235–236, 255–256
   synthetic_funcs.py39489%31, 35, 58, 65
scripts
   moo.py30196%44
   run_branin.py34197%56
   script_wrappers.py31293%57–58
   synth_func_cli.py210100% 
wrappers
   base_wrapper.py1953084%63–64, 89–92, 94, 102, 110, 115, 147, 156, 167, 215–216, 218, 267, 269, 271, 275, 330, 402, 416, 589, 591–594, 602, 612
   script_wrapper.py103991%193, 204–205, 273, 279, 327, 332, 346, 351
   synthetic_wrapper.py16287%16, 28
   wrapper_utils.py1321092%147–148, 228, 277, 283, 385–387, 395–396
TOTAL220726887% 

Please sign in to comment.