Skip to content

Commit

Permalink
Bring back Encoder/Decoder in DBSettings
Browse files Browse the repository at this point in the history
Summary:
An amendment to D15335716 -- turns out we do need Encoder/Decoder in DBSettings, rather than Config, otherwise there's no easy way to make it work with Facebook.

(Keeping the url/creator change, though.)

Differential Revision: D15352973

fbshipit-source-id: 463451842fb4acf9d97322c59d8de2e4be632ad4
  • Loading branch information
ldworkin authored and facebook-github-bot committed May 15, 2019
1 parent f4455d9 commit f14b508
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions ax/service/utils/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
from ax.core.experiment import Experiment
from ax.storage.sqa_store.db import init_engine_and_session_factory
from ax.storage.sqa_store.load import load_experiment as _load_experiment
from ax.storage.sqa_store.save import save_experiment as _save_experiment
from ax.storage.sqa_store.load import _load_experiment
from ax.storage.sqa_store.save import _save_experiment
from ax.storage.sqa_store.structs import DBSettings


Expand All @@ -22,7 +22,7 @@ def load_experiment(name: str, db_settings: DBSettings) -> Experiment:
ax.core.Experiment: Loaded experiment.
"""
init_engine_and_session_factory(creator=db_settings.creator, url=db_settings.url)
experiment = _load_experiment(name, db_settings.config)
experiment = _load_experiment(name, decoder=db_settings.decoder)
if not isinstance(experiment, Experiment) or experiment.is_simple_experiment:
raise ValueError("Service API only supports Experiment")
return experiment
Expand All @@ -37,4 +37,4 @@ def save_experiment(experiment: Experiment, db_settings: DBSettings) -> None:
db_settings: Defines behavior for loading/saving experiment to/from db.
"""
init_engine_and_session_factory(creator=db_settings.creator, url=db_settings.url)
_save_experiment(experiment, db_settings.config)
_save_experiment(experiment, encoder=db_settings.encoder)
6 changes: 5 additions & 1 deletion ax/storage/sqa_store/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

from typing import Callable, NamedTuple, Optional

from ax.storage.sqa_store.decoder import Decoder
from ax.storage.sqa_store.encoder import Encoder
from ax.storage.sqa_store.sqa_config import SQAConfig


class DBSettings(NamedTuple):
"""
Defines behavior for loading/saving experiment to/from db.
Either creator or url must be specified as a way to connect to the SQL db.
"""

config: Optional[SQAConfig] = SQAConfig()
creator: Optional[Callable] = None
decoder: Decoder = Decoder(config=SQAConfig())
encoder: Encoder = Encoder(config=SQAConfig())
url: Optional[str] = None

0 comments on commit f14b508

Please sign in to comment.