esteinig / critter

BEAST models for pathogen transmission dynamics in Python
Apache License 2.0
1 stars 0 forks source link

Unique ID on class import #9

Open esteinig opened 2 years ago

esteinig commented 2 years ago

Unique identifier in distributions and parameters (using critter.utils.get_uuid) is instantiated at import, so that using the same import results in assignment of the same (replicated) identifiers.

esteinig commented 2 years ago

I should rewrite the distribution classes, they are a mess

esteinig commented 2 years ago

Distributions identifiers are now PrivateAttr and not settable on instantiation; instead, a unique (uuid4) identifier is assigned on instance creation. Each parameter in the distribution is also assigned a private identifier (but Parameter classes identifiers can still be set if needed).

class Distribution(BaseModel):
    _id: str = PrivateAttr()

class Uniform(Distribution):
    def __init__(self, **data):
        super().__init__(**data)
        self._id: str = f"Uniform.{get_uuid(short=False)}"

Instances are unique:

from critter.blocks.distributions import Uniform 
uni1, uni2 = Uniform(), Uniform()
assert uni1._id != uni2._id

Might change this to an incremental numeric identifier instead of unique, so the output XML files for BEAST can be tested - leaving issue open for now.