You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@bruno-f-cruz copying the discussion from #1385 since I'll close that issue soon.
For reference, this is related to https://github.com/AllenNeuralDynamics/aind-data-schema/issues/960. I raised this exact issue here (https://github.com/AllenNeuralDynamics/aind-data-schema/issues/960#issuecomment-2155055024). While this PR solves the specific problem, please consider the larger issue: These enum-like classes can't be easily hashed, and this will always present problems when trying to use Set or Dict, which is a big limitation IMO.
Yes, same issue. But we're still trapped by the goal/requirement of keeping information about registries attached to their corresponding objects
A few possible solutions come to mind:
Modify the serialization/schema building behavior to "mock" it as a simple enum (this API is a bit annoying, but we have done it in the past https://github.com/AllenNeuralDynamics/aind-behavior-curriculum/blob/e18289f084ba325df0bfe3c3ada79a5cbf18fcdc/src/aind_behavior_curriculum/curriculum.py#L53). It should be noted that this may not even fix the problem completely depending on what class you deserialize to.
Attach the information as metadata via annotated (this is a bit clunky...):
from aind_data_schema_models.modalities import Modality
import enum
from typing import Annotated, get_args
class StrModality(enum.Enum):
BEHAVIOR = "behavior"
VIDEO = "video"
StrModalityWithMetadata = Annotated[StrModality, Modality]
def materialize_metadata(value: StrModality):
return get_args(StrModalityWithMetadata)[1].from_abbreviation(value.value)
print(StrModalityWithMetadata.BEHAVIOR)
print(materialize_metadata(StrModality.BEHAVIOR))
a = {StrModalityWithMetadata.BEHAVIOR: 1, StrModalityWithMetadata.VIDEO: 2}
print(a)
If the information is not necessary during schema building, and only later during analysis, one simple way to go about this is to add a single method (e.g. materialize_enum_reference(modality: Enum.Modality) -> FullyReferencedModality). This method decouples the ontology from the code that generates the fully referenced structure. The fully referenced structure could be fetched from a separate database (or even from the library itself, worst-case scenario).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
@bruno-f-cruz copying the discussion from #1385 since I'll close that issue soon.
Beta Was this translation helpful? Give feedback.
All reactions