Skip to content

Commit

Permalink
Display metatensor-torch torchscript classes correctly in docs (#40)
Browse files Browse the repository at this point in the history
* Display torchscript classes correctly in docs
* Disable compiled functions when building docs
  • Loading branch information
frostedoyster authored Jan 26, 2024
1 parent e54c82a commit cfa37b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
ROOT = os.path.abspath(os.path.join("..", ".."))
sys.path.insert(0, ROOT)

# when importing metatensor-torch, this will change the definition of the classes
# to include the documentation
os.environ["METATENSOR_IMPORT_FOR_SPHINX"] = "1"

# -- Project information -----------------------------------------------------

# The master toctree document.
Expand Down
10 changes: 8 additions & 2 deletions src/metatensor/models/utils/data/dataset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Dict, List

import metatensor.torch
Expand All @@ -6,8 +7,13 @@
from metatensor.torch.atomistic import ModelCapabilities, System


compiled_slice = torch.jit.script(metatensor.torch.slice)
compiled_join = torch.jit.script(metatensor.torch.join)
if os.environ.get("METATENSOR_IMPORT_FOR_SPHINX", "0") == "1":
# This is necessary to make the Sphinx documentation build
compiled_slice = None
compiled_join = None
else:
compiled_slice = torch.jit.script(metatensor.torch.slice)
compiled_join = torch.jit.script(metatensor.torch.join)


class Dataset(torch.utils.data.Dataset):
Expand Down

0 comments on commit cfa37b2

Please sign in to comment.