-
Notifications
You must be signed in to change notification settings - Fork 74
Introduce mock_trial_data for MockEnv and add some basic Scheduler tests #980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bpkroth
wants to merge
84
commits into
microsoft:main
Choose a base branch
from
bpkroth:refactor/mock-scheduler-and-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
cd8b88f
Start introducing MockScheduler for better Scheduler testing
bpkroth 2c9c968
fixup scheduler schemas refactor
bpkroth 2f4a82e
reorg optimizer fixtures for reuse
bpkroth 24ccf5a
reorg files based storage fixture
bpkroth bdfd9b0
adding basic scheduler config example loader test
bpkroth b66e17a
Refactor Scheduler schema definitions to make it easier to add new ones.
bpkroth 30191c0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bc8dc8f
Refactor some test fixtures for better reuse so we can test loading S…
bpkroth ea7b3ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7563b8a
fixup
bpkroth b03e31c
lint
bpkroth 8eb14c0
apply suggestions
bpkroth 8ad4c3d
revert
bpkroth d4d5153
load test configs too
bpkroth 1eb1acb
format
bpkroth 947b759
Merge branch 'refactor/tests' into refactor/mock-scheduler-and-tests
bpkroth 0c3c805
Merge branch 'refactor/scheduler-schemas' into refactor/mock-schedule…
bpkroth 1112af4
list in __all__ so we load it as a part of tests schemas checking
bpkroth 973ad2b
Merge branch 'main' into refactor/mock-scheduler-and-tests
bpkroth 7a0d087
new mock scheduler schema and test configs
bpkroth dded243
refactor to split steps for easier hooking
bpkroth c305196
Merge remote-tracking branch 'upstream/main' into refactor/mock-sched…
bpkroth b16db23
Merge branch 'main' into refactor/mock-scheduler-and-tests
bpkroth f1fe022
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 83ff70f
Update mlos_bench/mlos_bench/tests/config/schedulers/test_load_schedu…
bpkroth 71420e6
fixup
bpkroth 70130ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0a440a1
ignore the build tree in vscode
bpkroth efafc6f
adding more accessors
bpkroth 842d393
wip: enable mock env to report arbitrary data
bpkroth 19cec78
spelling
bpkroth 175f315
refactor status parsing a little bit again
bpkroth 7904716
extra test too
bpkroth 54a96e8
more links
bpkroth 2e1c4db
start adding a mock trial runner
bpkroth 626554d
Revert "start adding a mock trial runner"
bpkroth b87c02a
schema work on mock trial data
bpkroth b4e5640
remove mock scheduler
bpkroth 80cf2fa
allow mock trial data to be in the global config as well
bpkroth 8426621
comments as prompts in preparation to run a trial
bpkroth cdc614f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b3f49e9
fixups
bpkroth a41e85f
revert
bpkroth 63e0f88
remove
bpkroth 44bdde2
refactor status parsing a little bit again
bpkroth 607fffd
extra test too
bpkroth aaf0842
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8f472bb
revert
bpkroth 8a4aac2
comments
bpkroth 50ffde4
add accessor for the mock_trial_data property
bpkroth b1e2a52
make it a property
bpkroth f0f7c4c
add some basic fixtures to get started with
bpkroth c27b3c2
add a method for creating schedulers, intended to be used with pytest…
bpkroth 9813268
stubbing out a very basic test to get started
bpkroth 3b92017
wip: testing
bpkroth 341564e
wip
bpkroth 5c06814
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 836dcd9
comments
bpkroth 0072141
fixups
bpkroth 5400bd6
more checks
bpkroth e62a378
Add more checks
bpkroth 206bb77
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] abe412b
linting
bpkroth f5cb468
doc tweaks
bpkroth c047bc2
Merge branch 'refactor/parse-status' into refactor/mock-scheduler-and…
bpkroth dc7a7b2
fixup
bpkroth 76e94ed
fixup
bpkroth 7f8522a
fixups
bpkroth 9e03e63
remove old files
bpkroth f9e3339
add some common globals
bpkroth a05b5ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 94e31b5
simplify
bpkroth 21e49db
rename
bpkroth 46be004
fixup
bpkroth 01f7a02
always try and convert metrics back to numerics if possible
bpkroth b035e57
wip: tell mysql to use a datetime that can store fractional seconds
bpkroth ca101ef
add more trial data for testing
bpkroth 98ec1cc
:type fixups
bpkroth 82f602c
check the telemetry
bpkroth 176480f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 22f4e79
revert the bulk conversion one
bpkroth aa9f728
debugging
bpkroth 6289216
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5be025e
Merge branch 'main' into refactor/mock-scheduler-and-tests
bpkroth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactor some test fixtures for better reuse so we can test loading S…
…cheduler config examples.
- Loading branch information
commit bc8dc8f3b4878f0aa52fbcdbd2d68430d56f4f0c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| Unit tests for the mlos_bench Scheduler configs. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # | ||
| """ | ||
| Pytest fixtures for Scheduler config tests. | ||
|
|
||
| Provides fixtures for creating multiple TrialRunner instances using the mock environment config. | ||
| """ | ||
|
|
||
| from importlib.resources import files | ||
|
|
||
| import pytest | ||
|
|
||
| from mlos_bench.services.config_persistence import ConfigPersistenceService | ||
| from mlos_bench.schedulers.trial_runner import TrialRunner | ||
| from mlos_bench.util import path_join | ||
|
|
||
| # pylint: disable=redefined-outer-name | ||
|
|
||
| TRIAL_RUNNERS_COUNT = 4 | ||
|
|
||
| @pytest.fixture | ||
| def mock_env_config_path() -> str: | ||
| """ | ||
| Returns the absolute path to the mock environment configuration file. | ||
| This file is used to create TrialRunner instances for testing. | ||
| """ | ||
|
|
||
| # Use the files() routine to locate the file relative to this directory | ||
| return path_join( | ||
| str(files("mlos_bench.config").joinpath("environments", "mock", "mock_env.jsonc")), | ||
| abs_path=True, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def trial_runners( | ||
| config_loader_service: ConfigPersistenceService, | ||
| mock_env_config_path: str, | ||
| ) -> list[TrialRunner]: | ||
| """ | ||
| Fixture that returns a list of TrialRunner instances using the mock environment config. | ||
|
|
||
| Returns | ||
| ------- | ||
| list[TrialRunner] | ||
| List of TrialRunner instances created from the mock environment config. | ||
| """ | ||
| return TrialRunner.create_from_json( | ||
| config_loader=config_loader_service, | ||
| env_json=mock_env_config_path, | ||
| num_trial_runners=TRIAL_RUNNERS_COUNT, | ||
| ) |
77 changes: 77 additions & 0 deletions
77
mlos_bench/mlos_bench/tests/config/schedulers/test_load_scheduler_config_examples.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # | ||
| """Tests for loading scheduler config examples.""" | ||
| import logging | ||
|
|
||
| import pytest | ||
|
|
||
| from mlos_bench.config.schemas.config_schemas import ConfigSchema | ||
| from mlos_bench.optimizers.mock_optimizer import MockOptimizer | ||
| from mlos_bench.schedulers.base_scheduler import Scheduler | ||
| from mlos_bench.schedulers.trial_runner import TrialRunner | ||
| from mlos_bench.services.config_persistence import ConfigPersistenceService | ||
| from mlos_bench.storage.sql.storage import SqlStorage | ||
| from mlos_bench.tests.config import locate_config_examples | ||
| from mlos_bench.util import get_class_from_name | ||
|
|
||
| import mlos_bench.tests.storage.sql.fixtures | ||
| import mlos_bench.tests.optimizers.fixtures | ||
|
|
||
| mock_opt = mlos_bench.tests.optimizers.fixtures.mock_opt | ||
| sqlite_storage = mlos_bench.tests.storage.sql.fixtures.sqlite_storage | ||
|
|
||
|
|
||
| _LOG = logging.getLogger(__name__) | ||
| _LOG.setLevel(logging.DEBUG) | ||
|
|
||
| # pylint: disable=redefined-outer-name | ||
|
|
||
| # Get the set of configs to test. | ||
| CONFIG_TYPE = "schedulers" | ||
|
|
||
|
|
||
| def filter_configs(configs_to_filter: list[str]) -> list[str]: | ||
| """If necessary, filter out json files that aren't for the module we're testing.""" | ||
| return configs_to_filter | ||
|
|
||
|
|
||
| configs = locate_config_examples( | ||
| ConfigPersistenceService.BUILTIN_CONFIG_PATH, | ||
| CONFIG_TYPE, | ||
| filter_configs, | ||
| ) | ||
| assert configs | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("config_path", configs) | ||
| def test_load_scheduler_config_examples( | ||
| config_loader_service: ConfigPersistenceService, | ||
| config_path: str, | ||
| mock_env_config_path: str, | ||
| trial_runners: list[TrialRunner], | ||
| sqlite_storage: SqlStorage, | ||
| mock_opt: MockOptimizer, | ||
| ) -> None: | ||
| """Tests loading a config example.""" | ||
| config = config_loader_service.load_config(config_path, ConfigSchema.SCHEDULER) | ||
| assert isinstance(config, dict) | ||
| cls = get_class_from_name(config["class"]) | ||
| assert issubclass(cls, Scheduler) | ||
| global_config = { | ||
| # Required configs generally provided by the Launcher. | ||
| "experiment_id": f"test_experiment_{__name__}", | ||
| "trial_id": 1, | ||
| } | ||
| # Make an instance of the class based on the config. | ||
| scheduler_inst = config_loader_service.build_scheduler( | ||
| config=config, | ||
| global_config=global_config, | ||
| trial_runners=trial_runners, | ||
| optimizer=mock_opt, | ||
| storage=sqlite_storage, | ||
| root_env_config=mock_env_config_path, | ||
| ) | ||
| assert scheduler_inst is not None | ||
| assert isinstance(scheduler_inst, cls) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.