Skip to content

Commit 0cab884

Browse files
authored
Schema changes example for mlos_benchd service (#931)
# Pull Request ## Title Schema changes for mlos_benchd service. ______________________________________________________________________ ## Description Schema changes for mlos_benchd service. Storage APIs to adjust these to come in a future PR. - See #732 ______________________________________________________________________ ## Type of Change - ✨ New feature ______________________________________________________________________ ## Testing Local, CI ______________________________________________________________________ ## Additional Notes (optional) @eujing have a look at the [commit history in the PR](https://github.com/microsoft/MLOS/pull/931/commits) for a sense of what's going on. This can probably be merged as is. Happy to discuss further though. ______________________________________________________________________
1 parent 3c319cd commit 0cab884

5 files changed

Lines changed: 99 additions & 11 deletions

File tree

mlos_bench/mlos_bench/environments/status.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
#
5-
"""Enum for the status of the benchmark/environment."""
5+
"""Enum for the status of the benchmark/environment Trial or Experiment."""
66

77
import enum
88

99

1010
class Status(enum.Enum):
11-
"""Enum for the status of the benchmark/environment."""
11+
"""Enum for the status of the benchmark/environment Trial or Experiment."""
1212

1313
UNKNOWN = 0
1414
PENDING = 1
@@ -29,8 +29,8 @@ def is_good(self) -> bool:
2929
}
3030

3131
def is_completed(self) -> bool:
32-
"""Check if the status of the benchmark/environment is one of {SUCCEEDED,
33-
CANCELED, FAILED, TIMED_OUT}.
32+
"""Check if the status of the benchmark/environment Trial or Experiment is one
33+
of {SUCCEEDED, CANCELED, FAILED, TIMED_OUT}.
3434
"""
3535
return self in {
3636
Status.SUCCEEDED,
@@ -40,25 +40,37 @@ def is_completed(self) -> bool:
4040
}
4141

4242
def is_pending(self) -> bool:
43-
"""Check if the status of the benchmark/environment is PENDING."""
43+
"""Check if the status of the benchmark/environment Trial or Experiment is
44+
PENDING.
45+
"""
4446
return self == Status.PENDING
4547

4648
def is_ready(self) -> bool:
47-
"""Check if the status of the benchmark/environment is READY."""
49+
"""Check if the status of the benchmark/environment Trial or Experiment is
50+
READY.
51+
"""
4852
return self == Status.READY
4953

5054
def is_succeeded(self) -> bool:
51-
"""Check if the status of the benchmark/environment is SUCCEEDED."""
55+
"""Check if the status of the benchmark/environment Trial or Experiment is
56+
SUCCEEDED.
57+
"""
5258
return self == Status.SUCCEEDED
5359

5460
def is_failed(self) -> bool:
55-
"""Check if the status of the benchmark/environment is FAILED."""
61+
"""Check if the status of the benchmark/environment Trial or Experiment is
62+
FAILED.
63+
"""
5664
return self == Status.FAILED
5765

5866
def is_canceled(self) -> bool:
59-
"""Check if the status of the benchmark/environment is CANCELED."""
67+
"""Check if the status of the benchmark/environment Trial or Experiment is
68+
CANCELED.
69+
"""
6070
return self == Status.CANCELED
6171

6272
def is_timed_out(self) -> bool:
63-
"""Check if the status of the benchmark/environment is TIMED_OUT."""
73+
"""Check if the status of the benchmark/environment Trial or Experiment is
74+
TIMED_OUT.
75+
"""
6476
return self == Status.FAILED

mlos_bench/mlos_bench/storage/sql/alembic/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ This document contains some notes on how to use [`alembic`](https://alembic.sqla
3636

3737
> Normally this would be done with `alembic upgrade head`, but this command is convenient to ensure if will work with the `mlos_bench` command line interface as well.
3838
39+
Examine the results using something like:
40+
41+
```sh
42+
sqlite3 mlos_bench.sqlite .schema
43+
sqlite3 mlos_bench.sqlite "SELECT * FROM alembic_version;"
44+
```
45+
3946
1. If the migration script works, commit the changes to the [`mlos_bench/storage/sql/schema.py`](../schema.py) and [`mlos_bench/storage/sql/alembic/versions`](./versions/) files.
4047

4148
> Be sure to update the latest version in the [`test_storage_schemas.py`](../../../tests/storage/test_storage_schemas.py) file as well.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
#
5+
"""Adding Experiment table columns to support mlos_benchd service - See #732
6+
7+
Revision ID: 8928a401115b
8+
Revises: f83fb8ae7fc4
9+
Create Date: 2025-01-14 17:06:36.181503+00:00
10+
11+
"""
12+
# pylint: disable=no-member
13+
14+
from collections.abc import Sequence
15+
16+
import sqlalchemy as sa
17+
from alembic import op
18+
19+
# revision identifiers, used by Alembic.
20+
revision: str = "8928a401115b"
21+
down_revision: str | None = "f83fb8ae7fc4"
22+
branch_labels: str | Sequence[str] | None = None
23+
depends_on: str | Sequence[str] | None = None
24+
25+
26+
def upgrade() -> None:
27+
"""The schema upgrade script for this revision."""
28+
# ### commands auto generated by Alembic - please adjust! ###
29+
op.add_column("experiment", sa.Column("ts_start", sa.DateTime(), nullable=True))
30+
op.add_column("experiment", sa.Column("ts_end", sa.DateTime(), nullable=True))
31+
op.add_column("experiment", sa.Column("status", sa.String(length=16), nullable=True))
32+
op.add_column(
33+
"experiment",
34+
sa.Column(
35+
"driver_name",
36+
sa.String(length=40),
37+
nullable=True,
38+
comment="Driver Host/Container Name",
39+
),
40+
)
41+
op.add_column(
42+
"experiment",
43+
sa.Column("driver_pid", sa.Integer(), nullable=True, comment="Driver Process ID"),
44+
)
45+
# ### end Alembic commands ###
46+
47+
48+
def downgrade() -> None:
49+
"""The schema downgrade script for this revision."""
50+
# ### commands auto generated by Alembic - please adjust! ###
51+
op.drop_column("experiment", "driver_pid")
52+
op.drop_column("experiment", "driver_name")
53+
op.drop_column("experiment", "status")
54+
op.drop_column("experiment", "ts_end")
55+
op.drop_column("experiment", "ts_start")
56+
# ### end Alembic commands ###

mlos_bench/mlos_bench/storage/sql/schema.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ def __init__(self, engine: Engine | None):
103103
Column("root_env_config", String(1024), nullable=False),
104104
Column("git_repo", String(1024), nullable=False),
105105
Column("git_commit", String(40), nullable=False),
106+
# For backwards compatibility, we allow NULL for ts_start.
107+
Column("ts_start", DateTime),
108+
Column("ts_end", DateTime),
109+
# Should match the text IDs of `mlos_bench.environments.Status` enum:
110+
# For backwards compatibility, we allow NULL for status.
111+
Column("status", String(self._STATUS_LEN)),
112+
# There may be more than one mlos_benchd_service running on different hosts.
113+
# This column stores the host/container name of the driver that
114+
# picked up the experiment.
115+
# They should use a transaction to update it to their own hostname when
116+
# they start if and only if its NULL.
117+
Column("driver_name", String(40), comment="Driver Host/Container Name"),
118+
Column("driver_pid", Integer, comment="Driver Process ID"),
106119
PrimaryKeyConstraint("exp_id"),
107120
)
108121
"""The Table storing

mlos_bench/mlos_bench/tests/storage/test_storage_schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# NOTE: This value is hardcoded to the latest revision in the alembic versions directory.
1313
# It could also be obtained programmatically using the "alembic heads" command or heads() API.
1414
# See Also: schema.py for an example of programmatic alembic config access.
15-
CURRENT_ALEMBIC_HEAD = "f83fb8ae7fc4"
15+
CURRENT_ALEMBIC_HEAD = "8928a401115b"
1616

1717

1818
def test_storage_schemas(storage: SqlStorage) -> None:

0 commit comments

Comments
 (0)