From d16b44cc4bae66d8ac4654b32f00f54f6277fb3e Mon Sep 17 00:00:00 2001 From: Samuel Burbulla Date: Tue, 21 Nov 2023 08:51:55 +0200 Subject: [PATCH] Setup automatic generation of docs. --- docs/about.md | 5 +++++ docs/documentation.md | 4 ---- docs/index.md | 14 +++++++++++++- docs/installation.md | 8 ++++++++ docs/requirements.txt | 5 ++++- mkdocs.yml | 21 +++++++++++++++++++-- scripts/gen_ref_pages.py | 34 ++++++++++++++++++++++++++++++++++ src/continuity/__init__.py | 1 + src/continuity/data/dataset.py | 11 +++++++++-- 9 files changed, 93 insertions(+), 10 deletions(-) delete mode 100644 docs/documentation.md create mode 100644 scripts/gen_ref_pages.py diff --git a/docs/about.md b/docs/about.md index 7885686c..40eebb7f 100644 --- a/docs/about.md +++ b/docs/about.md @@ -1,2 +1,7 @@ About ========== + +**Authors**: +Samuel Burbulla (2023) + +AppliedAI Institute for Europe gGmbH diff --git a/docs/documentation.md b/docs/documentation.md deleted file mode 100644 index 773fec4f..00000000 --- a/docs/documentation.md +++ /dev/null @@ -1,4 +0,0 @@ -Modules -======= - -::: continuity.data.dataset.DataSet diff --git a/docs/index.md b/docs/index.md index 1233e9e2..faf2f80b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,4 +1,16 @@ Continuity ========== -Mapping continuous functions with neural networks. +**Continuity** is a Python package for *mapping continuous functions with neural +networks*. + +This package is based on PyTorch and provides a general interface for machine +learning on continuous functions. It implements various neural network +architectures, including DeepONets or neural operators, physics-informed loss +functions to train the networks based on PDEs, and a variety of benchmarks. + +### Installation +See [Installation](installation.md) for details on how to install **Continuity**. + +### Reference +The module documentation can be found in [Reference](/reference/continuity). diff --git a/docs/installation.md b/docs/installation.md index 87884f72..9a4caff3 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,6 +1,14 @@ Installation ============ +It is recommended to install **Continuity** in a virtual environment. +``` +python3 -m venv venv +source venv/bin/activate +``` + +For a editable installation, clone the repository and install the +package using pip. ``` git clone https://github.com/aai-institute/Continuity.git cd Continuity diff --git a/docs/requirements.txt b/docs/requirements.txt index a839c60c..291fc480 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,5 @@ mkdocs -mkdocstrings +mkdocs-gen-files +mkdocs-literate-nav +mkdocs-material +mkdocstrings-python diff --git a/mkdocs.yml b/mkdocs.yml index 3d49ea1e..1f2a4bab 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -2,13 +2,30 @@ site_name: Continuity nav: - Home: index.md - Installation: installation.md - - Documentation: documentation.md - About: about.md + - Reference: reference/ + theme: name: readthedocs locale: "en" logo: img/logo.png + repo: fontawesome/brands/github + +repo_url: https://github.com/aai-institute/Continuity +edit_uri: edit/main/docs/ plugins: - search - - mkdocstrings + - autorefs + - mkdocstrings: + default_handler: python + handlers: + python: + options: + show_root_heading: true + show_source: false + - gen-files: + scripts: + - scripts/gen_ref_pages.py + - literate-nav: + nav_file: SUMMARY.md diff --git a/scripts/gen_ref_pages.py b/scripts/gen_ref_pages.py new file mode 100644 index 00000000..5562cb76 --- /dev/null +++ b/scripts/gen_ref_pages.py @@ -0,0 +1,34 @@ +"""Generate the code reference pages and navigation.""" + +from pathlib import Path + +import mkdocs_gen_files + +nav = mkdocs_gen_files.Nav() + +src = Path(__file__).parent.parent / "src" + +for path in sorted(src.rglob("*.py")): + module_path = path.relative_to(src).with_suffix("") + doc_path = path.relative_to(src).with_suffix(".md") + full_doc_path = Path("reference", doc_path) + + parts = tuple(module_path.parts) + + if parts[-1] == "__init__": + parts = parts[:-1] + doc_path = doc_path.with_name("index.md") + full_doc_path = full_doc_path.with_name("index.md") + elif parts[-1] == "__main__": + continue + + nav[parts] = doc_path.as_posix() + + with mkdocs_gen_files.open(full_doc_path, "w") as fd: + ident = ".".join(parts) + fd.write(f"::: {ident}") + + mkdocs_gen_files.set_edit_path(full_doc_path, path) + +with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file: + nav_file.writelines(nav.build_literate_nav()) diff --git a/src/continuity/__init__.py b/src/continuity/__init__.py index e69de29b..7586d288 100644 --- a/src/continuity/__init__.py +++ b/src/continuity/__init__.py @@ -0,0 +1 @@ +"""The Continuity package.""" diff --git a/src/continuity/data/dataset.py b/src/continuity/data/dataset.py index c6cd6c74..127a8cfe 100644 --- a/src/continuity/data/dataset.py +++ b/src/continuity/data/dataset.py @@ -1,3 +1,5 @@ +"""Provide base classes for data sets.""" + import math from numpy import ndarray from typing import List, Optional @@ -46,8 +48,13 @@ def __str__(self): s += ")" return s - def to_tensor(self): - """Convert observation to tensor""" + def to_tensor(self) -> torch.Tensor: + """Convert observation to tensor. + + Returns: + Tensor of shape (num_sensors, coordinate_dim + num_channels) + + """ u = torch.zeros((self.num_sensors, self.coordinate_dim + self.num_channels)) for i, sensor in enumerate(self.sensors): u[i] = torch.concat([tensor(sensor.x), tensor(sensor.u)])