From 59a561deda8f3b0eb01bc6f9d6f4a2344ba541b8 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 26 Sep 2023 20:15:12 +0300 Subject: [PATCH 1/8] Drop support for Pythons older than 3.8 --- .github/workflows/run_tests.yml | 2 +- README.md | 2 +- setup.py | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index e63c1e7..5c57e4f 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -54,7 +54,7 @@ jobs: needs: [ check_version ] strategy: matrix: - python-version: [ 3.6, 3.8 ] + python-version: [ 3.8 ] os: [ ubuntu-latest, macOS-latest, windows-latest ] fail-fast: false runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 767a95f..84f9827 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This library provides [stochastic differential equation (SDE)](https://en.wikipe pip install torchsde ``` -**Requirements:** Python >=3.6 and PyTorch >=1.6.0. +**Requirements:** Python >=3.8 and PyTorch >=1.6.0. ## Documentation Available [here](./DOCUMENTATION.md). diff --git a/setup.py b/setup.py index 23e873a..5bd16bc 100644 --- a/setup.py +++ b/setup.py @@ -41,14 +41,12 @@ packages=setuptools.find_packages(exclude=['benchmarks', 'diagnostics', 'examples', 'tests']), install_requires=[ "boltons>=20.2.1", - "numpy==1.19;python_version<'3.7'", - "numpy>=1.19;python_version>='3.7'", - "scipy==1.5;python_version<'3.7'", - "scipy>=1.5;python_version>='3.7'", + "numpy>=1.19", + "scipy>=1.5", "torch>=1.6.0", "trampoline>=0.1.2", ], - python_requires='~=3.6', + python_requires='>=3.8', classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", From 7f2ef817184838aad43cc188a7aee075fb2c22c1 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 26 Sep 2023 20:16:26 +0300 Subject: [PATCH 2/8] Remove 2020-era Windows patch from CI --- .github/workflows/run_tests.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 5c57e4f..ee0711c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -72,10 +72,6 @@ jobs: python -m pip install --upgrade pip python -m pip install flake8 pytest - - name: Windows patch # Specifically for windows, since pip fails to fetch torch 1.6.0 as of Oct 2020. - if: runner.os == 'Windows' - run: python -m pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html - - name: Lint with flake8 run: | python -m flake8 . From 4746fc848c5bdc8b730a38419ab75ab395c20909 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 26 Sep 2023 20:17:31 +0300 Subject: [PATCH 3/8] Remove baroque check_version step from CI --- .github/workflows/run_tests.yml | 42 --------------------------------- 1 file changed, 42 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index ee0711c..4bc1ecf 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -9,49 +9,7 @@ on: - cron: "0 2 * * 6" jobs: - check_version: - strategy: - matrix: - python-version: [ 3.8 ] - os: [ ubuntu-latest ] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Check version - if: (github.event_name == 'pull_request' && github.base_ref == 'master') - run: | - python -m pip install --upgrade pip - - python -m pip install git+https://github.com/google-research/torchsde.git - master_info=$(pip list | grep torchsde) - master_version=$(echo ${master_info} | cut -d " " -f2) - python -m pip uninstall -y torchsde - - python setup.py install - pr_info=$(pip list | grep torchsde) - pr_version=$(echo ${pr_info} | cut -d " " -f2) - - python -c "import itertools as it - import sys - - _, master_version, pr_version = sys.argv - - master_version_ = [int(i) for i in master_version.split('.')] - pr_version_ = [int(i) for i in pr_version.split('.')] - - master_version__ = tuple(m for p, m in it.zip_longest(pr_version_, master_version_, fillvalue=0)) - pr_version__ = tuple(p for p, m in it.zip_longest(pr_version_, master_version_, fillvalue=0)) - sys.exit(pr_version__ < master_version__)" ${master_version} ${pr_version} - build: - needs: [ check_version ] strategy: matrix: python-version: [ 3.8 ] From 529de6cc1b7fdea2feb4091cf80c1ae92a4592a5 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 26 Sep 2023 20:19:39 +0300 Subject: [PATCH 4/8] CI: renovate, add pip cache --- .github/workflows/run_tests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 4bc1ecf..14a3539 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -18,12 +18,14 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: setup.py - name: Install dependencies run: | From ad784129a3ec31d865eadb5245e2966873d6862f Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 26 Sep 2023 20:32:11 +0300 Subject: [PATCH 5/8] CI: split linting to separate step --- .github/workflows/run_tests.yml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 14a3539..71bbea2 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -27,16 +27,25 @@ jobs: cache: pip cache-dependency-path: setup.py - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install flake8 pytest + - name: Install + run: pip install pytest -e . + + - name: Test with pytest + run: python -m pytest + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + cache: pip + cache-dependency-path: setup.py - name: Lint with flake8 run: | + python -m pip install flake8 python -m flake8 . - - - name: Test with pytest - run: | - python setup.py install - python -m pytest From 6af010fed81625a7420e2abb4d95c7ea71664bda Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 26 Sep 2023 20:32:42 +0300 Subject: [PATCH 6/8] CI: don't allow compiling libraries from scratch, use correct Torch repo --- .github/workflows/run_tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 71bbea2..cce7b27 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -28,7 +28,9 @@ jobs: cache-dependency-path: setup.py - name: Install - run: pip install pytest -e . + run: pip install pytest -e . --only-binary=numpy,scipy,matplotlib,torch + env: + PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu - name: Test with pytest run: python -m pytest From 9996af12c60989628d874b75d5efd154d16a3a0c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 26 Sep 2023 20:33:12 +0300 Subject: [PATCH 7/8] CI: print pytest progress --- .github/workflows/run_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index cce7b27..9e979ea 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -33,7 +33,7 @@ jobs: PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu - name: Test with pytest - run: python -m pytest + run: python -m pytest -v lint: runs-on: ubuntu-latest From 9985de795e2438c0ad30b70ee97e720fb5f77f1d Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 26 Sep 2023 20:30:25 +0300 Subject: [PATCH 8/8] Drop Boltons dependency for small custom LRU dict --- setup.py | 1 - torchsde/_brownian/brownian_interval.py | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 5bd16bc..66f3d1f 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,6 @@ url="https://github.com/google-research/torchsde", packages=setuptools.find_packages(exclude=['benchmarks', 'diagnostics', 'examples', 'tests']), install_requires=[ - "boltons>=20.2.1", "numpy>=1.19", "scipy>=1.5", "torch>=1.6.0", diff --git a/torchsde/_brownian/brownian_interval.py b/torchsde/_brownian/brownian_interval.py index afde9cb..79391d2 100644 --- a/torchsde/_brownian/brownian_interval.py +++ b/torchsde/_brownian/brownian_interval.py @@ -16,7 +16,6 @@ import trampoline import warnings -import boltons.cacheutils import numpy as np import torch @@ -112,6 +111,21 @@ def __getitem__(self, item): raise KeyError +class _LRUDict(dict): + def __init__(self, max_size): + super().__init__() + self._max_size = max_size + self._keys = [] + + def __setitem__(self, key, value): + if key in self: + self._keys.remove(key) + elif len(self) >= self._max_size: + del self[self._keys.pop(0)] + super().__setitem__(key, value) + self._keys.append(key) + + class _Interval: # Intervals correspond to some subinterval of the overall interval [t0, t1]. # They are arranged as a binary tree: each node corresponds to an interval. If a node has children, they are left @@ -505,7 +519,7 @@ def __init__(self, elif cache_size == 0: self._increment_and_space_time_levy_area_cache = _EmptyDict() else: - self._increment_and_space_time_levy_area_cache = boltons.cacheutils.LRU(max_size=cache_size) + self._increment_and_space_time_levy_area_cache = _LRUDict(max_size=cache_size) # We keep track of the most recently queried interval, and start searching for the next interval from that # element of the binary tree. This is because subsequent queries are likely to be near the most recent query.