Skip to content

Commit

Permalink
Add doctest and fix issues in example
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCentauri authored and Luthaf committed Feb 3, 2025
1 parent ae7a507 commit 54bac1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions python/vesin-torch/vesin/torch/metatensor/_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ def __init__(self, options: NeighborListOptions, length_unit: str):
... types=torch.tensor([8, 1, 1]),
... pbc=torch.ones(3, dtype=bool),
... )
>>> options = NeighborListOptions(cutoff=4.0, full_list=True)
>>> options = NeighborListOptions(cutoff=4.0, full_list=True, strict=False)
>>> calculator = NeighborList(options, length_unit="Angstrom")
>>> neighbors = calculator.compute(system)
>>> neighbors
TensorBlock
samples (54): ['first_atom', 'second_atom', 'cell_shift_a', 'cell_shift_b',
... 'cell_shift_c']
samples (18): ['first_atom', 'second_atom', 'cell_shift_a', 'cell_shift_b', 'cell_shift_c']
components (3): ['xyz']
properties (1): ['distance']
gradients: None
>>> # The returned TensorBlock can then be registered with the system
<BLANKLINE>
The returned TensorBlock can then be registered with the system
>>> system.add_neighbor_list(options, neighbors)
"""
""" # noqa: E501

if not torch.jit.is_scripting():
if not _HAS_METATENSOR:
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ changedir = python/vesin
commands =
pytest {posargs}

# Enable when doc examples exist; pytest fails if no tests exist
# pytest --doctest-modules --pyargs vesin

[testenv:torch-tests]
passenv = *
description = Run the tests of the vesin-torch Python package
Expand All @@ -54,6 +57,7 @@ commands =
python {toxinidir}/scripts/pytest-dont-rewrite-torch.py

pytest {posargs}
pytest --doctest-modules --pyargs vesin.torch


[testenv:cxx-tests]
Expand Down

0 comments on commit 54bac1a

Please sign in to comment.