Skip to content

Commit 8587587

Browse files
mgarrardfacebook-github-bot
authored andcommitted
Add warning to SerializationMixin, to prevent usage that will result in circular deps (facebook#2629)
Summary: Pull Request resolved: facebook#2629 As titled, just adds a docstring and a warning therein Reviewed By: mpolson64 Differential Revision: D57390738 fbshipit-source-id: 958efe83d62a098456677eb6aaab06e786cdf872
1 parent f25b4ce commit 8587587

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ax/utils/common/serialization.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ def extract_init_args(args: Dict[str, Any], class_: Type) -> Dict[str, Any]:
129129

130130

131131
class SerializationMixin:
132+
"""Base class for Ax objects that define their JSON serialization and
133+
deserialization logic at the class level, e.g. most commonly ``Runner``
134+
and ``Metric`` subclasses.
135+
136+
NOTE: Using this class for Ax objects that receive other Ax objects
137+
as inputs, is recommended only iff the parent object (that would be
138+
inheriting from this base class) is not enrolled into
139+
CORE_ENCODER/DECODER_REGISTRY. Inheriting from this mixin with an Ax
140+
object that is in CORE_ENCODER/DECODER_REGISTRY, will result in a
141+
circular dependency, so such classes should inplement their encoding
142+
and decoding logic within the `json_store` module and not on the classes.
143+
144+
For example, TransitionCriterion take TrialStatus as inputs and are defined
145+
on the CORE_ENCODER/DECODER_REGISTRY, so TransitionCriterion should not inherit
146+
from SerializationMixin and should define custom encoding/decoding logic within
147+
the json_store module.
148+
"""
149+
132150
@classmethod
133151
def serialize_init_args(cls, obj: SerializationMixin) -> Dict[str, Any]:
134152
"""Serialize the properties needed to initialize the object.

0 commit comments

Comments
 (0)