Skip to content

Commit

Permalink
added new examples to notebook 17
Browse files Browse the repository at this point in the history
  • Loading branch information
znicolaou committed May 30, 2023
2 parents 4d002ab + 8598638 commit 24fd728
Show file tree
Hide file tree
Showing 55 changed files with 1,432 additions and 1,082 deletions.
4 changes: 0 additions & 4 deletions setup.cfg → .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ import-order-style = smarkets
statistics = True
count = True
verbose = 1
# format = [%(code)s] %(text)s @ %(path)s:%(row)d:%(col)d

[codespell]
ignore-words-list = pres,nd
4 changes: 2 additions & 2 deletions .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ jobs:
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: docs/JOSS2/paper.md
- name: Upload
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: paper
# This is the output path where Pandoc will write the compiled
Expand Down
34 changes: 21 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
name: Tests

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
Linting:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.7
python-version: "3.9"
- name: Linting
run: |
pip install pre-commit
Expand All @@ -23,30 +29,32 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.7, 3.8]
python-version: ["3.8", "3.10"]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements-dev.txt
pip install sympy # needed for notebook 9, but not required for pysindy
pip install --upgrade pip
pip install .[dev,miosr,cvxpy]
- name: Build the docs
# Not exactly how RTD does it, but close.
run: |
sudo apt-get update -y
sudo apt-get install pandoc
pip install .[docs]
cd docs
python -m sphinx -T -E -W -b html -d _build/doctrees . _build/html
cd ..
- name: Test with pytest
run: |
pytest test --cov=pysindy --cov-report=xml
coverage run --source=pysindy -m pytest test && coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand All @@ -55,7 +63,7 @@ jobs:
pip install papermill
cd examples
papermill --report-mode 1_feature_overview.ipynb out.json
- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v1
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: 3.7
- name: Install dependencies
run: pip install wheel
python-version: "3.9"
- name: Install Build
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python setup.py sdist bdist_wheel
run: python -m build .
- name: Upload package
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@v1.8.5
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist
*.egg-info
commit-msg
todo
poetry.lock

# Environments
.env
Expand Down
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
rev: 5.0.4
hooks:
- id: flake8
args: ["--config=setup.cfg"]
args: ["--config=.flake8"]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
Expand All @@ -34,11 +34,12 @@ repos:
hooks:
- id: sphinx-lint
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.4
hooks:
- id: codespell
types_or: [python, rst, markdown]
args: ["-L hist"]
additional_dependencies: [tomli]
args: ["--toml", "pyproject.toml"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
Expand Down
7 changes: 5 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ sphinx:
configuration: docs/conf.py

python:
version: 3.7
version: 3.8
install:
- requirements: requirements-dev.txt
- method: pip
path: .
extra_requirements:
- docs
72 changes: 58 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The approximation problem to be solved can then be compactly written as
Each row of this matrix equation corresponds to one coordinate function of ``f(x)``.
SINDy employs sparse regression techniques to find a solution ``Xi`` with sparse column vectors.
For a more in-depth look at the mathematical foundations of SINDy, please see our `introduction to SINDy <https://pysindy.readthedocs.io/en/latest/examples/2_introduction_to_sindy.html>`__.
For a more in-depth look at the mathematical foundations of SINDy, please see our `introduction to SINDy <https://pysindy.readthedocs.io/en/latest/examples/2_introduction_to_sindy/example.html>`__.

Relation to PySINDy
^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -93,7 +93,7 @@ which prints the following
x' = -2.000 x
y' = 1.000 y
PySINDy provides numerous other features not shown here. We recommend the `feature overview <https://pysindy.readthedocs.io/en/latest/examples/1_feature_overview.html>`__ section of the documentation for a more exhaustive summary of additional features.
PySINDy provides numerous other features not shown here. We recommend the `feature overview <https://pysindy.readthedocs.io/en/latest/examples/1_feature_overview/example.html>`__ section of the documentation for a more exhaustive summary of additional features.

Installation
------------
Expand Down Expand Up @@ -121,23 +121,41 @@ Then, to install the package, run
pip install .
If you do not have pip you can instead use
If you do not have root access, you should add the ``--user`` option to the above lines.

Caveats
^^^^^^^

To run the unit tests, or example notebooks, you should install the dev-dependencies with:

.. code-block:: bash
python setup.py install
pip install pysindy[dev]
If you do not have root access, you should add the ``--user`` option to the above lines.
or if you are installing from a local copy

Caveats
^^^^^^^
If you would like to use the ``SINDy-PI`` optimizer, the ``Trapping SINDy`` optimizer (TrappingSR3), or the other SR3 optimizations with inequality constraints, you will also need to install the cvxpy package, e.g. with ``pip install cvxpy``.
.. code-block:: bash
pip install .[dev]
To build a local copy of the documentation, you should install the docs-dependencies with:

.. code-block:: bash
pip install pysindy[docs]
If you are looking to use convex optimization provided by `cvxpy <https://github.com/cvxpy/cvxpy>`__, then you have to install

.. code-block:: bash
pip install pysindy[cvxpy]
To run the unit tests, example notebooks, or build a local copy of the documentation, you should install the additional dependencies in ``requirements-dev.txt``
to utilize Mixed-Integer Optimized Sparse Regression (MIOSR) via `GurobiPy <https://pypi.org/project/gurobipy/>`__, you
require

.. code-block:: bash
pip install -r requirements-dev.txt
pip install pysindy[miosr]
Documentation
Expand Down Expand Up @@ -178,32 +196,58 @@ You can optimize your notebook for testing by checking ``__name__``. When our t
Contributing code
^^^^^^^^^^^^^^^^^
We welcome contributions to PySINDy. To contribute a new feature please submit a pull request. To get started we recommend installing the packages in ``requirements-dev.txt`` via
We welcome contributions to PySINDy. To contribute a new feature please submit a pull request. To get started we recommend installing an editable ``dev`` version from a local clone via

.. code-block:: bash
pip install -r requirements-dev.txt
pip install -e .[dev]
This will allow you to run unit tests and automatically format your code. To be accepted your code should conform to PEP8 and pass all unit tests. Code can be tested by invoking

.. code-block:: bash
pytest
We recommend using ``pre-commit`` to format your code. Once you have staged changes to commit
We recommend using ``pre-commit`` to format your code. The easiest approach is to install pre-commit via

.. code-block:: bash
pre-commit install
After which pre-commit will automatically check all future commits. Once you have staged changes to commit

.. code-block:: bash
git add path/to/changed/file.py
you can run the following to automatically reformat your staged code
Pre-commit will then automatically run all checks against your committed code. If you want to trigger this manually, you can run the following to automatically reformat your staged code

.. code-block:: bash
pre-commit
Note that you will then need to re-stage any changes ``pre-commit`` made to your code.

Building documentation requires the ``docs`` dependencies, which can be installed with either

.. code-block:: bash
pip install pysindy[docs]
or with

.. code-block:: bash
pip install .[docs]
for a local clone of the repository. Once installed, run

.. code-block:: bash
python -m sphinx -TEb html -d _build/doctrees -D language=en . ./build
Or check the build step in the most recent CI run or [RTD build](https://readthedocs.org/projects/pysindy/builds/).

There are a number of SINDy variants and advanced functionality that would be great to implement in future releases:

1. Bayesian SINDy, for instance that from Hirsh, Seth M., David A. Barajas-Solano, and J. Nathan Kutz. "Sparsifying Priors for Bayesian Uncertainty Quantification in Model Discovery." arXiv preprint arXiv:2107.02107 (2021).
Expand Down
146 changes: 73 additions & 73 deletions examples/10_PDEFIND_examples.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/11_SSR_FROLS_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Jupyter notebook written by Alan Kaptanoglu and Jared Callaham.\n",
"\n",
"An interactive version of this notebook is available on binder\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7?filepath=examples/11_SSR_FROLS_examples.ipynb)"
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7.3?filepath=examples/11_SSR_FROLS_examples.ipynb)"
]
},
{
Expand Down
733 changes: 432 additions & 301 deletions examples/12_weakform_SINDy_examples.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/13_ensembling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"source": [
"# Ensembling Feature Overview\n",
"Ensembling is a fancy name for sub-sampling the data and generating $n_\\text{models}$ from regressing onto each of these sub-samples. In practice this helps to robustify the regressions against outliers and other issues. We highly recommend checking out the following paper for understanding the usefulness of these methods against noisy data: \n",
"#### Fasel, Urban, et al. \"Ensemble-SINDy: Robust sparse model discovery in the low-data, high-noise limit, with active learning and control.\" arXiv preprint arXiv:2111.10992 (2021). https://arxiv.org/abs/2111.10992\n",
"#### Fasel, U., Kutz, J. N., Brunton, B. W., & Brunton, S. L. (2022). Ensemble-SINDy: Robust sparse model discovery in the low-data, high-noise limit, with active learning and control. Proceedings of the Royal Society A, 478(2260), 20210904. https://arxiv.org/abs/2111.10992\n",
"\n",
"This notebook provides an overview of the basic and advanced functionality of using ensemble methods in PySINDy. Ensembling robustifies the SINDy method. Written by Alan Kaptanoglu and Urban Fasel. \n",
"\n",
"An interactive version of this notebook is available on binder\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7?filepath=examples/13_ensembling.ipynb)\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7.3?filepath=examples/13_ensembling.ipynb)\n",
"\n",
"There are many variants of ensembling/subsampling strategies and post-processing methods. We will show the following useful variants below: <br> <br>\n",
"Ensembling: <br>\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/14_cavity_flow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"This Jupyter notebook example is written by Jared Callaham and demonstrates the use of SINDy to learn a model for the quasiperiodic dynamics in a shear-driven cavity at Re=7500, following [Callaham, Brunton, and Loiseau (2021)](https://arxiv.org/abs/2106.02409). It will focus on working through a relatively involved fluid dynamics example, rather than comparing optimizers, libraries, etc. This example also includes some other more advanced SINDy \"tricks\" like using dynamic mode decomposition to rotate the generalized coordinates and co-opting some of the SINDy infrastructure to perform nonlinear dimensionality reduction.\n",
"\n",
"An interactive version of this notebook is available on binder\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7?filepath=examples/14_cavity_flow.ipynb)\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7.3?filepath=examples/14_cavity_flow.ipynb)\n",
"\n",
"As in the cylinder wake example (see notebook 3), the reduced-order model appproximates the 2D time-varying velocity field $\\mathbf{u}(\\mathbf{x}, t)$ with the POD expansion\n",
"$$\n",
Expand Down
6 changes: 3 additions & 3 deletions examples/15_pysindy_lectures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"\n",
"This notebook is a summary of the PySINDy YouTube lectures found [here](https://www.youtube.com/playlist?list=PLN90bHJU-JLoOfEk0KyBs2qLTV7OkMZ25). \n",
"An interactive version of this notebook is available on binder\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7?filepath=examples/15_pysindy_lectures.ipynb)\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7.3?filepath=examples/15_pysindy_lectures.ipynb)\n",
"\n",
"These examples show how to use the SINDy method in practice, addressing the following practical questions:\n",
"1. How does one choose the thresholding parameter $\\lambda$?\n",
Expand Down Expand Up @@ -2229,7 +2229,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -2243,7 +2243,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.7.4"
},
"toc": {
"base_numbering": 1,
Expand Down
5 changes: 4 additions & 1 deletion examples/16_noise_robustness/16_benchmark_paper.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"\n",
"In addition, we investigate how Pareto-optimal models generated from sparse system identification methods depend on the dynamical properties of the equations, finding to leading order that the performance of these methods is independent of the dynamical properties of these equations, including the amount of chaos, scale separation, degree of nonlinearity, and, surprisingly, the syntactic complexity.\n",
" \n",
"We will use the dysts database, containingn over 100 chaotic systems. We will investigate a subset of the systems that are polynomially nonlinear, with highest polynomial degree <= 4. All of the following 70 systems are bounded and exhibit strange attractors."
"We will use the dysts database, containingn over 100 chaotic systems. We will investigate a subset of the systems that are polynomially nonlinear, with highest polynomial degree <= 4. All of the following 70 systems are bounded and exhibit strange attractors.\n",
"\n",
"An interactive version of this notebook is available on binder\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7.3?filepath=examples/16_noise_robustness/16_benchmark_paper.ipynb)"
]
},
{
Expand Down
5 changes: 4 additions & 1 deletion examples/16_noise_robustness/optimizer_comparison.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"## Full optimizer comparison\n",
"Notebook written by Lanyue Zhang and Alan Kaptanoglu\n",
"\n",
"This post-processing file takes the results from Pareto-optimal scans of the dysts database with different optimizers and varying amounts of noise, as in the example Jupyter notebook 16_benchmark_paper.ipynb. The primary goal of this notebook is to fully reproduce the results shown in our new system identification benchmark paper."
"This post-processing file takes the results from Pareto-optimal scans of the dysts database with different optimizers and varying amounts of noise, as in the example Jupyter notebook 16_benchmark_paper.ipynb. The primary goal of this notebook is to fully reproduce the results shown in our new system identification benchmark paper.\n",
"\n",
"An interactive version of this notebook is available on binder\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dynamicslab/pysindy/v1.7.3?filepath=examples/16_noise_robustness/optimizer_comparison.ipynb)"
]
},
{
Expand Down
2 changes: 2 additions & 0 deletions examples/17_parameterized_pattern_formation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pdf
data

0 comments on commit 24fd728

Please sign in to comment.