Skip to content

Commit

Permalink
Various updates following GP's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwaroquiers committed Jul 1, 2022
1 parent 858cbc9 commit 230bfa5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/atomate2/abinit/jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def make(
)

# Run abinit
run_abinit(
run_status = run_abinit(
abinit_cmd=job_config.settings.ABINIT_CMD,
mpirun_cmd=job_config.settings.ABINIT_MPIRUN_CMD,
wall_time=job_config.wall_time,
Expand All @@ -286,7 +286,7 @@ def make(
job_config.workdir,
critical_events=self.critical_events,
run_number=run_number,
# structure_fixed=self.structure_fixed,
run_status=run_status,
)
task_doc.task_label = self.name

Expand Down
4 changes: 4 additions & 0 deletions src/atomate2/abinit/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def run_abinit(

command.append(INPUT_FILE_NAME)

status = "completed"

with open(LOG_FILE_NAME, "w") as stdout, open(STDERR_FILE_NAME, "w") as stderr:
process = subprocess.Popen(command, stdout=stdout, stderr=stderr)

Expand All @@ -58,5 +60,7 @@ def run_abinit(
remaining_time = max_end_time - current_time
if remaining_time < 5 * SLEEP_TIME_STEP:
process.terminate()
status = "killed"

process.wait()
return status
2 changes: 1 addition & 1 deletion src/atomate2/abinit/schemas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def from_directory(
source: str = "log",
critical_events=None,
run_number=1,
# structure_fixed=True,
run_status=None,
) -> _T:
"""Build AbinitTaskDocument from directory."""
# Files required for the job analysis.
Expand Down
22 changes: 13 additions & 9 deletions src/atomate2/abinit/sets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from abipy.abio.inputs import AbinitInput
from abipy.flowtk.psrepos import get_repo_from_name
from abipy.flowtk.utils import Directory, irdvars_for_ext
from monty.json import MontyEncoder
from pymatgen.core.structure import Structure
from pymatgen.io.abinit.pseudos import PseudoTable
from pymatgen.io.core import InputGenerator, InputSet
Expand Down Expand Up @@ -55,7 +56,14 @@ def __init__(
self.input_files = input_files
self.link_files = link_files
self.validation = validation
super().__init__(inputs={INPUT_FILE_NAME: abinit_input})
super().__init__(
inputs={
INPUT_FILE_NAME: abinit_input,
"abinit_input.json": json.dumps(
abinit_input.as_dict(), cls=MontyEncoder
),
}
)

def write_input(
self,
Expand Down Expand Up @@ -366,6 +374,10 @@ def get_input_set( # type: ignore
params = self.get_params(
instance_or_class=self, kwargs=kwargs, prev_gen=None
)
if prev_outputs is not None and not self.prev_outputs_deps:
raise RuntimeError(
f"Previous outputs not allowed for {self.__class__.__name__}."
)
abinit_input = self.get_abinit_input(
structure=structure,
pseudos=pseudos,
Expand Down Expand Up @@ -407,14 +419,6 @@ def check_format_prev_dirs(self, prev_dirs):
return None
if isinstance(prev_dirs, (str, Path)):
return [str(prev_dirs)]
if not isinstance(prev_dirs, (list, tuple)):
raise RuntimeError(
"Previous directories should be provided as a list "
"or tuple of str or a single str."
)
for prev_dir in prev_dirs:
if not isinstance(prev_dir, (str, Path)):
raise RuntimeError("Previous directory should be a str or a Path.")
return [str(prev_dir) for prev_dir in prev_dirs]

def resolve_deps(self, prev_dirs, deps, check_runlevel=True):
Expand Down
21 changes: 7 additions & 14 deletions tests/abinit/sets/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@


class TestAbinitInputSet:
def test_init(self):
abinit_input = "FakeAbinitInput"
def test_init(self, abinit_test_dir):
abinit_input = load_abinit_input(
os.path.join(abinit_test_dir, "abinit_inputs"), fname="abinit_input_Si.json"
)
ais = AbinitInputSet(abinit_input=abinit_input)
assert ais.inputs == {"run.abi": abinit_input}
assert set(ais.inputs.keys()) == {"run.abi", "abinit_input.json"}
assert ais.inputs["run.abi"] == abinit_input
assert '"@class": "AbinitInput"' in ais.inputs["abinit_input.json"]
assert ais.input_files is None
assert ais.link_files is True
ais = AbinitInputSet(
abinit_input=abinit_input,
input_files=["/some/input/file", "/some/other/input/file"],
link_files=False,
)
assert ais.inputs == {"run.abi": abinit_input}
assert ais.input_files == ["/some/input/file", "/some/other/input/file"]
assert ais.link_files is False

Expand Down Expand Up @@ -203,16 +206,6 @@ def test_check_format_prev_dirs(self):
assert prev_outputs == ["/some/path"]
prev_outputs = aisg.check_format_prev_dirs(Path("/some/path"))
assert prev_outputs == ["/some/path"]
with pytest.raises(
RuntimeError,
match=r"Previous directories should be provided as a list "
"or tuple of str or a single str.",
):
aisg.check_format_prev_dirs(3.5)
with pytest.raises(
RuntimeError, match=r"Previous directory should be a str or a Path."
):
aisg.check_format_prev_dirs(["/some/path", 3.5])
prev_outputs = aisg.check_format_prev_dirs(
["/some/path", Path("/some/other/path")]
)
Expand Down

0 comments on commit 230bfa5

Please sign in to comment.