Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
cd8b88f
Start introducing MockScheduler for better Scheduler testing
May 19, 2025
2c9c968
fixup scheduler schemas refactor
May 19, 2025
2f4a82e
reorg optimizer fixtures for reuse
May 19, 2025
24ccf5a
reorg files based storage fixture
May 19, 2025
bdfd9b0
adding basic scheduler config example loader test
May 19, 2025
b66e17a
Refactor Scheduler schema definitions to make it easier to add new ones.
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…
May 19, 2025
ea7b3ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 19, 2025
7563b8a
fixup
May 19, 2025
b03e31c
lint
May 19, 2025
8eb14c0
apply suggestions
May 19, 2025
8ad4c3d
revert
May 19, 2025
d4d5153
load test configs too
May 19, 2025
1eb1acb
format
May 19, 2025
947b759
Merge branch 'refactor/tests' into refactor/mock-scheduler-and-tests
May 19, 2025
0c3c805
Merge branch 'refactor/scheduler-schemas' into refactor/mock-schedule…
May 19, 2025
1112af4
list in __all__ so we load it as a part of tests schemas checking
May 19, 2025
973ad2b
Merge branch 'main' into refactor/mock-scheduler-and-tests
May 19, 2025
7a0d087
new mock scheduler schema and test configs
May 19, 2025
dded243
refactor to split steps for easier hooking
May 20, 2025
c305196
Merge remote-tracking branch 'upstream/main' into refactor/mock-sched…
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
71420e6
fixup
May 20, 2025
70130ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2025
0a440a1
ignore the build tree in vscode
May 20, 2025
efafc6f
adding more accessors
May 22, 2025
842d393
wip: enable mock env to report arbitrary data
May 22, 2025
19cec78
spelling
May 22, 2025
175f315
refactor status parsing a little bit again
May 22, 2025
7904716
extra test too
May 22, 2025
54a96e8
more links
May 22, 2025
2e1c4db
start adding a mock trial runner
May 22, 2025
626554d
Revert "start adding a mock trial runner"
May 22, 2025
b87c02a
schema work on mock trial data
May 22, 2025
b4e5640
remove mock scheduler
May 22, 2025
80cf2fa
allow mock trial data to be in the global config as well
May 22, 2025
8426621
comments as prompts in preparation to run a trial
May 22, 2025
cdc614f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
b3f49e9
fixups
May 22, 2025
a41e85f
revert
May 22, 2025
63e0f88
remove
May 22, 2025
44bdde2
refactor status parsing a little bit again
May 22, 2025
607fffd
extra test too
May 22, 2025
aaf0842
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
8f472bb
revert
May 22, 2025
8a4aac2
comments
May 22, 2025
50ffde4
add accessor for the mock_trial_data property
May 22, 2025
b1e2a52
make it a property
May 22, 2025
f0f7c4c
add some basic fixtures to get started with
May 22, 2025
c27b3c2
add a method for creating schedulers, intended to be used with pytest…
May 22, 2025
9813268
stubbing out a very basic test to get started
May 22, 2025
3b92017
wip: testing
May 22, 2025
341564e
wip
May 22, 2025
5c06814
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
836dcd9
comments
May 22, 2025
0072141
fixups
May 22, 2025
5400bd6
more checks
May 22, 2025
e62a378
Add more checks
May 22, 2025
206bb77
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
abe412b
linting
May 22, 2025
f5cb468
doc tweaks
May 22, 2025
c047bc2
Merge branch 'refactor/parse-status' into refactor/mock-scheduler-and…
May 22, 2025
dc7a7b2
fixup
May 22, 2025
76e94ed
fixup
May 22, 2025
7f8522a
fixups
May 22, 2025
9e03e63
remove old files
May 22, 2025
f9e3339
add some common globals
May 22, 2025
a05b5ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
94e31b5
simplify
May 27, 2025
21e49db
rename
May 27, 2025
46be004
fixup
May 27, 2025
01f7a02
always try and convert metrics back to numerics if possible
May 27, 2025
b035e57
wip: tell mysql to use a datetime that can store fractional seconds
May 27, 2025
ca101ef
add more trial data for testing
May 27, 2025
98ec1cc
:type fixups
May 27, 2025
82f602c
check the telemetry
May 27, 2025
176480f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 27, 2025
22f4e79
revert the bulk conversion one
May 27, 2025
aa9f728
debugging
May 27, 2025
6289216
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 27, 2025
5be025e
Merge branch 'main' into refactor/mock-scheduler-and-tests
bpkroth Jun 5, 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,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tell the editor to ignore scanning some python file copies

"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"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Allow specifying mock trial data in the globals too.

}
},
"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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add some basic accessor methods.

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