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

Add documentation structure #13

Merged
merged 33 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4661a74
Add basic documentation structure
frostedoyster Dec 2, 2023
9073fba
Fix conf.py path
frostedoyster Dec 2, 2023
0cfd607
Make readthedocs install requirements
frostedoyster Dec 2, 2023
62bde5a
??
frostedoyster Dec 2, 2023
e763bb4
???
frostedoyster Dec 2, 2023
0638701
Fix everything
frostedoyster Dec 2, 2023
914bc0f
Set up tox -e docs and run it in CI
frostedoyster Dec 2, 2023
b584288
Dbug
frostedoyster Dec 2, 2023
99d7dc3
Re-add warnings
frostedoyster Dec 2, 2023
b805516
Make sure _static and _templates are not ignored
frostedoyster Dec 2, 2023
097214e
Add documentation preview
frostedoyster Dec 2, 2023
a710388
Eliminate double installation?
frostedoyster Dec 2, 2023
d148e17
Write a documentation skeleton
frostedoyster Dec 2, 2023
6bd1da8
Fix a few issues with the documentation display
frostedoyster Dec 2, 2023
5a612ac
Remove makefiles, add intersphinx
frostedoyster Dec 2, 2023
fc64450
Attempt parsing of version
frostedoyster Dec 2, 2023
bb1c6cf
Fix parsing?
frostedoyster Dec 2, 2023
0171bcd
Try again
frostedoyster Dec 2, 2023
b56c7b2
Add developer documentation page
frostedoyster Dec 3, 2023
0e327a0
Add documentation of utils
frostedoyster Dec 4, 2023
075ba72
Try to install metatensor-models on readthedocs
frostedoyster Dec 4, 2023
561bc28
What?
frostedoyster Dec 4, 2023
44add8c
?
frostedoyster Dec 4, 2023
0e380d2
???
frostedoyster Dec 4, 2023
9c69733
Fix readthedocs
frostedoyster Dec 4, 2023
ded5c0d
Try to show utils documentation
frostedoyster Dec 4, 2023
ec3a9c8
Try to fix readthedocs build in a different way
frostedoyster Dec 5, 2023
29857f3
Fix it for real
frostedoyster Dec 5, 2023
8ffe755
Go back to old configuration file
frostedoyster Dec 5, 2023
1e1de75
Try again
frostedoyster Dec 5, 2023
0255001
more structure to utils docs
PicoCentauri Dec 5, 2023
3fabf96
Try to fix readthedocs failure
frostedoyster Dec 5, 2023
4afef12
Add comment about environment variable
PicoCentauri Dec 5, 2023
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
27 changes: 27 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Documentation

on:
push:
branches: [main]
tags: ["*"]
pull_request:
# Check all PR

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: install dependencies
run: |
python -m pip install tox
sudo apt install doxygen
- name: build documentation
run: tox -e docs
env:
# Use the CPU-only version of torch
PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu
17 changes: 17 additions & 0 deletions .github/workflows/pr-docs-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: readthedocs/actions

on:
pull_request_target:
types:
- opened

permissions:
pull-requests: write

jobs:
documentation-links:
runs-on: ubuntu-latest
steps:
- uses: readthedocs/actions/preview@v1
with:
project-slug: metatensor-models
30 changes: 30 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
rust: "1.70"


# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/src/conf.py
fail_on_warning: true


# Declare the Python requirements required to build the docs.
# Additionally, a custom environment variable
# PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu
# is declared in the project’s dashboard
python:
install:
- method: pip
path: .
- requirements: docs/requirements.txt
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ prune .tox

exclude .gitignore
exclude tox.ini
exclude .readthedocs.yml

global-exclude *.py[cod] __pycache__/* *.so *.dylib
4 changes: 4 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
furo
sphinx >= 7
sphinx-toggleprompt
tomli
Empty file added docs/src/_static/.gitkeep
Empty file.
Empty file added docs/src/_templates/.gitkeep
Empty file.
80 changes: 80 additions & 0 deletions docs/src/conf.py
Copy link
Contributor

Choose a reason for hiding this comment

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

In general some intersphinx and all the options we use in metatensor for organizing the docstring are very useful and should be added.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import sys
from datetime import datetime

import tomli # Replace by tomllib from std library once docs are build with Python 3.11

import metatensor_models


ROOT = os.path.abspath(os.path.join("..", ".."))
sys.path.insert(0, ROOT)

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

# The master toctree document.
master_doc = "index"

with open(os.path.join(ROOT, "pyproject.toml"), "rb") as fp:
project_dict = tomli.load(fp)["project"]

project = project_dict["name"]
author = ", ".join(a["name"] for a in project_dict["authors"])

copyright = f"{datetime.now().date().year}, {author}"

# The full version, including alpha/beta/rc tags
release = metatensor_models.__version__


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.viewcode",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx_toggleprompt",
]

python_use_unqualified_type_names = True

autoclass_content = "both"
autodoc_member_order = "bysource"
autodoc_typehints = "both"
autodoc_typehints_format = "short"

intersphinx_mapping = {
"ase": ("https://wiki.fysik.dtu.dk/ase/", None),
"python": ("https://docs.python.org/3", None),
"torch": ("https://pytorch.org/docs/stable/", None),
"metatensor": ("https://lab-cosmo.github.io/metatensor/latest/", None),
"rascaline": ("https://luthaf.fr/rascaline/latest/", None),
}

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "furo"

html_theme_options = {
"footer_icons": [
{
"name": "GitHub",
"url": project_dict["urls"]["repository"],
"html": "",
"class": "fa-brands fa-github fa-2x",
},
],
}

# font-awesome logos (used in the footer)
html_css_files = [
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/fontawesome.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/solid.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/brands.min.css",
]
4 changes: 4 additions & 0 deletions docs/src/dev-docs/adding-models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Adding new models
=================

To be done.
12 changes: 12 additions & 0 deletions docs/src/dev-docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Developer documentation
=======================

This is a collection of documentation for developers of the metatensor-models package.
It includes documentation on how to add a new model, as well as the API of the utils module.


.. toctree::
:maxdepth: 1

adding-models
utils/index
7 changes: 7 additions & 0 deletions docs/src/dev-docs/utils/dataset.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dataset
#######

.. automodule:: metatensor_models.utils.data.dataset
:members:
:undoc-members:
:show-inheritance:
10 changes: 10 additions & 0 deletions docs/src/dev-docs/utils/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Utilitliy API
=============

This is the API for the ``utils`` module of ``metatensor-models``.

.. toctree::
:maxdepth: 1

dataset
readers/index
17 changes: 17 additions & 0 deletions docs/src/dev-docs/utils/readers/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Structure and Target data Readers
=================================

The main entry point for reading structure and target information are the two reader
functions

.. automodule:: metatensor_models.utils.data.readers
:members:

Based on the provided filename they chose which child reader they use. For details on
these refer to their documentation

.. toctree::
:maxdepth: 1

structure
target
13 changes: 13 additions & 0 deletions docs/src/dev-docs/utils/readers/structure.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Structure Readers
#################

Parsers for obtaining information from structures. All readers return a :py:class:`list`
of :py:class:`rascaline.torch.system.System`. The mapping which reader is used for which
file type is stored in

.. autodata:: metatensor_models.utils.data.readers.structures.STRUCTURE_READERS

Implemented Readers
-------------------

.. autofunction:: metatensor_models.utils.data.readers.structures.read_ase
13 changes: 13 additions & 0 deletions docs/src/dev-docs/utils/readers/target.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Target data Readers
###################

Parsers for obtaining information from structures. All readers return a of
:py:class:`metatensor.torch.TensorMap`. The mapping which reader is used for which file
type is stored in

.. autodata:: metatensor_models.utils.data.readers.targets.TARGET_READERS

Implemented Readers
-------------------

.. autofunction:: metatensor_models.utils.data.readers.targets.read_ase
4 changes: 4 additions & 0 deletions docs/src/how-to.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
How-to
======

This section describes how to use the ``metatensor-models`` package.
12 changes: 12 additions & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Welcome to metatensor-models's documentation!
=============================================

This is a collection of atomistic models interfaced with ``metatensor``.

.. toctree::
:maxdepth: 1

quickstart
how-to
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also add our utils functions maybe as a subfolder API in the docs. Even if they are not essentials for the enduser they are useful if you want to develop something.

Copy link
Collaborator Author

@frostedoyster frostedoyster Dec 4, 2023

Choose a reason for hiding this comment

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

Utils are mainly for developers, which are not really the target of our documentation. I would add them under how-to/"add a new model" perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

we can also have two separate doc sections: one for users and one for devs. Rascaline does something like this.

models
dev-docs/index
10 changes: 10 additions & 0 deletions docs/src/models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Available models
================

This is a list of the models available in ``metatensor-models``.

.. toctree::
:maxdepth: 1
:glob:

models/*
4 changes: 4 additions & 0 deletions docs/src/models/soap-bpnn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SOAP-BPNN
=========

This is a Behler-Parrinello neural network with SOAP features.
8 changes: 8 additions & 0 deletions docs/src/quickstart.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Quickstart
==========

You can install metatensor-models with pip:

.. code-block:: bash

pip install git+https://github.com/lab-cosmo/metatensor-models.git
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ requires-python = ">=3.7"
readme = "README.md"
license = {text = "BSD-3-Clause"}
description = "" # TODO
authors = [
# TODO
]
authors = [{name = "metatensor-models developers"}]

dependencies = [
"ase",
Expand Down
11 changes: 9 additions & 2 deletions src/metatensor_models/utils/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ class Dataset(torch.utils.data.Dataset):
def __init__(
self, structures: List[rascaline.torch.System], targets: Dict[str, TensorMap]
):
"""Creates a dataset from a list of `rascaline.torch.System`s and
a list of dictionaries of `TensorMap`s."""
"""
Creates a dataset from a list of `rascaline.torch.System` objects
and a dictionary of targets where the keys are strings and the
values are `TensorMap` objects.
"""

for tensor_map in targets.values():
n_structures = (
Expand All @@ -35,8 +38,10 @@ def __len__(self):
def __getitem__(self, index):
"""
Generates one sample of data.

Args:
index: The index of the item in the dataset.

Returns:
A tuple containing the structure and targets for the given index.
"""
Expand All @@ -59,9 +64,11 @@ def __getitem__(self, index):
def collate_fn(batch):
"""
Creates a batch from a list of samples.

Args:
batch: A list of samples, where each sample is a tuple containing a
structure and targets.

Returns:
A tuple containing the structures and targets for the batch.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .ase import read_ase

STRUCTURE_READERS = {".xyz": read_ase}
""":py:class:`dict`: dictionary mapping file suffixes to a structure reader"""
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .ase import read_ase

TARGET_READERS = {".xyz": read_ase}
""":py:class:`dict`: dictionary mapping file suffixes to a target structure reader"""
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ commands =
twine check dist/*.tar.gz dist/*.whl
check-manifest {toxinidir}

[testenv:docs]
# this environement builds the documentation with sphinx
deps =
-r docs/requirements.txt

commands =
sphinx-build {posargs:-E} -W -b html docs/src docs/build/html

[flake8]
# longer lines for compatibility with other linters
max_line_length = 88
Expand Down