OpenFreeEnergy / gufe

grand unified free energy by OpenFE
https://gufe.readthedocs.io
MIT License
28 stars 7 forks source link

UUID JSON codec? #293

Closed hmacdope closed 4 months ago

hmacdope commented 4 months ago

We often find ourselves trying to attach UUIDs to GUFE objects. These can't be serialised as a class but can easily be represented as a string. Would you be open to adding a UUID codec? It would looks something like:

PATH_CODEC = JSONCodec(
    cls=uuid.UUID,
    to_dict=lambda u: {"uuid": str(u)},
    from_dict=lambda dct: UUID(dct["uuid"]),
)

See https://github.com/choderalab/asapdiscovery/issues/886 for occurrence in the wild. Happy to contribute the change myself if good to go ahead. Tagging @jthorton here also.

richardjgowers commented 4 months ago

Yeah adding a codec is a good idea if you can?

On Tue, 27 Feb 2024 at 23:36, Hugo MacDermott-Opeskin < @.***> wrote:

We often find ourselves trying to attach UUIDs to GUFE objects. These can't be serialised as a class but can easily be represented as a string. Would you be open to adding a UUID codec? It would looks something like:

PATH_CODEC = JSONCodec( cls=uuid.UUID, to_dict=lambda u: {"uuid": str(u)}, from_dict=lambda dct: pathlib.PosixPath(dct["uuid"]), )

See choderalab/asapdiscovery#886 https://github.com/choderalab/asapdiscovery/issues/886 for occurrence in the wild. Happy to contribute the change myself if good to go ahead. Tagging @jthorton https://github.com/jthorton here also.

— Reply to this email directly, view it on GitHub https://github.com/OpenFreeEnergy/gufe/issues/293, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGSGB6XP4XLVOCHMJYYAE3YVZUW7AVCNFSM6AAAAABD5ALBWWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE2TONZZHA4TENA . You are receiving this because you are subscribed to this thread.Message ID: @.***>