Skip to content

Add LAMMPS testing #78

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Add LAMMPS testing #78

wants to merge 16 commits into from

Conversation

mayukh33
Copy link
Contributor

No description provided.

Copy link
Contributor

@clpetix clpetix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on this! Just a few comments from me and a suggestion on how to address the topology tests.

@clpetix
Copy link
Contributor

clpetix commented May 20, 2025

@mayukh33, could you review the changes to dump.py?

@mayukh33
Copy link
Contributor Author

@mayukh33, could you review the changes to dump.py?

Looks good to me!

@clpetix
Copy link
Contributor

clpetix commented May 22, 2025

@mphoward, this is ready for your review!

Copy link
Contributor

@mphoward mphoward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This generally looks really good. Please address my comments and let me know if you have any questions.

@@ -42,3 +42,51 @@ jobs:
- name: Test (optin)
run: |
python -m pytest
test-lammps:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't seem like they are separate tests, since you are essentially rerunning everything in the test step here. Either you should mark the tests that need LAMMPS and only run those here:

https://docs.pytest.org/en/stable/example/markers.html

or else this test step can basically just replace the one above.

assert numpy.allclose(snap_2.charge, 0)
else:
assert not snap_2.has_charge()
_tmp.cleanup()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_tmp.cleanup()

@@ -1,8 +1,18 @@
import os
import tempfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import tempfile

Comment on lines +267 to +274
def test_data_file_min_lammps(snap, atom_style, shuffle_ids):
if shuffle_ids:
snap.id = [3, 1, 2]

# write the data file with default values using lammpsio
_tmp = tempfile.TemporaryDirectory()
directory = _tmp.name
filename = directory + "/atoms.data"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the tmp_path fixture rather than creating your own:

https://docs.pytest.org/en/6.2.x/tmpdir.html

Suggested change
def test_data_file_min_lammps(snap, atom_style, shuffle_ids):
if shuffle_ids:
snap.id = [3, 1, 2]
# write the data file with default values using lammpsio
_tmp = tempfile.TemporaryDirectory()
directory = _tmp.name
filename = directory + "/atoms.data"
def test_data_file_min_lammps(tmp_path, snap, atom_style, shuffle_ids):
if shuffle_ids:
snap.id = [3, 1, 2]
# write the data file with default values using lammpsio
filename = tmp_path / "atoms.data"

You may need one additionally command to stringify the file path.

Comment on lines +372 to +382
# create file with 2 snapshots
schema = {
"id": 13,
"position": (11, 10, 12),
"image": (9, 8, 7),
"velocity": (4, 5, 6),
"typeid": 3,
"mass": 2,
"molecule": 1,
"charge": 0,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably move this schema closer to where it is used. However, is this even necessary, or can the schema just be deduced from the file now?

Comment on lines +432 to +434
f = lammpsio.DumpFile.create(filename, schema, snaps)
assert filename.exists
assert len(f) == 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this overwriting the file that lammps created, destroying the test?

Suggested change
f = lammpsio.DumpFile.create(filename, schema, snaps)
assert filename.exists
assert len(f) == 2

Comment on lines +437 to +440
f2 = lammpsio.DumpFile(filename, sort_ids=sort_ids)
read_snaps = [s for s in f2]
for i, s in enumerate(f2):
assert read_snaps[i].N == snaps[i].N
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f2 = lammpsio.DumpFile(filename, sort_ids=sort_ids)
read_snaps = [s for s in f2]
for i, s in enumerate(f2):
assert read_snaps[i].N == snaps[i].N
f = lammpsio.DumpFile(filename, sort_ids=sort_ids)
assert filename.exists
assert len(f) == 2
for read_snap, snap in zip(f, snaps):
assert read_snap.N == snap.N



@pytest.mark.skipif(not has_lammps, reason="lammps not installed")
def test_copy_from_lammps(snap, tmp_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test necessary? Is the purpose only to test the copy_from argument, or is it doing something else? If only copy_from, that is a purely Python thing so I don't think we really need to test that with LAMMPS.



@pytest.mark.skipif(not has_lammps, reason="lammps not installed")
def test_copy_from_topology_lammps(snap_8, tmp_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here. If we've verified the topology info passes through LAMMPS correctly for the DataFile, I don't see a reason to separately test the copy_from feature on its again. If the test is doing something in addition to that, please clarify!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants