diff --git a/README.md b/README.md index f0dee80..bf4c9b0 100644 --- a/README.md +++ b/README.md @@ -3,139 +3,24 @@ A [simple] [general-purpose] Python template 🐍🚀🎉🦕 -I used this template for [fesenjoon](https://pypi.org/project/fesenjoon/) and [medviz](https://pypi.org/project/medviz/). - -## How to use - -- Linux and Mac - Use GCC Makefile - -- Install Makefile - - https://community.chocolatey.org/packages/make - - http://www.cygwin.com/ - -### Bootstrap - -To use env in another directory: - -``` bash - make env -``` - -There is no need to active virtual environment when the `PY` command is used from Makefile. - -To use env here (local directory) - -``` bash - make env-local -``` - -``` bash - source env_platform_ver/bin/activate -``` - -Set a name for the package: - -```bash - make init newName -``` - -Check Python and pip version - -``` bash - make -``` - -Update pip and build tools - -``` bash - make check -``` - -Install the requirements - -``` bash - make pireq -``` - -### Install a package - -``` bash - make piu numpy matplotlib scipy -``` - -## Features - -- Linter: Pylint -- Formatter: Black -- CI: GitHub Actions - -### ToDo - -- [x] Formatter: Black + isort -- [x] Type checker: MyPy -- [x] Linter: Ruff -- [x] Linter: Pylint -- [x] GitHub Actions -- [x] Git Hooks -- [x] PyPI Publish -- [x] Flit -- [x] Poetry -- [x] Ruff - -### Git - -Git hooks are available in ./scripts/.githooks - -``` bash - chmod +x ./scripts/.githooks/script - - git config core.hooksPath ./scripts/.githooks - -``` - - -## Publish to PyPI - - -1. To build a package, run: -``` bash - make pkg-build -``` - -2. To check the build, run: -``` bash - make pkg-check -``` - -3. To install the package locally, run: -``` bash - make pkg-install -``` - -4. Create `.pypirc` file in the root directory of the project. It should look like this: - -``` bash - [distutils] - index-servers = - pypi - testpypi - - [pypi] - repository: https://upload.pypi.org/legacy/ - username: - password: - - [testpypi] - repository: https://test.pypi.org/legacy/ - username: - password: -``` - -4. To publish to PyPI, run: - -``` bash - make pkg-publish -``` +## Run on HPC + +1. Clone the repository + ```bash + git clone git@github.com:mohsenhariri/template-python.git + chmod -R u=rwx,go= template-python + cd template-python + ``` + +2. Run the initialization script + ```bash + chmod +x hpc.init + source hpc.init + ``` + +3. Modify or add commands to `hpc.make` file + +4. Run the `hpc.make` file + ```bash + make newCommand + ``` \ No newline at end of file diff --git a/hpc.init b/hpc.init index 9b92c3a..244ece0 100644 --- a/hpc.init +++ b/hpc.init @@ -5,8 +5,9 @@ echo "Job ID: $SLURM_JOB_ID" module purge -module load Python/3.11.3-GCCcore-12.3.0 -module load CUDA/12.0.0 + +module load Python/3.10.4-GCCcore-11.3.0 +module load cuDNN/8.4.1.50-CUDA-11.7.0 DIRNAME="$(basename "$(pwd)")" @@ -17,7 +18,12 @@ make switch-env hpc make env-local make test make check -make pia +# install all dependencies available in requirements.txt +make pia # Run Makefile targets -make run \ No newline at end of file +make run + +# install pytorch +# make piu install torch torchvision --index-url https://download.pytorch.org/whl/cu117 +make gpu-test diff --git a/hpc.make b/hpc.make index 0575f69..61b2a83 100644 --- a/hpc.make +++ b/hpc.make @@ -1,2 +1,5 @@ run: - $(PY) $(SRC)/app.py \ No newline at end of file + $(PY) $(SRC)/app.py + +gpu-test: + $(PY) $(SRC)/gpu.py \ No newline at end of file diff --git a/pkg/app.py b/pkg/app.py index fd19bc7..742dacb 100644 --- a/pkg/app.py +++ b/pkg/app.py @@ -1,4 +1,4 @@ """ DocString """ -print("main") +print("Running on HPC") diff --git a/pkg/args.py b/pkg/args.py deleted file mode 100644 index 2cd1d83..0000000 --- a/pkg/args.py +++ /dev/null @@ -1,8 +0,0 @@ -import argparse - -parser = argparse.ArgumentParser(description="URL of file or folder") - -parser.add_argument("-id", type=str, default=None, metavar="N", help="URL") -id = parser.parse_args().id - -print() diff --git a/pkg/gpu.py b/pkg/gpu.py new file mode 100644 index 0000000..f350a3a --- /dev/null +++ b/pkg/gpu.py @@ -0,0 +1,6 @@ +import torch + +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") + +print(f"Using {device} device") +print(f"Using {torch.cuda.device_count()} GPUs!") diff --git a/pkg/sample.py b/pkg/sample.py deleted file mode 100644 index 644ebcc..0000000 --- a/pkg/sample.py +++ /dev/null @@ -1,12 +0,0 @@ -""" Short description of this Python module. -Longer description of this module. - -""" -# Built-in -# import os -# import sys - -# Third Party -# import numpy as np - -# Owned diff --git a/pkg/test_app.py b/pkg/test_app.py deleted file mode 100644 index f2d44b3..0000000 --- a/pkg/test_app.py +++ /dev/null @@ -1,27 +0,0 @@ -import unittest - - -class TestCalc(unittest.TestCase): - @classmethod - def setUpClass(cls) -> None: - # Database connection - return super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - return super().tearDownClass() - - def setUp(self) -> None: - print("start") - return super().setUp() - - def tearDown(self) -> None: - print("finish") - return super().tearDown() - - def test_app(self): - pass - - -if __name__ == "__main__": - unittest.main() diff --git a/pkg/utility/custom_type.py b/pkg/utility/custom_type.py deleted file mode 100644 index 14f6f05..0000000 --- a/pkg/utility/custom_type.py +++ /dev/null @@ -1,4 +0,0 @@ -from pathlib import Path -from typing import Iterable, Union - -PathType = Union[str, Path, Iterable[str], Iterable[Path]] diff --git a/pkg/utility/reader.py b/pkg/utility/reader.py deleted file mode 100644 index 9d82048..0000000 --- a/pkg/utility/reader.py +++ /dev/null @@ -1,33 +0,0 @@ -from os import getenv -from pathlib import Path - -from .custom_type import PathType - - -def path_in(p: str, global_path=True) -> PathType: - if p[0] == "/" or not global_path: # Check whether p is absolute path. - path_input = p - else: - root_in = getenv("ROOT_IN") or "." - path_input = rf"{root_in}/{p}" - - path: PathType = Path(path_input) - if not path.exists(): - raise Exception(f"{p} doesn't exist on the earth.") - - return path - - -def path_out(p: str, global_path=True) -> PathType: - if p[0] == "/" or not global_path: # Check whether p is absolute path - path_output = p - else: - root_out = getenv("ROOT_OUT") or "." - path_output = rf"{root_out}/{p}" - - path: PathType = Path(path_output) - if not path.exists(): - print("The output path doesn't exist but no worries I'm making it.") - path.mkdir(parents=True) - - return path