Skip to content

Commit

Permalink
Add storage tutorial to registry-related errors (#2687)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2687

There have been a few storage-related issues ([example](#1780)). Linking to docs from error messages may help.

Reviewed By: lena-kashtelyan

Differential Revision: D48451133

fbshipit-source-id: d8eb71c35e056a787137b2fdb9be8d687909d884
  • Loading branch information
Bernie Beckerman authored and facebook-github-bot committed Aug 21, 2024
1 parent 8801c79 commit 5b8d203
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
7 changes: 7 additions & 0 deletions ax/exceptions/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
from ax.exceptions.core import AxError


STORAGE_DOCS_SUFFIX = (
"Please see our storage tutorial (https://ax.dev/docs/storage.html) "
"for more details ('Customizing' section will be "
"relevant for saving Ax object subclasses)."
)


class JSONDecodeError(AxError):
"""Raised when an error occurs during JSON decoding."""

Expand Down
4 changes: 2 additions & 2 deletions ax/storage/json_store/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
SumConstraint,
)
from ax.core.search_space import SearchSpace
from ax.exceptions.storage import JSONDecodeError
from ax.exceptions.storage import JSONDecodeError, STORAGE_DOCS_SUFFIX
from ax.modelbridge.generation_strategy import (
GenerationNode,
GenerationStep,
Expand Down Expand Up @@ -160,7 +160,7 @@ def object_from_json(
err = (
f"The JSON dictionary passed to `object_from_json` has a type "
f"{_type} that is not registered with a corresponding class in "
f"DECODER_REGISTRY."
f"DECODER_REGISTRY. {STORAGE_DOCS_SUFFIX}"
)
raise JSONDecodeError(err)

Expand Down
4 changes: 2 additions & 2 deletions ax/storage/json_store/decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def class_from_json(json: dict[str, Any]) -> type[Any]:
reverse_registry = CLASS_TO_REVERSE_REGISTRY[_class]
if index_in_registry not in reverse_registry:
raise ValueError(
f"Index '{index_in_registry}'"
" is not registered in the reverse registry."
f"Index '{index_in_registry}' is not registered in the reverse "
f"registry."
)
return reverse_registry[index_in_registry]
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions ax/storage/json_store/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import numpy as np
import pandas as pd
import torch
from ax.exceptions.storage import JSONEncodeError
from ax.exceptions.storage import JSONEncodeError, STORAGE_DOCS_SUFFIX
from ax.storage.json_store.encoders import tensor_to_dict
from ax.storage.json_store.registry import (
CORE_CLASS_ENCODER_REGISTRY,
Expand Down Expand Up @@ -185,6 +185,6 @@ def object_to_json( # noqa C901
err = (
f"Object {obj} passed to `object_to_json` (of type {_type}, module: "
f"{_type.__module__}) is not registered with a corresponding encoder "
"in ENCODER_REGISTRY."
f"in ENCODER_REGISTRY. {STORAGE_DOCS_SUFFIX}"
)
raise JSONEncodeError(err)
7 changes: 4 additions & 3 deletions ax/storage/json_store/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
ThresholdEarlyStoppingStrategy,
)
from ax.exceptions.core import AxStorageWarning
from ax.exceptions.storage import JSONEncodeError
from ax.exceptions.storage import JSONEncodeError, STORAGE_DOCS_SUFFIX
from ax.global_stopping.strategies.improvement import ImprovementGlobalStoppingStrategy
from ax.modelbridge.best_model_selector import BestModelSelector
from ax.modelbridge.generation_node import GenerationNode
Expand Down Expand Up @@ -572,7 +572,8 @@ def botorch_modular_to_dict(class_type: type[Any]) -> dict[str, Any]:
raise ValueError(
f"Class `{class_type.__name__}` not in Type[{_class.__name__}] "
"registry, please add it. BoTorch object registries are "
"located in `ax/storage/botorch_modular_registry.py`."
"located in `ax/storage/botorch_modular_registry.py`. "
f"{STORAGE_DOCS_SUFFIX}"
)
return {
"__type": f"Type[{_class.__name__}]",
Expand All @@ -581,7 +582,7 @@ def botorch_modular_to_dict(class_type: type[Any]) -> dict[str, Any]:
}
raise ValueError(
f"{class_type} does not have a corresponding parent class in "
"CLASS_TO_REGISTRY."
f"CLASS_TO_REGISTRY. {STORAGE_DOCS_SUFFIX}"
)


Expand Down

0 comments on commit 5b8d203

Please sign in to comment.