-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from ORNL/dev
Main < Dev
- Loading branch information
Showing
23 changed files
with
361 additions
and
87 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,12 @@ | ||
# Make sure you run this from the directory root | ||
rm -rf .pytest_cache \ | ||
.build \ | ||
.dist \ | ||
build \ | ||
dist \ | ||
*egg* \ | ||
mlruns \ | ||
mlflow.db | ||
|
||
rm -rf **/*mlruns* | ||
rm -rf */*/*mlruns* |
This file contains 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,20 @@ | ||
version: '3.8' | ||
services: | ||
flowcept_redis: | ||
container_name: flowcept_redis | ||
image: redis | ||
ports: | ||
- 6379:6379 | ||
|
||
mlflow_interceptor_redis: | ||
container_name: mlflow_interceptor_redis | ||
image: redis | ||
ports: | ||
- 60379:6379 | ||
|
||
zambeze_rabbitmq: | ||
container_name: zambeze_rabbitmq | ||
image: rabbitmq:3.11-management | ||
ports: | ||
- 5672:5672 | ||
- 15672:15672 |
This file contains 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mlflow-skinny | ||
sqlalchemy | ||
SQLAlchemy>=1.4.42 | ||
alembic | ||
sqlparse | ||
watchdog>=2.1.9 | ||
|
This file contains 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
This file contains 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,29 @@ | ||
from redis import Redis | ||
|
||
from flowcept.flowceptor.plugins.settings_dataclasses import AbstractSettings | ||
|
||
|
||
class InterceptorStateManager(object): | ||
def __init__(self, settings: AbstractSettings): | ||
self._set_name = settings.key | ||
|
||
if not hasattr(settings, "redis_host"): | ||
raise Exception( | ||
f"This plugin setting {settings.key} " | ||
f"does not have a Redis Host." | ||
) | ||
|
||
self._db = Redis( | ||
host=settings.redis_host, | ||
port=settings.redis_port, | ||
db=0, | ||
) | ||
|
||
def clear_set(self): | ||
self._db.delete(self._set_name) | ||
|
||
def add_element_id(self, element_id: str): | ||
self._db.sadd(self._set_name, element_id) | ||
|
||
def has_element_id(self, element_id) -> bool: | ||
return self._db.sismember(self._set_name, element_id) |
This file contains 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,94 @@ | ||
from typing import List | ||
from sqlalchemy.engine import Row, create_engine | ||
from textwrap import dedent | ||
from flowcept.flowceptor.plugins.mlflow.mlflow_dataclasses import RunData | ||
from flowcept.flowceptor.plugins.settings_dataclasses import ( | ||
MLFlowSettings, | ||
) | ||
|
||
|
||
class MLFlowDAO: | ||
|
||
_LIMIT = 10 | ||
# TODO: This should not at all be hard coded. | ||
# This value needs to be greater than the amount of | ||
# runs inserted in the Runs table at each data observation | ||
|
||
def __init__(self, mlflow_settings: MLFlowSettings): | ||
self._engine = MLFlowDAO._get_db_engine(mlflow_settings.file_path) | ||
|
||
@staticmethod | ||
def _get_db_engine(sqlite_file): | ||
try: | ||
db_uri = f"sqlite:///{sqlite_file}" | ||
engine = create_engine(db_uri) | ||
return engine | ||
except Exception: | ||
raise Exception(f"Could not create DB engine with uri: {db_uri}") | ||
|
||
def get_finished_run_uuids(self) -> List[Row]: | ||
sql = dedent( | ||
f""" | ||
SELECT run_uuid | ||
FROM | ||
runs | ||
WHERE | ||
status = 'FINISHED' | ||
ORDER BY end_time DESC | ||
LIMIT {MLFlowDAO._LIMIT} | ||
""" | ||
) | ||
conn = self._engine.connect() | ||
results = conn.execute(sql).fetchall() | ||
return results | ||
|
||
def get_run_data(self, run_uuid: str) -> RunData: | ||
# TODO: consider outer joins to get the run data even if there's | ||
# no metric or param | ||
sql = dedent( | ||
f""" | ||
SELECT r.run_uuid, r.start_time, r.end_time, r.status, | ||
m.key as 'metric_key', m.value as 'metric_value', | ||
p.key as 'parameter_key', p.value as 'parameter_value' | ||
FROM | ||
runs AS r, | ||
metrics as m, | ||
params as p | ||
WHERE | ||
r.run_uuid = m.run_uuid AND | ||
m.run_uuid = p.run_uuid AND | ||
r.run_uuid = '{run_uuid}' AND | ||
r.status = 'FINISHED' | ||
ORDER BY | ||
end_time DESC, | ||
metric_key, metric_value, | ||
parameter_key, parameter_value | ||
LIMIT 30 | ||
""" | ||
) | ||
conn = self._engine.connect() | ||
result_set = conn.execute(sql).fetchall() | ||
run_data_dict = {"metrics": {}, "parameters": {}} | ||
for tuple_ in result_set: | ||
tuple_dict = tuple_._asdict() | ||
metric_key = tuple_dict.get("metric_key", None) | ||
metric_value = tuple_dict.get("metric_value", None) | ||
if metric_key and metric_value: | ||
if not (metric_key in run_data_dict["metrics"]): | ||
run_data_dict["metrics"][metric_key] = None | ||
run_data_dict["metrics"][metric_key] = metric_value | ||
|
||
param_key = tuple_dict.get("parameter_key", None) | ||
param_value = tuple_dict.get("parameter_value", None) | ||
if param_key and param_value: | ||
if not (param_key in run_data_dict["parameters"]): | ||
run_data_dict["parameters"][param_key] = None | ||
run_data_dict["parameters"][param_key] = param_value | ||
|
||
run_data_dict["run_uuid"] = tuple_dict["run_uuid"] | ||
run_data_dict["start_time"] = tuple_dict["start_time"] | ||
run_data_dict["end_time"] = tuple_dict["end_time"] | ||
run_data_dict["status"] = tuple_dict["status"] | ||
|
||
run_data = RunData(**run_data_dict) | ||
return run_data |
This file contains 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,12 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class RunData: | ||
|
||
run_uuid: str | ||
start_time: int | ||
end_time: int | ||
metrics: dict | ||
parameters: dict | ||
status: str |
This file contains 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.