Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
c240f6a
Prepare experiment load to handle async out of order trial completion
bpkroth May 9, 2025
4c767f0
Rename some methods and move some to the base class in preparation fo…
bpkroth May 9, 2025
0261125
remove wait_for_trial_runners for now
bpkroth May 9, 2025
5db8fb2
remove vscode setting
bpkroth May 9, 2025
540cbce
comments
bpkroth May 9, 2025
a10529a
doc improvements
bpkroth May 9, 2025
b435223
tweaks
bpkroth May 9, 2025
71d3f24
fixups
bpkroth May 9, 2025
263452a
doc fixups
bpkroth May 9, 2025
9398b18
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 9, 2025
281dbf4
add tests and fixes
bpkroth May 9, 2025
defeb28
fixup suggested
bpkroth May 10, 2025
eaec8aa
Merge branch 'main' into refactor/prepare-exp-load-to-handle-async-tr…
bpkroth May 12, 2025
6e8c4da
Merge branch 'main' into refactor/rename-reorg-scheduler-methods
bpkroth May 12, 2025
6ac5b42
Merge branch 'refactor/rename-reorg-scheduler-methods' into refactor/…
bpkroth May 12, 2025
fc1eaba
Merge branch 'refactor/rename-reorg-scheduler-methods' into refactor/…
bpkroth May 12, 2025
c7886db
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 12, 2025
287f815
slight reorg
bpkroth May 12, 2025
0811b7a
fix bad merge
bpkroth May 12, 2025
c26aaf1
fix doc syntax
bpkroth May 12, 2025
69e11a4
Merge branch 'main' into refactor/prepare-exp-load-to-handle-async-tr…
bpkroth May 12, 2025
33ca8d1
Merge branch 'main' into refactor/prepare-exp-load-to-handle-async-tr…
bpkroth May 13, 2025
74bfb04
Add tests for Status type conversion
bpkroth May 13, 2025
c77f31b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2025
4225862
improvements on docstring instructions
bpkroth May 13, 2025
3d8a783
type tweaks
bpkroth May 13, 2025
446502f
improvements on docstring instructions
bpkroth May 13, 2025
34137a4
Revert "improvements on docstring instructions"
bpkroth May 13, 2025
631f29d
Merge branch 'copilot-doc-instructions-tweaks' into refactor/prepare-…
bpkroth May 13, 2025
8098ed6
new test for get longest idle prefix
bpkroth May 13, 2025
4757ac4
pylint
bpkroth May 13, 2025
ca5c9b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2025
6f78eea
fixups
bpkroth May 13, 2025
6b90301
stash completed statuses in a more reusable way
bpkroth May 13, 2025
1cd52ba
Merge branch 'additional-tests-for-type-conversions' into refactor/pr…
bpkroth May 13, 2025
b80e5e1
more tests and status tweaks
bpkroth May 13, 2025
fbf7548
wip tests and other fixups
bpkroth May 13, 2025
eebb214
stash completed statuses in a more reusable way
bpkroth May 13, 2025
15abbb5
more tests and status tweaks
bpkroth May 13, 2025
6fd08d8
reorg more functions in scheduler for easier overloading
bpkroth May 13, 2025
de92c39
comments
bpkroth May 13, 2025
9cc55af
test fixups
bpkroth May 13, 2025
65d7cbc
new config schemas for schedulers
bpkroth May 13, 2025
25321da
starting to introduce a mock scheduler
bpkroth May 13, 2025
0f36a40
comment
bpkroth May 13, 2025
cbdfbf1
fixups
bpkroth May 13, 2025
865d853
rename a test for clarity
bpkroth May 13, 2025
234d291
linting
bpkroth May 13, 2025
2010ec8
comments
bpkroth May 13, 2025
dd5643f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2025
12ac360
stub out a test for loading example configs
bpkroth May 13, 2025
d4f5058
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2025
d472f6e
Merge branch 'main' into additional-tests-for-type-conversions
motus May 14, 2025
535ead0
switch to frozenset
bpkroth May 19, 2025
b370787
tweak
bpkroth May 19, 2025
18d41e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 19, 2025
a9f3b08
type fixups
bpkroth May 19, 2025
c704a6a
Merge branch 'additional-tests-for-type-conversions' into refactor/pr…
bpkroth May 19, 2025
a43835f
Merge branch 'main' into refactor/prepare-exp-load-to-handle-async-tr…
bpkroth May 19, 2025
e56f7c7
doc string tweaks
bpkroth May 19, 2025
cd8b88f
Start introducing MockScheduler for better Scheduler testing
bpkroth May 19, 2025
2c9c968
fixup scheduler schemas refactor
bpkroth May 19, 2025
2f4a82e
reorg optimizer fixtures for reuse
bpkroth May 19, 2025
24ccf5a
reorg files based storage fixture
bpkroth May 19, 2025
bdfd9b0
adding basic scheduler config example loader test
bpkroth May 19, 2025
b66e17a
Refactor Scheduler schema definitions to make it easier to add new ones.
bpkroth May 19, 2025
30191c0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 19, 2025
bc8dc8f
Refactor some test fixtures for better reuse so we can test loading S…
bpkroth May 19, 2025
ea7b3ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 19, 2025
7563b8a
fixup
bpkroth May 19, 2025
b03e31c
lint
bpkroth May 19, 2025
8eb14c0
apply suggestions
bpkroth May 19, 2025
8ad4c3d
revert
bpkroth May 19, 2025
d4d5153
load test configs too
bpkroth May 19, 2025
1eb1acb
format
bpkroth May 19, 2025
947b759
Merge branch 'refactor/tests' into refactor/mock-scheduler-and-tests
bpkroth May 19, 2025
0c3c805
Merge branch 'refactor/scheduler-schemas' into refactor/mock-schedule…
bpkroth May 19, 2025
1112af4
list in __all__ so we load it as a part of tests schemas checking
bpkroth May 19, 2025
973ad2b
Merge branch 'main' into refactor/mock-scheduler-and-tests
bpkroth May 19, 2025
7a0d087
new mock scheduler schema and test configs
bpkroth May 19, 2025
dded243
refactor to split steps for easier hooking
bpkroth May 20, 2025
c305196
Merge remote-tracking branch 'upstream/main' into refactor/mock-sched…
bpkroth May 20, 2025
b16db23
Merge branch 'main' into refactor/mock-scheduler-and-tests
bpkroth May 20, 2025
f1fe022
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2025
83ff70f
Update mlos_bench/mlos_bench/tests/config/schedulers/test_load_schedu…
bpkroth May 20, 2025
d3a00a4
Merge remote-tracking branch 'upstream/main' into refactor/prepare-ex…
bpkroth May 20, 2025
e5dcb56
Merge branch 'refactor/mock-scheduler-and-tests' into refactor/prepar…
bpkroth May 20, 2025
71420e6
fixup
bpkroth May 20, 2025
70130ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2025
039a853
Merge branch 'refactor/mock-scheduler-and-tests' into refactor/prepar…
bpkroth May 20, 2025
0a440a1
ignore the build tree in vscode
bpkroth May 20, 2025
efafc6f
adding more accessors
bpkroth May 22, 2025
842d393
wip: enable mock env to report arbitrary data
bpkroth May 22, 2025
19cec78
spelling
bpkroth May 22, 2025
175f315
refactor status parsing a little bit again
bpkroth May 22, 2025
7904716
extra test too
bpkroth May 22, 2025
54a96e8
more links
bpkroth May 22, 2025
2e1c4db
start adding a mock trial runner
bpkroth May 22, 2025
626554d
Revert "start adding a mock trial runner"
bpkroth May 22, 2025
b87c02a
schema work on mock trial data
bpkroth May 22, 2025
b4e5640
remove mock scheduler
bpkroth May 22, 2025
80cf2fa
allow mock trial data to be in the global config as well
bpkroth May 22, 2025
8426621
comments as prompts in preparation to run a trial
bpkroth May 22, 2025
cdc614f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
b3f49e9
fixups
bpkroth May 22, 2025
a41e85f
revert
bpkroth May 22, 2025
63e0f88
remove
bpkroth May 22, 2025
44bdde2
refactor status parsing a little bit again
bpkroth May 22, 2025
607fffd
extra test too
bpkroth May 22, 2025
aaf0842
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
8f472bb
revert
bpkroth May 22, 2025
5185eb7
Merge branch 'refactor/mock-scheduler-and-tests' into refactor/prepar…
bpkroth May 22, 2025
8b3d839
remove mock scheduler configs
bpkroth May 22, 2025
8a4aac2
comments
bpkroth May 22, 2025
50ffde4
add accessor for the mock_trial_data property
bpkroth May 22, 2025
b1e2a52
make it a property
bpkroth May 22, 2025
f0f7c4c
add some basic fixtures to get started with
bpkroth May 22, 2025
c27b3c2
add a method for creating schedulers, intended to be used with pytest…
bpkroth May 22, 2025
9813268
stubbing out a very basic test to get started
bpkroth May 22, 2025
3b92017
wip: testing
bpkroth May 22, 2025
341564e
wip
bpkroth May 22, 2025
5c06814
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
836dcd9
comments
bpkroth May 22, 2025
0072141
fixups
bpkroth May 22, 2025
5400bd6
more checks
bpkroth May 22, 2025
e62a378
Add more checks
bpkroth May 22, 2025
206bb77
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
abe412b
linting
bpkroth May 22, 2025
f5cb468
doc tweaks
bpkroth May 22, 2025
c047bc2
Merge branch 'refactor/parse-status' into refactor/mock-scheduler-and…
bpkroth May 22, 2025
f8f472c
Merge branch 'refactor/mock-scheduler-and-tests' into refactor/prepar…
bpkroth May 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"**/__pycache__/": true,
"**/node_modules/": true,
"**/*.egg-info": true,
"mlos_*/build/": true,
"doc/source/autoapi/": true,
"doc/build/doctrees/": true,
"doc/build/html/": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
},
"optimization_targets": {
"$ref": "./common-defs-subschemas.json#/$defs/optimization_targets"
},
"mock_trial_data": {
"$ref": "../environments/mock-env-subschema.json#/$defs/mock_trial_data"
}
},
"additionalProperties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,136 @@
"$id": "https://raw.githubusercontent.com/microsoft/MLOS/main/mlos_bench/mlos_bench/config/schemas/environments/mock-env-subschema.json",
"title": "mlos_bench MockEnv config",
"description": "Config instance for a mlos_bench MockEnv",

"$defs": {
"mock_trial_common_phase_data": {
"type": "object",
"properties": {
"sleep": {
"type": "number",
"description": "Optional time to sleep (in seconds) before returning from this phase of the trial.",
"examples": [0, 0.1, 0.5, 1, 2],
"minimum": 0,
"maximum": 60
},
"exception": {
"type": "string",
"description": "Optional exception message to raise during phase."
}
}
},
"mock_trial_status_run_phase_data": {
"type": "object",
"properties": {
"status": {
"description": "The status to report for this phase of the trial. Default is phase dependent.",
"enum": [
"UNKNOWN",
"PENDING",
"READY",
"RUNNING",
"SUCCEEDED",
"CANCELED",
"FAILED",
"TIMED_OUT"
]
},
"metrics": {
"type": "object",
"description": "A dictionary of metrics for this phase of the trial.",
"additionalProperties": {
"type": [
"number",
"string",
"boolean"
],
"description": "The value of the metric."
},
"examples": [
{
"score": 0.95,
"color": "green"
},
{
"accuracy": 0.85,
"loss": 0.15
}
],
"minProperties": 0
}
}
},
"mock_trial_data_item": {
"description": "Mock data for a single trial, split by phase",
"type": "object",
"properties": {
"run": {
"description": "A dictionary of trial data for the run phase.",
"type": "object",
"allOf": [
{
"$ref": "#/$defs/mock_trial_common_phase_data"
},
{
"$ref": "#/$defs/mock_trial_status_run_phase_data"
}
],
"minProperties": 1,
"unevaluatedProperties": false
},
"status": {
"description": "A dictionary of trial data for the status phase.",
"type": "object",
"allOf": [
{
"$ref": "#/$defs/mock_trial_common_phase_data"
},
{
"$ref": "#/$defs/mock_trial_status_run_phase_data"
}
],
"minProperties": 1,
"unevaluatedProperties": false
},
"setup": {
"description": "A dictionary of trial data for the setup phase.",
"type": "object",
"allOf": [
{
"$ref": "#/$defs/mock_trial_common_phase_data"
}
],
"minProperties": 1,
"unevaluatedProperties": false
},
"teardown": {
"description": "A dictionary of trial data for the teardown phase.",
"type": "object",
"allOf": [
{
"$ref": "#/$defs/mock_trial_common_phase_data"
}
],
"minProperties": 1,
"unevaluatedProperties": false
}
},
"unevaluatedProperties": false,
"minProperties": 1
},
"mock_trial_data": {
"description": "A set of mock trial data to use for testing, keyed by trial id. Used by MockEnv.",
"type": "object",
"patternProperties": {
"^[1-9][0-9]*$": {
"$ref": "#/$defs/mock_trial_data_item"
}
},
"unevaluatedProperties": false,
"minProperties": 1
}
},

"type": "object",
"properties": {
"class": {
Expand Down Expand Up @@ -42,6 +172,9 @@
},
"minItems": 1,
"uniqueItems": true
},
"mock_trial_data": {
"$ref": "#/$defs/mock_trial_data"
}
}
}
Expand Down
86 changes: 86 additions & 0 deletions mlos_bench/mlos_bench/environments/base_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,92 @@ def parameters(self) -> dict[str, TunableValue]:
"""
return self._params.copy()

@property
def current_trial_id(self) -> int:
"""
Get the current trial ID.

This value can be used in scripts or environment variables to help
identify the Trial this Environment is currently running.

Returns
-------
trial_id : int
The current trial ID.

Notes
-----
This method is used to identify the current trial ID for the environment.
It is expected to be called *after* the base
:py:meth:`Environment.setup` method has been called and parameters have
been assigned.
"""
val = self._params["trial_id"]
assert isinstance(val, int), (
"Expected trial_id to be an int, but got %s (type %s): %s",
val,
type(val),
self._params,
)
return val

@property
def trial_runner_id(self) -> int:
"""
Get the ID of the :py:class:`~.mlos_bench.schedulers.trial_runner.TrialRunner`
for this Environment.

This value can be used in scripts or environment variables to help
identify the TrialRunner for this Environment.

Returns
-------
trial_runner_id : int
The trial runner ID.

Notes
-----
This shouldn't change during the lifetime of the Environment since each
Environment is assigned to a single TrialRunner.
"""
val = self._params["trial_runner_id"]
assert isinstance(val, int), (
"Expected trial_runner_id to be an int, but got %s (type %s)",
val,
type(val),
)
return val

@property
def experiment_id(self) -> str:
"""
Get the ID of the experiment.

This value can be used in scripts or environment variables to help
identify the TrialRunner for this Environment.

Returns
-------
experiment_id : str
The ID of the experiment.

Notes
-----
This value comes from the globals config or ``mlos_bench`` CLI arguments
in the experiment setup.

See Also
--------
mlos_bench.config : documentation on the configuration system
"""
val = self._params["experiment_id"]
assert isinstance(val, str), (
"Expected experiment_id to be an int, but got %s (type %s)",
val,
type(val),
)
return val

def setup(self, tunables: TunableGroups, global_config: dict | None = None) -> bool:
"""
Set up a new benchmark environment, if necessary. This method must be
Expand Down
Loading
Loading