Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MPID assignment in electrode workflow #956

Merged
merged 8 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/atomate2/common/jobs/electrode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from typing import TYPE_CHECKING, Callable, NamedTuple

from emmet.core.electrode import InsertionElectrodeDoc
from emmet.core.mpid import MPID
from emmet.core.structure_group import StructureGroupDoc
from jobflow import Flow, Maker, Response, job
from pymatgen.analysis.defects.generators import ChargeInterstitialGenerator
from pymatgen.entries.computed_entries import ComputedStructureEntry
from ulid import ULID

if TYPE_CHECKING:
from pathlib import Path
Expand Down Expand Up @@ -154,13 +156,23 @@ def get_computed_entries(
return multi
# keep the [1] for now, if jobflow supports NamedTuple, we can do this much cleaner
s_ = RelaxJobSummary._make(single)
s_.entry.entry_id = s_.uuid

# Ensure that the entry_id is an acceptable MPID
try:
entry_id = MPID(s_.uuid)
except ValueError:
entry_id = ULID()
s_.entry.entry_id = str(entry_id)

# Store UUID for provenance
s_.entry.data["UUID"] = s_.uuid

ent = ComputedStructureEntry(
structure=s_.structure,
energy=s_.entry.energy,
parameters=s_.entry.parameters,
data=s_.entry.data,
entry_id=s_.uuid,
entry_id=s_.entry.entry_id,
)
return [*multi, ent]

Expand Down
21 changes: 1 addition & 20 deletions tests/vasp/flows/test_electrode.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
from __future__ import annotations

from unittest import mock

import pytest
from jobflow.settings import JobflowSettings


@pytest.fixture()
def mock_jobflow_settings(memory_jobstore):
"""Set the UID_TYPE to "ulid" to make sure the documents can be sorted.

See: https://github.com/materialsproject/jobflow/issues/519#issuecomment-1906850096
"""

settings = JobflowSettings(JOB_STORE=memory_jobstore, UID_TYPE="ulid")

with mock.patch("jobflow.SETTINGS", settings):
yield


def test_electrode_makers(mock_vasp, clean_dir, test_dir, mock_jobflow_settings):
def test_electrode_makers(mock_vasp, clean_dir, test_dir):
from emmet.core.electrode import InsertionElectrodeDoc
from jobflow import OutputReference, run_locally
from monty.serialization import loadfn
Expand All @@ -32,7 +14,6 @@ def test_electrode_makers(mock_vasp, clean_dir, test_dir, mock_jobflow_settings)
update_user_incar_settings,
update_user_kpoints_settings,
)
# mock the default setting

# mapping from job name to directory containing test files
ref_paths = {
Expand Down
Loading