From f14b5086081bc28feab9761de493ae56e34631df Mon Sep 17 00:00:00 2001 From: Lili Dworkin Date: Wed, 15 May 2019 12:08:37 -0700 Subject: [PATCH] Bring back Encoder/Decoder in DBSettings 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 --- ax/service/utils/storage.py | 8 ++++---- ax/storage/sqa_store/structs.py | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ax/service/utils/storage.py b/ax/service/utils/storage.py index 1b6c23ffade..96c94ad012d 100644 --- a/ax/service/utils/storage.py +++ b/ax/service/utils/storage.py @@ -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 @@ -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 @@ -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) diff --git a/ax/storage/sqa_store/structs.py b/ax/storage/sqa_store/structs.py index 9de2705d55a..8800b5c4eac 100644 --- a/ax/storage/sqa_store/structs.py +++ b/ax/storage/sqa_store/structs.py @@ -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