Skip to content

Commit

Permalink
add batch_id to tasks, mark certain glue code for removal pending db …
Browse files Browse the repository at this point in the history
…update
  • Loading branch information
esoteric-ephemera committed May 21, 2024
1 parent 7ab775f commit 2e27989
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion emmet-core/emmet/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from emmet.core import __version__
from emmet.core.common import convert_datetime
from emmet.core.utils import utcnow

T = TypeVar("T", bound="EmmetBaseModel")

Expand All @@ -34,7 +35,7 @@ class EmmetMeta(BaseModel):
)

build_date: Optional[datetime] = Field( # type: ignore
default_factory=datetime.utcnow,
default_factory=utcnow,
description="The build date for this document.",
)

Expand Down
19 changes: 19 additions & 0 deletions emmet-core/emmet/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ class TaskDoc(StructureMetadata, extra="allow"):
description="Timestamp for the most recent calculation for this task document",
)

batch_id: Optional[str] = Field(
None,
description="Identifier for this calculation; should provide rough information about the calculation origin and purpose.",
)

# Note that these private fields are needed because TaskDoc permits extra info
# added to the model, unlike TaskDocument. Because of this, when pydantic looks up
# attrs on the model, it searches for them in the model extra dict first, and if it
Expand All @@ -447,6 +452,7 @@ def model_post_init(self, __context: Any) -> None:
self._run_type = RunType(temp[0])
self.task_type = TaskType(" ".join(temp[1:]))

# TODO: remove after imposing TaskDoc schema on older tasks in collection
if self.structure is None:
self.structure = self.calcs_reversed[0].output.structure

Expand All @@ -457,6 +463,19 @@ def model_post_init(self, __context: Any) -> None:
def last_updated_dict_ok(cls, v) -> datetime:
return convert_datetime(cls, v)

@field_validator("batch_id", mode="before")
@classmethod
def _validate_batch_id(cls, v) -> str:
if v is not None:
invalid_chars = set(
char for char in v if (not char.isalnum()) or (char not in {"-", "_"})
)
if len(invalid_chars) > 0:
raise ValueError(
f"Invalid characters in batch_id:\n{' '.join(invalid_chars)}"
)
return v

@model_validator(mode="after")
def set_entry(self) -> datetime:
if (
Expand Down
2 changes: 1 addition & 1 deletion emmet-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
include_package_data=True,
install_requires=[
"pymatgen<=2024.4.13",
"pymatgen==2024.4.13",
"monty>=2024.2.2",
"pydantic>=2.0",
"pydantic-settings>=2.0",
Expand Down

0 comments on commit 2e27989

Please sign in to comment.