diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 93b65adfe..e5c9f3d4c 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -60,7 +60,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install ford + pip install --group docs - name: Build docs with FORD run: ford FTorch.md @@ -109,7 +109,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install ford + pip install --group docs - name: Build docs with FORD run: ford FTorch.md diff --git a/.github/workflows/preprocessing.yml b/.github/workflows/preprocessing.yml index ced37c29b..8a15e46f0 100644 --- a/.github/workflows/preprocessing.yml +++ b/.github/workflows/preprocessing.yml @@ -45,7 +45,7 @@ jobs: python-version: '3.13' # Use 3.13 as no PyTorch wheels for 3.14 yet. - name: Install fypp, the Fortran pre-processor - run: pip install fypp + run: pip install --group preproc - name: Check ftorch_tensor.fypp matches ftorch_tensor.f90 run: | diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 92564a2f2..a23a56108 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -65,7 +65,7 @@ jobs: python -m pip install --upgrade pip python -m venv ../ftorch_venv . ../ftorch_venv/bin/activate - pip install .[dev] --extra-index-url https://download.pytorch.org/whl/cpu + pip install . --extra-index-url https://download.pytorch.org/whl/cpu --group lint # Run CMake build to get compile commands for clang - name: FTorch CMake diff --git a/.github/workflows/test_suite_macos_cpu_clang.yml b/.github/workflows/test_suite_macos_cpu_clang.yml index 9ebd75b0f..edd1324e3 100644 --- a/.github/workflows/test_suite_macos_cpu_clang.yml +++ b/.github/workflows/test_suite_macos_cpu_clang.yml @@ -81,7 +81,7 @@ jobs: python -m pip install --upgrade pip python -m venv ftorch . ftorch/bin/activate - pip install . --extra-index-url https://download.pytorch.org/whl/cpu + pip install . --extra-index-url https://download.pytorch.org/whl/cpu --group test - name: Install gfortran and OpenMPI # Install from source to avoid compiler mismatch between gfortran versions diff --git a/.github/workflows/test_suite_ubuntu_cpu_gnu.yml b/.github/workflows/test_suite_ubuntu_cpu_gnu.yml index 3be107fa9..896ce9797 100644 --- a/.github/workflows/test_suite_ubuntu_cpu_gnu.yml +++ b/.github/workflows/test_suite_ubuntu_cpu_gnu.yml @@ -122,7 +122,7 @@ jobs: python -m pip install --upgrade pip python -m venv ftorch . ftorch/bin/activate - pip install . --extra-index-url https://download.pytorch.org/whl/cpu + pip install . --extra-index-url https://download.pytorch.org/whl/cpu --group test - name: Install OpenMPI run: | diff --git a/.github/workflows/test_suite_ubuntu_cpu_intel.yml b/.github/workflows/test_suite_ubuntu_cpu_intel.yml index da3f81eb5..e4b6d33a3 100644 --- a/.github/workflows/test_suite_ubuntu_cpu_intel.yml +++ b/.github/workflows/test_suite_ubuntu_cpu_intel.yml @@ -66,7 +66,7 @@ jobs: python -m pip install --upgrade pip python -m venv ftorch . ftorch/bin/activate - pip install . --extra-index-url https://download.pytorch.org/whl/cpu + pip install . --extra-index-url https://download.pytorch.org/whl/cpu --group test - name: Install Intel tools uses: rscohn2/setup-oneapi@a5ae4e7697b9cd5dc8a616f94c1e56b87140999d diff --git a/.github/workflows/test_suite_ubuntu_cuda_gnu.yml b/.github/workflows/test_suite_ubuntu_cuda_gnu.yml index 2be98f25c..35d66efbc 100644 --- a/.github/workflows/test_suite_ubuntu_cuda_gnu.yml +++ b/.github/workflows/test_suite_ubuntu_cuda_gnu.yml @@ -74,7 +74,7 @@ jobs: . ftorch/bin/activate # CUDA v12.9 chosen as latest supported by PyTorch # Check this is <= what GPU-runner has installed (backwards compatible) - pip install . --extra-index-url https://download.pytorch.org/whl/cu129 + pip install . --extra-index-url https://download.pytorch.org/whl/cu129 --group test - name: Install cmake and NVIDIA dev toolkit run: | diff --git a/.github/workflows/test_suite_windows_cpu_intel.yml b/.github/workflows/test_suite_windows_cpu_intel.yml index 78c328371..9f0a91ab4 100644 --- a/.github/workflows/test_suite_windows_cpu_intel.yml +++ b/.github/workflows/test_suite_windows_cpu_intel.yml @@ -65,7 +65,7 @@ jobs: pip install --upgrade pip python -m venv ftorch call ftorch\Scripts\activate - pip install . + pip install . --group test - name: Build FTorch shell: cmd diff --git a/codespace/build_FTorch.sh b/codespace/build_FTorch.sh index f480c1ee0..b77892f55 100755 --- a/codespace/build_FTorch.sh +++ b/codespace/build_FTorch.sh @@ -4,12 +4,13 @@ # It should be run from the top of the repository i.e. `FTorch/` # --- -# Set up a virtual environment and install neccessary Python dependencies +# Set up a virtual environment and install necessary Python dependencies # We will specify the cpu-only version of PyTorch to match the codespace hardware python3 -m venv venv # shellcheck source=/dev/null source venv/bin/activate -pip install . --extra-index-url https://download.pytorch.org/whl/cpu +# shellcheck disable=SC2102 +pip install .[examples] --extra-index-url https://download.pytorch.org/whl/cpu # Extract the location of the installed packages in the venv # This is typically `FTorch/build/venv/lib/python3.xx/site-packages/` diff --git a/examples/01_Tensor/README.md b/examples/01_Tensor/README.md index 8af27267d..397b2e230 100644 --- a/examples/01_Tensor/README.md +++ b/examples/01_Tensor/README.md @@ -24,7 +24,9 @@ To run this example requires: ## Running To run this example, first install FTorch as described in the main -documentation. +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. To compile the Fortran code, using the included `CMakeLists.txt`, execute the following code: diff --git a/examples/02_SimpleNet/README.md b/examples/02_SimpleNet/README.md index 872679204..693ee3a86 100644 --- a/examples/02_SimpleNet/README.md +++ b/examples/02_SimpleNet/README.md @@ -30,13 +30,10 @@ To run this example requires: ## Running -To run this example install FTorch as described in the main documentation. -Then from this directory create a virtual environment and install the necessary Python -modules: -``` -python3 -m venv venv -source venv/bin/activate -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. You can check that everything is working by running `simplenet.py`: ``` diff --git a/examples/03_ResNet/README.md b/examples/03_ResNet/README.md index 6faa84803..a69a9ae56 100644 --- a/examples/03_ResNet/README.md +++ b/examples/03_ResNet/README.md @@ -26,13 +26,10 @@ To run this example requires: ## Running -To run this example install FTorch as described in the main documentation. -Then from this directory create a virtual environment an install the neccessary Python -modules: -``` -python3 -m venv venv -source venv/bin/activate -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. You can check that everything is working by running `resnet18.py`: diff --git a/examples/04_Batching/README.md b/examples/04_Batching/README.md index 8f138855d..afbea12d2 100644 --- a/examples/04_Batching/README.md +++ b/examples/04_Batching/README.md @@ -130,11 +130,10 @@ tensor([[[ 0., 1., 2., 3., 4.], ## Running -To run this example, first install FTorch as described in the main documentation. Then, from this directory, create a virtual environment and install the necessary Python modules: -``` -python3 -m venv venv -source venv/bin/activate -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. A Python file `batchingnet.py` is provided that defines the simple PyTorch 'net'. Running this file as a script will write the model out in PyTorch's diff --git a/examples/05_MultiIO/README.md b/examples/05_MultiIO/README.md index 9f7ca7aa7..061c88259 100644 --- a/examples/05_MultiIO/README.md +++ b/examples/05_MultiIO/README.md @@ -34,13 +34,10 @@ To run this example requires: ## Running -To run this example install FTorch as described in the main documentation. Then -from this directory create a virtual environment and install the necessary -Python modules: -``` -python3 -m venv venv -source venv/bin/activate -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. You can check everything is working by running `multiionet.py`: ``` diff --git a/examples/06_Looping/README.md b/examples/06_Looping/README.md index 6be8bd79a..97855d61c 100644 --- a/examples/06_Looping/README.md +++ b/examples/06_Looping/README.md @@ -66,13 +66,10 @@ To run this example requires: ## Running -To run this example install FTorch as described in the main documentation. Then -from this directory create a virtual environment and install the necessary -Python modules: -``` -python3 -m venv venv -source venv/bin/activate -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. You can check everything is working by running `simplenet.py`: ``` diff --git a/examples/07_MultiGPU/README.md b/examples/07_MultiGPU/README.md index b22db4dac..9d965f8d3 100644 --- a/examples/07_MultiGPU/README.md +++ b/examples/07_MultiGPU/README.md @@ -26,12 +26,10 @@ To run this example requires: ## Running -To run this example install FTorch as described in the main documentation. Then from -this directory create a virtual environment and install the necessary Python modules: -``` -python3 -m venv venv -source venv/bin/activate -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. You can check that everything is working by running `simplenet.py`: ``` diff --git a/examples/08_MPI/CMakeLists.txt b/examples/08_MPI/CMakeLists.txt index ef07098ee..9fa05936f 100644 --- a/examples/08_MPI/CMakeLists.txt +++ b/examples/08_MPI/CMakeLists.txt @@ -28,9 +28,6 @@ if(NOT DEFINED ENV{VIRTUAL_ENV} AND NOT DEFINED ENV{CONDA_PREFIX}) message(FATAL_ERROR "Please activate your virtualenv or conda environment") endif() -# Install Python dependencies -execute_process(COMMAND ${Python_EXECUTABLE} -m pip install mpi4py) - # Fortran example add_executable(mpi_infer_fortran mpi_infer_fortran.f90) target_link_libraries(mpi_infer_fortran PRIVATE FTorch::ftorch) diff --git a/examples/08_MPI/README.md b/examples/08_MPI/README.md index 9e763606a..f225fc831 100644 --- a/examples/08_MPI/README.md +++ b/examples/08_MPI/README.md @@ -26,14 +26,10 @@ To run this example requires: ## Running -To run this example install FTorch as described in the main documentation. Then -from this directory create a virtual environment and install the necessary -Python modules: -``` -python3 -m venv venv -source venv/bin/activate -pip install mpi4py -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. You can check the network is set up correctly by running `simplenet.py`: ``` diff --git a/examples/09_Autograd/README.md b/examples/09_Autograd/README.md index 0049b8f93..a454abd39 100644 --- a/examples/09_Autograd/README.md +++ b/examples/09_Autograd/README.md @@ -30,13 +30,10 @@ To run this example requires: ## Running -To run this example install FTorch as described in the main documentation. -Then from this directory create a virtual environment and install the necessary -Python modules: -``` -python3 -m venv venv -source venv/bin/activate -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. ### Tensor manipulation demo diff --git a/examples/10_Optimizers/README.md b/examples/10_Optimizers/README.md index d2e331d76..d9132a271 100644 --- a/examples/10_Optimizers/README.md +++ b/examples/10_Optimizers/README.md @@ -25,14 +25,10 @@ To run this example requires: ## Running -To run this example install FTorch as described in the main documentation. -Then from this directory create a virtual environment and install the necessary -Python modules: -``` -python3 -m venv venv -source venv/bin/activate -pip install -r requirements.txt -``` +To run this example, first install FTorch as described in the main +documentation, making use of the `examples` optional dependencies. See the +[user guide section](https://cambridge-iccs.github.io/FTorch/page/installation/general.html#python-dependencies) +on Python dependencies for details. Run the Python version of the demo with ``` diff --git a/pages/developer/developer.md b/pages/developer/developer.md index a463d6009..8df102800 100644 --- a/pages/developer/developer.md +++ b/pages/developer/developer.md @@ -23,11 +23,14 @@ expected for submissions. ### Developer requirements Development tools for [pre-processing](#fortran-source-and-fypp), -[code styling](#code-style) etc. are pip-installable using the +[code styling](#code-style) etc. are pip-installable using the `dev` dependency +group in the [pyproject.toml file](https://github.com/Cambridge-ICCS/FTorch/blob/main/pyproject.toml): ```sh -pip install .[dev] +pip install . --group dev ``` +This pulls in the packages in the `docs`, `lint`, `preproc`, and `test` +dependency groups, which can also be used individually. In order to streamline the process of uploading we provide a pre-commit hook in [`.githooks/pre-commit`](https://github.com/Cambridge-ICCS/FTorch/blob/main/.githooks/pre-commit). diff --git a/pages/installation/general.md b/pages/installation/general.md index 2ce6f25ec..297fb0930 100644 --- a/pages/installation/general.md +++ b/pages/installation/general.md @@ -20,10 +20,10 @@ To install FTorch requires the following to be installed on the system: - [CMake](https://cmake.org/) >= 3.18 - Fortran (2008 standard compliant), C++ (must fully support C++17), and C compilers - [LibTorch](https://pytorch.org/cppdocs/installing.html)[^1] or [PyTorch](https://pytorch.org/) -- TorchVision and NumPy (required for examples) -For instructions on how to install PyTorch, TorchVision, and NumPy, see the -[Python dependencies](#python-dependencies) section below. +For instructions on how to install PyTorch and additional Python dependencies +for FTorch's examples, see the [Python dependencies](#python-dependencies) +section below. [^1]: _The minimal example provided downloads the CPU-only Linux Nightly binary. @@ -35,14 +35,20 @@ For instructions on how to install PyTorch, TorchVision, and NumPy, see the If LibTorch is not installed then FTorch requires PyTorch to be installed. FTorch's `pt2ts` utility script has PyTorch as a hard requirement, as well as the `ftorch_utils` Python module included in the FTorch repo. To install -PyTorch, `ftorch_utils`, and the additional dependencies (TorchVision and NumPy) -of FTorch's examples suite, run +PyTorch and `ftorch_utils`, run ```sh pip install . --extra-index-url ``` where `` is determined based on the [matrix](https://pytorch.org/get-started/locally/) on the PyTorch website. +We recommend also installing the additional dependencies for FTorch's examples +(TorchVision, matplotlib, NumPy, and mpi4py) in the same command. This can be +achieved by including the `examples` optional dependencies, as follows: +```sh +pip install .[examples] --extra-index-url +``` + If you don't want to install `ftorch_utils` then you can install FTorch's `torch` and `torchvision` dependencies using ```sh @@ -51,10 +57,10 @@ pip install torch torchvision --index-url @note We recommend installing `torch` and `torchvision` in the same command such as -would be done in the second command above. Doing so ensures that they are -configured in the same way. If you have installed the `ftorch_utils` module as -in the first command above then there is no need to worry about this because -they are both included as dependencies. +would be done in the third command above. Doing so ensures that they are +configured in the same way. If you have installed the `ftorch_utils` module with +the `examples` optional dependencies as in the second command above then there +is no need to worry about this because they are both included as dependencies. @endnote #### Additional dependencies of the test suite diff --git a/pages/installation/gpu.md b/pages/installation/gpu.md index e3facd679..c0342bc8c 100644 --- a/pages/installation/gpu.md +++ b/pages/installation/gpu.md @@ -28,9 +28,10 @@ HIP with a LibTorch binary. #### Installation using pip -To install `ftorch_utils` and its dependencies with GPU support, use +To install `ftorch_utils`, its dependencies, and the additional dependencies +for the examples with GPU support, use ```sh -pip install . --extra-index-url +pip install .[examples] --extra-index-url ``` or to install `torch` and `torchvision` directly use ```sh diff --git a/pages/installation/systems.md b/pages/installation/systems.md index e1779fb99..8ca832b8a 100644 --- a/pages/installation/systems.md +++ b/pages/installation/systems.md @@ -72,7 +72,7 @@ rem Activate the virtual environment call .ftorch\Scripts\activate rem Install dependencies (--extra-index-url not required on Windows) -pip install . +pip install .[examples] rem Enable output ECHO ON diff --git a/pyproject.toml b/pyproject.toml index fbca2cd92..a9131aefd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,26 +28,37 @@ keywords = [ ] classifiers = [ "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", "Programming Language :: Fortran", "Programming Language :: Python", + "Topic :: Scientific/Engineering", ] -dependencies = [ - "matplotlib", - "numpy", - "torch", - "torchvision", -] +dependencies = ["numpy", "torch"] +optional-dependencies = {examples = ["matplotlib", "mpi4py", "torchvision"]} -[project.optional-dependencies] -dev = [ +[dependency-groups] +docs = ["ford>=7.0.13"] +lint = [ "clang-format==19.1.3", "clang-tidy==19.1.0", "cmakelang", - "ford>=7.0.13", "fortitude-lint==0.7.0", - "fypp==3.2", "ruff==0.7.3", ] +preproc = ["fypp==3.2"] +test = [ + "matplotlib", + "mpi4py", + "pytest", + "torchvision", +] +dev = [ + {include-group = "docs"}, + {include-group = "lint"}, + {include-group = "preproc"}, + {include-group = "test"}, +] [project.scripts] pt2ts = "ftorch_utils.pt2ts:main_cli"