From 663e1fd899ed10a1f3495d8f8df477ee7a06762f Mon Sep 17 00:00:00 2001 From: "Gerald E. Fux" Date: Fri, 21 Jun 2024 15:05:00 +0200 Subject: [PATCH] Renew CI and update to python3.10 --- .circleci/config.yml | 20 ------ .github/workflows/python-package-pypi.yml | 49 +++++++++++++ .github/workflows/python-package-tests.yml | 26 +++++++ .github/workflows/pythonpublish.yml | 26 ------- .travis.yml | 12 ---- CONTRIBUTING.md | 31 ++++---- PULL_REQUEST_TEMPLATE.md | 9 +-- oqupy/backends/node_array.py | 2 +- oqupy/helpers.py | 2 +- oqupy/system_dynamics.py | 7 +- pylintrc | 84 +++------------------- requirements.txt | 2 +- requirements_ci.txt | 9 ++- setup.py | 4 +- tests/physics/tempo_superohmic_test.py | 4 +- tox.ini | 15 ++-- 16 files changed, 123 insertions(+), 179 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/python-package-pypi.yml create mode 100644 .github/workflows/python-package-tests.yml delete mode 100644 .github/workflows/pythonpublish.yml delete mode 100644 .travis.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index a812d6c8..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/python:3.6 - steps: - - checkout - - restore_cache: - key: deps1-{{ .Branch }}-{{ checksum "requirements_ci.txt" }} - - run: - command: | - python3 -m pip install tox - - run: - name: Running tests - command: | - tox - - save_cache: - key: deps1-{{ .Branch }}-{{ checksum "requirements_ci.txt" }} - paths: - - ".tox" diff --git a/.github/workflows/python-package-pypi.yml b/.github/workflows/python-package-pypi.yml new file mode 100644 index 00000000..f75de2d3 --- /dev/null +++ b/.github/workflows/python-package-pypi.yml @@ -0,0 +1,49 @@ +name: PyPI + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + + release-build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: install packages + run: pip install build twine + - name: build release package + run: python -m build + + - name: upload windows dists + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + + pypi-publish: + environment: publish + runs-on: ubuntu-latest + needs: + - release-build + permissions: + id-token: write + + steps: + - name: Retrieve release distributions + uses: actions/download-artifact@v4 + with: + name: release-dists + path: dist/ + + - name: Publish release distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/python-package-tests.yml b/.github/workflows/python-package-tests.yml new file mode 100644 index 00000000..2570a658 --- /dev/null +++ b/.github/workflows/python-package-tests.yml @@ -0,0 +1,26 @@ +name: tests + +on: [push, workflow_dispatch] + +jobs: + tests: + + runs-on: ubuntu-latest + strategy: + matrix: + python: ["3.10"] + + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + - name: Install tox + run: pip install tox + - name: Run tox + run: tox + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml deleted file mode 100644 index b143a530..00000000 --- a/.github/workflows/pythonpublish.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Upload Python Package - -on: - release: - types: [created] - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dfacf00c..00000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: python -python: - - "3.6" -# command to install dependencies -install: - - pip install tox -# command to run tests -script: - - tox -# commants to deploy -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69126034..3a3ed401 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -103,8 +103,6 @@ resource. After initialising a new repository in an empty directory with `git in ```bash $ #if you use ssh: $ git remote add upstream git@github.com:tempoCollaboration/OQuPy.git -$ #if you use https -$ git remote add upstream https://github.com/tempoCollaboration/OQuPy.git $ git fetch upstream $ git checkout main @@ -121,7 +119,7 @@ $ git push origin main ``` ### 4. Setup your local environment -As a development environment you will need `git`, `python3.6`, `pip3` and `tox` +As a development environment you will need `git`, `python3.10`, `pip3` and `tox` installed. You need `git` to @@ -130,7 +128,7 @@ changes to the repository, while `tox` allows you to run tests on the package in an virtual environment (to avoid that the result of the tests depends on the local setup). If you are unfamiliar with `git`, [this](https://swcarpentry.github.io/git-novice/) is a good place to start -learning about it. Currently the code is tested against `python3.6`, which makes it +learning about it. Currently the code is tested against `python3.10`, which makes it necessary to have this version of the python interpreter installed in the development environment. @@ -176,8 +174,6 @@ added to the project, namely: * execute the tests that check the functionality of the package (with `pytest`) * test the coding style (with `pylint`) -* check that the documentation can be generated (with `sphinx`) - #### 7.1 test all You can run all three tests by simply running `tox` in your local clone of the repository: @@ -187,20 +183,19 @@ $ tox This performs a bunch of tests. If they all pass, it will finish with something like: ```bash - py36: commands succeeded - style: commands succeeded - docs: commands succeeded - congratulations :) + pytest: OK (136.95=setup[30.37]+cmd[106.58] seconds) + pylint: OK (51.52=setup[25.93]+cmd[25.59] seconds) + congratulations :) (188.56 seconds) ``` #### 7.2 test pytest only -You can run the pytests on python3.6 with: +You can run the pytests on python3.10 with: ```bash -$ tox -e py36 +$ tox -e pytest ``` or you can pick a specific test in `./tests` to run with: ```bash -$ tox -e py36 coverage/api_test.py +$ tox -e pytest coverage/api_test.py ``` Here `coverage/api_test.py` is the path of the test file *relative to the tests directory* and the command must be run from the *base directory of the repository.* @@ -209,18 +204,20 @@ directory* and the command must be run from the *base directory of the repositor This checks the code [code style](https://www.python.org/dev/peps/pep-0008/) with pylint: ```bash -$ tox -e style +$ tox -e pylint ``` or you can check the style of a specific file in `./oqupy` with: ```bash -$ tox -e style base_api.py +$ tox -e pylint base_api.py ``` where `base_api.py` is the path of the file *relative to the oqupy directory* and again this command must be run from the base directory of the repository. -[comment]: # (The reason for this is that tox prepends the path you pass as an argument with './oqupy/' when using the style command, and './tests/' when using the py36 command) +[comment]: # (The reason for this is that tox prepends the path you pass as an +argument with './oqupy/' when using the style command, and './tests/' when +using the py36 command) -#### 7.4 test sphinx only +#### 7.4 build the documentation This invokes a sphinx-build to build the HTML documentation ```bash $ tox -e docs diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 79735546..47a62480 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -2,7 +2,7 @@ This checklist serves as a guide for contributors and maintainers to assess whether a contribution can be merged into the main branch and thus serves -to guarantee the quality of the package. Please also read the +to guarantee the quality of the package. Please read the [contribution guideline](https://github.com/tempoCollaboration/OQuPy/blob/main/CONTRIBUTING.md). Before you submit a pull request, please go through this checklist once @@ -18,13 +18,10 @@ type of your contribution. * [ ] The automated test are all positive: - [ ] `tox -e py36` (to run `pytest`) the code tests. - [ ] `tox -e style` (to run `pylint`) the [code style](https://www.python.org/dev/peps/pep-0008/) tests. - - [ ] `tox -e docs` (to run `sphinx`) generate the documentation. * [ ] Added test for changed/added code. -* [ ] API code contributions include input checks (defensive code). -* [ ] API code contributions include helpful error messages. * [ ] The documentation has been updated: - [ ] docstring for all new functions/methods/classes/modules. - [ ] consistent style of all docstrings. - [ ] for new modules: `/docs/pages/modules.rst` has been updated. - - [ ] for api contributions: `/docs/pages/api.rst` has been updated. - - [ ] for api contributions: tutorials and examples have been updated. + - [ ] for new functionality: `/docs/pages/api.rst` has been updated. + - [ ] for new functionality: tutorials and examples have been updated. diff --git a/oqupy/backends/node_array.py b/oqupy/backends/node_array.py index 7707cc5c..406262e2 100644 --- a/oqupy/backends/node_array.py +++ b/oqupy/backends/node_array.py @@ -112,7 +112,7 @@ def __str__(self) -> Text: def get_verbose_string(self): """Returns a verbose desciption of the NodeArray. """ - ret = [self.__str__()] + ret = [str(self)] ret.append("\n") ret.append(f" rank = {self.rank}\n") ret.append(f" len = {len(self)}\n") diff --git a/oqupy/helpers.py b/oqupy/helpers.py index 0def27ac..9a1303cd 100644 --- a/oqupy/helpers.py +++ b/oqupy/helpers.py @@ -41,7 +41,7 @@ def plot_correlations_with_parameters( if parameters.add_correlation_time is None: add_time = 0.0 infinity = False - elif parameters.add_correlation_time == np.infty: + elif parameters.add_correlation_time == np.inf: add_time = 0.0 infinity = True else: diff --git a/oqupy/system_dynamics.py b/oqupy/system_dynamics.py index 6f54f9c8..0a4fa01d 100644 --- a/oqupy/system_dynamics.py +++ b/oqupy/system_dynamics.py @@ -16,6 +16,7 @@ """ from typing import List, Optional, Text, Tuple, Union +import warnings from itertools import product import numpy as np @@ -862,12 +863,12 @@ def compute_correlations_nt( dt_ = process_tensor.dt else: if (process_tensor.dt is not None) and (process_tensor.dt != dt): - UserWarning("Specified time step `dt` does not match `dt` " \ + warnings.warn("Specified time step `dt` does not match `dt` " \ + "stored in the given process tensor " \ + f"({dt}!={process_tensor.dt}). " \ + "Using specified `dt`. " \ + "Don't specify `dt` to use the time step stored in the " \ - + "process tensor.") + + "process tensor.", UserWarning) dt_ = dt #Check that lengths of the ops_order, ops_times and dip_ops lists are equal @@ -892,7 +893,7 @@ def compute_correlations_nt( ret_correlations = np.empty(times_length, dtype=NpDtype) #This array will contain all correlations - ret_correlations[:] = np.NaN + 1.0j*np.NaN + ret_correlations[:] = np.nan + 1.0j*np.nan parameters = { diff --git a/pylintrc b/pylintrc index 5780168d..73b43fd7 100644 --- a/pylintrc +++ b/pylintrc @@ -54,79 +54,16 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=print-statement, - parameter-unpacking, - unpacking-in-except, - old-raise-syntax, - backtick, - long-suffix, - old-ne-operator, - old-octal-literal, - import-star-module-level, - non-ascii-bytes-literal, - raw-checker-failed, +disable=raw-checker-failed, bad-inline-option, locally-disabled, - locally-enabled, file-ignored, suppressed-message, useless-suppression, deprecated-pragma, - apply-builtin, - basestring-builtin, - buffer-builtin, - cmp-builtin, - coerce-builtin, - execfile-builtin, - file-builtin, - long-builtin, - raw_input-builtin, - reduce-builtin, - standarderror-builtin, - unicode-builtin, - xrange-builtin, - coerce-method, - delslice-method, - getslice-method, - setslice-method, - no-absolute-import, - old-division, - dict-iter-method, - dict-view-method, - next-method-called, - metaclass-assignment, - indexing-exception, - raising-string, - reload-builtin, - oct-method, - hex-method, - nonzero-method, - cmp-method, - input-builtin, - round-builtin, - intern-builtin, - unichr-builtin, - map-builtin-not-iterating, - zip-builtin-not-iterating, - range-builtin-not-iterating, - filter-builtin-not-iterating, - using-cmp-argument, - eq-without-hash, - div-method, - idiv-method, - rdiv-method, - exception-message-attribute, - invalid-str-codec, - sys-max-int, - bad-python3-import, - deprecated-string-function, - deprecated-str-translate-call, - deprecated-itertools-function, - deprecated-types-field, - next-method-defined, - dict-items-not-iterating, - dict-keys-not-iterating, - dict-values-not-iterating, + use-implicit-booleaness-not-comparison-to-string, + use-implicit-booleaness-not-comparison-to-zero, + use-symbolic-message-instead, super-init-not-called, # GEFux: added by hand duplicate-code, # GEFux: added by hand too-many-statements, # GEFux: added by hand @@ -140,7 +77,9 @@ disable=print-statement, abstract-method, # GEFux: added for development consider-using-enumerate, # GEFux: added by hand consider-using-f-string, # GEFux: added for development - too-many-arguments, # piperfw: added for development (MF degeneracy) + too-many-arguments, # piperfw: added for development + possibly-used-before-assignment, # GEFux: added by hand + unnecessary-lambda-assignment # GEFux: added by hand # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -244,13 +183,6 @@ max-line-length=80 # GEFux # Maximum number of lines in a module max-module-lines=2000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma, - dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no @@ -555,4 +487,4 @@ valid-metaclass-classmethod-first-arg=mcs # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=bultins.Exception diff --git a/requirements.txt b/requirements.txt index dd4b9569..fc7aca66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -numpy>=1.18.0 +numpy>=1.18,<2.0 scipy>=1.4.0 tensornetwork==0.4.3 matplotlib>=3.0.0 diff --git a/requirements_ci.txt b/requirements_ci.txt index 0e8fade6..5d73b0a0 100644 --- a/requirements_ci.txt +++ b/requirements_ci.txt @@ -1,16 +1,15 @@ -pytest +pytest>=8.1.0 pytest-cov -pylint +pylint>=3.1.0 sphinx sphinx_rtd_theme ipython -docutils==0.16 setuptools wheel -numpy>=1.18.0 +docutils==0.16 +numpy>=1.18,<2.0 scipy>=1.4.0 tensornetwork==0.4.3 matplotlib>=3.0.0 -tox h5py>=3.1.0 numdifftools>=0.9.41 diff --git a/setup.py b/setup.py index eac976ae..708236b6 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ url='http://github.com/tempoCollaboration/OQuPy', author='TEMPO Collaboration', author_email='tempo.collaboration@gmail.com', - python_requires=('>=3.6.0'), + python_requires=('>=3.10.0'), install_requires=requirements, license='Apache 2.0', description=short_description, @@ -59,7 +59,7 @@ packages=find_packages(exclude=['tests']), classifiers=[ "Development Status :: 3 - Alpha", - "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.10", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", ] diff --git a/tests/physics/tempo_superohmic_test.py b/tests/physics/tempo_superohmic_test.py index 389640c2..fd89de23 100644 --- a/tests/physics/tempo_superohmic_test.py +++ b/tests/physics/tempo_superohmic_test.py @@ -70,7 +70,7 @@ def test_tensor_network_tempo_backend_E(): dt=0.4, dkmax=2, epsrel=1.0e-5, - add_correlation_time=np.infty) + add_correlation_time=np.inf) tempo_E = oqupy.Tempo( system_E, bath_E, @@ -87,7 +87,7 @@ def test_tensor_network_pt_tempo_backend_E(): dt=0.4, dkmax=2, epsrel=1.0e-5, - add_correlation_time=np.infty) + add_correlation_time=np.inf) pt = oqupy.pt_tempo_compute( bath_E, start_time=t_start_E, diff --git a/tox.ini b/tox.ini index 72b28f7f..0bc3daf4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,25 +1,26 @@ [tox] -minversion = 3.10.0 -envlist = py36, style, docs +minversion = 4.14.0 +envlist = pytest, pylint -[testenv:py36] +[testenv:pytest] description = run pytests and make coverage report +basepython = python3.10 deps = -rrequirements_ci.txt commands = pytest --cov-report term-missing --cov=oqupy ./tests/{posargs} python -m coverage xml -[testenv:style] +[testenv:pylint] description = check code style with pylint -basepython = python3.6 +basepython = python3.10 deps = -rrequirements_ci.txt commands = pylint ./oqupy/{posargs} [testenv:docs] description = invoke sphinx-build to build the HTML docs -basepython = python3.6 +basepython = python3.10 deps = -rrequirements_ci.txt commands = sphinx-build -M html ./docs ./docs/_build -; sphinx-build -M latexpdf ./docs ./docs/_build +