From 55d6a4081ba65f2b6c9fe7b334fa30d8fae826c4 Mon Sep 17 00:00:00 2001 From: Samuel Burbulla Date: Tue, 21 Nov 2023 06:51:56 +0200 Subject: [PATCH 1/4] Install package to build docstrings. --- .github/workflows/docs.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 12bbe1a7..03880b70 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,10 +1,14 @@ -name: docs +name: Documentation + on: push: - branches: - - main + branches: [main] + pull_request: + branches: [main] + permissions: contents: write + jobs: deploy: runs-on: ubuntu-latest @@ -16,7 +20,7 @@ jobs: git config user.email 41898282+github-actions[bot]@users.noreply.github.com - uses: actions/setup-python@v4 with: - python-version: 3.x + python-version: 3.11 - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV - uses: actions/cache@v3 with: @@ -25,4 +29,5 @@ jobs: restore-keys: | mkdocs-material- - run: pip install mkdocs-material mkdocstrings + - run: pip install -e . - run: mkdocs gh-deploy --force From 4062c324c21d4b61795482623c43ad8931aef875 Mon Sep 17 00:00:00 2001 From: Samuel Burbulla Date: Tue, 21 Nov 2023 08:51:04 +0200 Subject: [PATCH 2/4] Clean up. --- .github/workflows/docs.yml | 2 +- docs/{README.md => README} | 0 src/continuity/model/neuraloperator.py | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename docs/{README.md => README} (100%) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 03880b70..b4330e8a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,6 +28,6 @@ jobs: path: .cache restore-keys: | mkdocs-material- - - run: pip install mkdocs-material mkdocstrings + - run: pip install -r requirements.txt - run: pip install -e . - run: mkdocs gh-deploy --force diff --git a/docs/README.md b/docs/README similarity index 100% rename from docs/README.md rename to docs/README diff --git a/src/continuity/model/neuraloperator.py b/src/continuity/model/neuraloperator.py index d7c0c8bc..cdc3b188 100644 --- a/src/continuity/model/neuraloperator.py +++ b/src/continuity/model/neuraloperator.py @@ -81,8 +81,8 @@ def __init__( coordinate_dim: Dimension of coordinate space num_channels: Number of channels depth: Number of hidden layers - width: Width of kernel network - depth: Depth of kernel network + kernel_width: Width of kernel network + kernel_depth: Depth of kernel network """ super().__init__() From d16b44cc4bae66d8ac4654b32f00f54f6277fb3e Mon Sep 17 00:00:00 2001 From: Samuel Burbulla Date: Tue, 21 Nov 2023 08:51:55 +0200 Subject: [PATCH 3/4] 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)]) From 918daac5a0a999ae3fce90e041502999ca568c8f Mon Sep 17 00:00:00 2001 From: Samuel Burbulla Date: Tue, 21 Nov 2023 08:53:36 +0200 Subject: [PATCH 4/4] Update docs/requirements.txt --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b4330e8a..9779cda5 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,6 +28,6 @@ jobs: path: .cache restore-keys: | mkdocs-material- - - run: pip install -r requirements.txt + - run: pip install -r docs/requirements.txt - run: pip install -e . - run: mkdocs gh-deploy --force