Skip to content

Commit

Permalink
Add warning to SerializationMixin, to prevent usage that will resul…
Browse files Browse the repository at this point in the history
…t in circular deps (#2629)

Summary:
Pull Request resolved: #2629

As titled, just adds a docstring and a warning therein

Reviewed By: mpolson64

Differential Revision: D57390738

fbshipit-source-id: 958efe83d62a098456677eb6aaab06e786cdf872
  • Loading branch information
mgarrard authored and facebook-github-bot committed Aug 2, 2024
1 parent f25b4ce commit 8587587
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ax/utils/common/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ def extract_init_args(args: Dict[str, Any], class_: Type) -> Dict[str, Any]:


class SerializationMixin:
"""Base class for Ax objects that define their JSON serialization and
deserialization logic at the class level, e.g. most commonly ``Runner``
and ``Metric`` subclasses.
NOTE: Using this class for Ax objects that receive other Ax objects
as inputs, is recommended only iff the parent object (that would be
inheriting from this base class) is not enrolled into
CORE_ENCODER/DECODER_REGISTRY. Inheriting from this mixin with an Ax
object that is in CORE_ENCODER/DECODER_REGISTRY, will result in a
circular dependency, so such classes should inplement their encoding
and decoding logic within the `json_store` module and not on the classes.
For example, TransitionCriterion take TrialStatus as inputs and are defined
on the CORE_ENCODER/DECODER_REGISTRY, so TransitionCriterion should not inherit
from SerializationMixin and should define custom encoding/decoding logic within
the json_store module.
"""

@classmethod
def serialize_init_args(cls, obj: SerializationMixin) -> Dict[str, Any]:
"""Serialize the properties needed to initialize the object.
Expand Down

0 comments on commit 8587587

Please sign in to comment.