Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/scripts/smoke_wheel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Run outside the checkout with a wheel installed into a fresh environment."""

import sys
from importlib.metadata import distribution
from pathlib import Path

import numpy as np
from matchms import Spectrum, similarity
from numba import cuda
from rdkit.Chem.rdFingerprintGenerator import GetMorganGenerator

import simms
from simms import similarity as gpu


def main(version):
dist = distribution("simms-gpu")
assert Path(simms.__file__).resolve() == dist.locate_file("simms/__init__.py").resolve()
assert Path(simms.__file__).resolve().is_relative_to(Path(sys.prefix).resolve())
assert simms.__version__ == dist.version == version
spectrum = Spectrum(
np.array([50.0, 75.0]),
np.array([2.0, 8.0]),
{"precursor_mz": 100.0, "smiles": "CCO", "inchikey": "LFQSCWFLJHTTHZ-UHFFFAOYSA-N"},
metadata_harmonization=False,
)
for name in (
"CosineGreedy",
"ModifiedCosineGreedy",
"NeutralLossesCosine",
"EntropyGreedy",
"CosineLinear",
"ModifiedCosineLinear",
"BinnedEmbeddingSimilarity",
"FingerprintSimilarity",
):
kwargs = (
{"fingerprint_generator": GetMorganGenerator(radius=2, fpSize=128)}
if name == "FingerprintSimilarity"
else {}
)
expected = getattr(similarity, name)(**kwargs).matrix([spectrum], progress_bar=False)
actual = getattr(gpu, "Cuda" + name)(**kwargs).matrix(
[spectrum], array_type="torch", progress_bar=False
)
assert actual.is_cuda == (not cuda.config.ENABLE_CUDASIM)
planes = actual.cpu().numpy().reshape(-1)
np.testing.assert_allclose(planes[0], expected.to_array("score").item(), atol=1e-12, rtol=0)
assert planes[0] > 0
if "matches" in expected.score_fields:
assert planes[1] == expected.to_array("matches").item() == 2
print(f"Cuda{name}: {planes.tolist()} ({actual.device})")
network = gpu.CudaTransitiveAlignment(min_direct_matches=2).sparse_matrix([spectrum, spectrum])
matches = network.to_coo("matches")
assert sorted(zip(matches.row, matches.col, matches.data)) == [(0, 1, 2), (1, 0, 2)]
np.testing.assert_allclose(network.to_coo("score").data, [1.0, 1.0], atol=1e-12, rtol=0)
print("CudaTransitiveAlignment: one symmetric direct edge")
print(f"simms-gpu {version} from {simms.__file__}")


if __name__ == "__main__":
main(sys.argv[1])
16 changes: 0 additions & 16 deletions .github/workflows/docker-image.yml

This file was deleted.

51 changes: 23 additions & 28 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "*" ]
branches: ["**"]
pull_request:
branches: [ "*" ]

jobs:
build:
permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9"] #, "3.10", "3.11"]

python-version: ["3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
NUMBA_CUDA_LOW_OCCUPANCY_WARNINGS=0 NUMBA_ENABLE_CUDASIM=1 pytest -m github_ci
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install package and test dependencies
run: |
python -m pip install --upgrade pip
python -m pip install torch --index-url https://download.pytorch.org/whl/cpu
extras=""
if [ "${{ matrix.python-version }}" != "3.14" ]; then
extras="chemap"
fi
python -m pip install -e . flake8 pytest nvidia-cuda-runtime $extras
- name: Lint
run: flake8 simms tests --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Test with CUDA simulator
run: NUMBA_CUDA_LOW_OCCUPANCY_WARNINGS=0 NUMBA_ENABLE_CUDASIM=1 pytest -m github_ci
79 changes: 52 additions & 27 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package
name: Publish simms-gpu

on:
release:
Expand All @@ -16,24 +8,57 @@ permissions:
contents: read

jobs:
deploy:

build:
if: startsWith(github.event.release.tag_name, 'v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Verify release version
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
python - <<'PY'
import os, runpy, tomllib
from pathlib import Path
project = tomllib.loads(Path("pyproject.toml").read_text())["project"]
version = runpy.run_path("simms/__version__.py")["__version__"]
assert project["name"] == "simms-gpu"
assert project["version"] == version and os.environ["RELEASE_TAG"] == f"v{version}"
PY
- name: Build and check sdist and wheel
run: |
python -m pip install build twine
python -m build
twine check --strict dist/*
- name: Smoke test installed wheel
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
NUMBA_CUDA_LOW_OCCUPANCY_WARNINGS: "0"
NUMBA_ENABLE_CUDASIM: "1"
run: |
python -m venv "$RUNNER_TEMP/smoke"
py="$RUNNER_TEMP/smoke/bin/python"
"$py" -m pip install torch --index-url https://download.pytorch.org/whl/cpu
"$py" -m pip install dist/*.whl chemap nvidia-cuda-runtime
cd "$RUNNER_TEMP"
"$py" -I "$GITHUB_WORKSPACE/.github/scripts/smoke_wheel.py" "${RELEASE_TAG#v}"
- uses: actions/upload-artifact@v4
with:
name: distributions
path: dist/

publish:
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/download-artifact@v4
with:
name: distributions
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ celerybeat.pid

# Environments
.env
.venv
.venv/
env/
venv/
ENV/
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## v1.0.0

- Install the `simms-gpu` distribution and keep using `import simms`. The release targets Python 3.11 through 3.14 and matchms 1.0. CUDA 12 and 13 extras install the corresponding numba-cuda toolchain. The `fingerprints` extra adds chemap.
- Scorers now return matchms `Scores` from `matrix` and `calculate_scores`. Use the `score` and `matches` fields where available. Sparse scoring filters nonzero pairs and inclusive `min_score` and `min_matches` thresholds on device. Optional Python predicates receive the surviving scores. Spectral scorers accept `SpectraCollection` and `PeakArrays`, with optional device-resident Torch results.
- Added `CudaNeutralLossesCosine`, `CudaEntropyGreedy`, `CudaCosineLinear`, `CudaModifiedCosineLinear` and `CudaBinnedEmbeddingSimilarity`. Updated `CudaCosineGreedy` and `CudaModifiedCosineGreedy` to match the 1.0 greedy algorithms. `CudaModifiedCosine` remains an alias. `CudaFingerprintSimilarity` now accepts matchms fingerprint containers and chemap generators.
- Added `CudaTransitiveAlignment` for molecular networks built from direct modified-cosine edges. It returns transitive edges, paths and optional aligned peak pairs, and accepts precomputed direct scores.
- Fixed greedy score and match-count errors on crowded spectra. Pairs that exceed a GPU peak or candidate limit are rescored with all peaks before filtering. The reported 577-peak self-comparison now returns 1.0 and 577 matches. [Issue #6](https://github.com/PangeAI/SimMS/issues/6)
- Fixed spectrum-array handling. One-dimensional object arrays use the public peak API and invalid numeric arrays get an error identifying the input side. Numeric peak data can be passed as `PeakArrays`. [Issue #9](https://github.com/PangeAI/SimMS/issues/9)
- Thanks to @BioGeek for the Python and CUDA packaging work and for the padded peak-array and device-tensor proposals that inspired this release. [PR #10](https://github.com/PangeAI/SimMS/pull/10), [PR #11](https://github.com/PangeAI/SimMS/pull/11)
Loading
Loading