diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index e0d087d..6dd643b 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,9 +1,12 @@ name: flake8 on: + push: + branches: + - main pull_request: paths: - - '**.py' + - "**.py" jobs: flake8-lint: @@ -20,4 +23,3 @@ jobs: - name: flake8-lint uses: py-actions/flake8@v2 - diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 225983a..9c4026b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,8 +22,7 @@ jobs: run: | python -m venv --upgrade-deps .venv source .venv/bin/activate - pip install -r requirements.txt - pip install -r requirements-dev.txt + pip install .[all] - name: Run Test run: | diff --git a/README.md b/README.md index b89f028..56c2b86 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,31 @@ # Sparse Coding -Reference sparse coding implementations for efficient learning and inference implemented in PyTorch with GPU support. -## Dictionary Learning +Reference sparse coding implementations for efficient learning and inference implemented in PyTorch with GPU support. + +## Features + +### Dictionary Learning + * Repo currently includes classic patch-wise sparse coding dictionary learning. -## Implemented Inference Methods +### Implemented Inference Methods + * Locally Competative Algorithm (LCA) * Gradient Descent with Euler's method on Laplace Prior (Vanilla) * Laplacian Scale Mixture (LSM) * Iterative Shrinkage-threshold Algorithm (ISTA) * Generic PyTorch minimization of arbitrary loss function (PyTorchOptimizer) -# Setup +## Setup + 1. Clone the repo. 2. Navigate to the directory containing the repo directory. -3. Run `pip install -e sparsecoding` -4. Navigate into the repo and install the requirements using `pip install -r requirements.txt` -5. Install the natural images dataset from this link: https://rctn.org/bruno/sparsenet/IMAGES.mat -6. Try running the demo notebook: `examples/sparse_coding.ipynb` +3. Run `pip install -e ".[all]"` +4. Install the natural images dataset from this link: https://rctn.org/bruno/sparsenet/IMAGES.mat +5. Try running the demo notebook: `examples/sparse_coding.ipynb` Note: If you are using a Jupyter notebook and change a source file, you can either: 1) restart the Jupyter kernel, or 2) follow instructions [here](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html#autoreload). -# Contributing +## Contributing + See the [contributing](docs/contributing.md) document! diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c6dabd8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,90 @@ +[project] +name = "sparsecoding" +version = "0.0.1" +# Authors are the current, primary stewards of the repo +# contributors can be found on github +authors = [ + { name = "Alex Belsten", email = "belsten@berkeley.edu" }, + { name = "Christian Shewmake", email = "cshewmake2@gmail.com" }, +] +description = "Pytorch infrasctructure for sparse coding." +readme = "README.md" +requires-python = ">=3.8" +# Trove classifiers: https://pypi.org/pypi?%3Aaction=list_classifiers +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Development Status :: 3 - Alpha", + "Natural Language :: English", +] + +dependencies = [ + "matplotlib", + "numpy", + "scipy", + "torch", + "torchvision", +] + + +[project.optional-dependencies] +dev = [ + "black==24.*", + "coverage", + "ipykernel", + "jupytext", + "nbconvert", + "pylint>=3.3.0", + "pyright", + "pytest", +] + +tutorials = [ + "jupyter", + "matplotlib", + "tqdm", + "scipy", +] + +all = [ + "sparsecoding[dev,tutorials]", +] + +[project.urls] +"Homepage" = "sparsecoding.readthedocs.io" +"Bug Tracker" = "https://github.com/rctn/sparsecoding/issues" + +[build-system] +requires = ["flit_core>=3.2"] +build-backend = "flit_core.buildapi" + +[tool.pytest.ini_options] +minversion = "6.0" +addopts = ["--tb=short"] +norecursedirs = ".git examples" +python_files = "*_test.py test_*.py" +log_cli = true +log_cli_level = "INFO" +log_cli_format = "\n%(asctime)s: %(levelname)s: %(filename)s:%(lineno)s::%(module)s::%(funcName)s:\n%(message)s" +log_cli_date_format = "%y-%m-%d %H:%M:%S" + +[tool.pylint.format] +max-line-length = "120" + +[tool.black] +line-length = 120 +extend-exclude = "\\.ipynb" + +[tool.pylint] +exclude = [".venv", ".vscode", "docs"] + +[tool.pylance] +exclude = [".venv", ".vscode", "docs"] + +[tool.pyright] +exclude = [".venv", ".vscode", "docs"] + +[tool.isort] +line_length = 120 +profile = "black" diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 4191a3f..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,3 +0,0 @@ -pylint -pytest -pyright \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 7c6c9f2..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -scipy -numpy -matplotlib -torch -torchvision diff --git a/setup.py b/setup.py deleted file mode 100644 index efde059..0000000 --- a/setup.py +++ /dev/null @@ -1,21 +0,0 @@ -import setuptools - -with open("README.md", "r", encoding="utf-8") as fh: - long_description = fh.read() - -setuptools.setup( - name="sparsecoding", - version="0.0.1", - author="Alex Belsten, Christian Shewmake", - author_email="cshewmake2@gmail.com", - description="Pytorch infrastructure for sparse coding.", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/rctn/sparsecoding", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", - ], - python_requires='>=3.8', -) diff --git a/tutorials/vanilla/README.md b/tutorials/vanilla/README.md new file mode 100644 index 0000000..8638b15 --- /dev/null +++ b/tutorials/vanilla/README.md @@ -0,0 +1,7 @@ +# Install required dependencies + +Install the tutorials dependencies by navigating to the root repo folder and running + +```sh +pip install .[tutorials] +``` diff --git a/tutorials/vanilla/requirements.txt b/tutorials/vanilla/requirements.txt deleted file mode 100644 index 183bcdc..0000000 --- a/tutorials/vanilla/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -jupyter -matplotlib -numpy -torch -torchvision -tqdm -scipy \ No newline at end of file