From 89fe364531f43c90c7bc5e11eff5260782bd3819 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 10 May 2024 21:09:50 -0400 Subject: [PATCH 1/5] benchmark performance of import Do a benchmark before working on #522 Signed-off-by: Jinzhe Zeng --- .github/workflows/test.yml | 5 +++++ pyproject.toml | 4 ++++ tests/benchmark/__init__.py | 0 tests/benchmark/test_import.py | 13 +++++++++++++ 4 files changed, 22 insertions(+) create mode 100644 tests/benchmark/__init__.py create mode 100644 tests/benchmark/test_import.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4a17fcde1..64462e9ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,11 @@ jobs: uses: codecov/codecov-action@v4 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Run benchmarks + uses: CodSpeedHQ/action@v2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: pytest tests/benchmark/ --codspeed pass: needs: [build] runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index 3f09801a7..664dda98b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,10 @@ docs = [ 'jupyterlite-sphinx', 'jupyterlite-xeus-python', ] +test = [ + 'pytest', + 'pytest-codspeed', +] [tool.setuptools.packages.find] include = ["dpdata*"] diff --git a/tests/benchmark/__init__.py b/tests/benchmark/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/benchmark/test_import.py b/tests/benchmark/test_import.py new file mode 100644 index 000000000..022320715 --- /dev/null +++ b/tests/benchmark/test_import.py @@ -0,0 +1,13 @@ +import pytest +import subprocess +import sys + +@pytest.mark.benchmark +def test_import(): + """Test import dpdata.""" + subprocess.check_output([sys.executable, "-c", "'from dpdata import LabeledSystem'"]).decode("ascii") + +@pytest.mark.benchmark +def test_cli(): + """Test dpdata command.""" + subprocess.check_output([sys.executable, "-m", "dpdata", "-h"]).decode("ascii") From ce4bb1720574f1cbb8e873a64011fda6f33d093a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 11 May 2024 01:10:18 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/benchmark/test_import.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/benchmark/test_import.py b/tests/benchmark/test_import.py index 022320715..04d461375 100644 --- a/tests/benchmark/test_import.py +++ b/tests/benchmark/test_import.py @@ -1,11 +1,16 @@ -import pytest import subprocess import sys +import pytest + + @pytest.mark.benchmark def test_import(): """Test import dpdata.""" - subprocess.check_output([sys.executable, "-c", "'from dpdata import LabeledSystem'"]).decode("ascii") + subprocess.check_output( + [sys.executable, "-c", "'from dpdata import LabeledSystem'"] + ).decode("ascii") + @pytest.mark.benchmark def test_cli(): From 35c8da8ef38aa2ab2cb4bda6ed1de7a6599d6e18 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 10 May 2024 21:13:25 -0400 Subject: [PATCH 3/5] move benchmark out of tests Signed-off-by: Jinzhe Zeng --- .github/workflows/test.yml | 4 ++-- {tests/benchmark => benchmark}/__init__.py | 0 {tests/benchmark => benchmark}/test_import.py | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {tests/benchmark => benchmark}/__init__.py (100%) rename {tests/benchmark => benchmark}/test_import.py (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64462e9ba..e63dc02d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: python-version: ${{ matrix.python-version }} - run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install dependencies - run: uv pip install --system .[amber,ase,pymatgen] coverage ./tests/plugin rdkit openbabel-wheel + run: uv pip install --system .[amber,ase,pymatgen,test] coverage ./tests/plugin rdkit openbabel-wheel - name: Test run: cd tests && coverage run --source=../dpdata -m unittest && cd .. && coverage combine tests/.coverage && coverage report - name: Run codecov @@ -31,7 +31,7 @@ jobs: uses: CodSpeedHQ/action@v2 with: token: ${{ secrets.CODSPEED_TOKEN }} - run: pytest tests/benchmark/ --codspeed + run: pytest benchmark/ --codspeed pass: needs: [build] runs-on: ubuntu-latest diff --git a/tests/benchmark/__init__.py b/benchmark/__init__.py similarity index 100% rename from tests/benchmark/__init__.py rename to benchmark/__init__.py diff --git a/tests/benchmark/test_import.py b/benchmark/test_import.py similarity index 100% rename from tests/benchmark/test_import.py rename to benchmark/test_import.py From ebd6c45ce2958f73dbc06dea5b7490a748aedc0f Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 14 May 2024 16:19:56 -0400 Subject: [PATCH 4/5] move benchmark to a seperated job --- .github/workflows/benchmark.yml | 24 ++++++++++++++++++++++++ .github/workflows/test.yml | 7 +------ pyproject.toml | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/benchmark.yml diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 000000000..b79ea6131 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,24 @@ +name: Python package + +on: + - push + - pull_request + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 + - run: curl -LsSf https://astral.sh/uv/install.sh | sh + - name: Install dependencies + run: uv pip install --system .[amber,ase,pymatgen,benchmark] rdkit openbabel-wheel + - name: Run benchmarks + uses: CodSpeedHQ/action@v2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: pytest benchmark/ --codspeed + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e63dc02d1..4a17fcde1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,18 +20,13 @@ jobs: python-version: ${{ matrix.python-version }} - run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install dependencies - run: uv pip install --system .[amber,ase,pymatgen,test] coverage ./tests/plugin rdkit openbabel-wheel + run: uv pip install --system .[amber,ase,pymatgen] coverage ./tests/plugin rdkit openbabel-wheel - name: Test run: cd tests && coverage run --source=../dpdata -m unittest && cd .. && coverage combine tests/.coverage && coverage report - name: Run codecov uses: codecov/codecov-action@v4 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - name: Run benchmarks - uses: CodSpeedHQ/action@v2 - with: - token: ${{ secrets.CODSPEED_TOKEN }} - run: pytest benchmark/ --codspeed pass: needs: [build] runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index 347151951..5292ba9c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ docs = [ 'jupyterlite-sphinx', 'jupyterlite-xeus', ] -test = [ +benchmark = [ 'pytest', 'pytest-codspeed', ] From cd9cc4f74041843e49ba0e244b71ae1552ec1fac Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 14 May 2024 16:43:24 -0400 Subject: [PATCH 5/5] run pre-commit --- .github/workflows/benchmark.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index b79ea6131..650ff59ef 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -21,4 +21,3 @@ jobs: with: token: ${{ secrets.CODSPEED_TOKEN }} run: pytest benchmark/ --codspeed -