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
7 changes: 7 additions & 0 deletions .github/scripts/smoke_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def main(version):
if "matches" in expected.score_fields:
assert planes[1] == expected.to_array("matches").item() == 2
print(f"Cuda{name}: {planes.tolist()} ({actual.device})")
molecules = simms.MolecularGraphs.from_smiles(["CC", "NN"])
distances = gpu.CudaMyopicMCES(threshold=2).matrix(molecules, progress_bar=False)
np.testing.assert_array_equal(distances.to_array("score"), [[0, 2], [2, 0]])
assert distances.to_array("exact").all()
forced = gpu.CudaMyopicMCES(max_frames=1).pair("C1CCCCC1", "C1CC1.C1CC1")
assert forced.item() == (4, True)
print("CudaMyopicMCES: exact GPU and HiGHS fallback distances")
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)]
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.1.0

- Added `CudaMyopicMCES` and the cached `MolecularGraphs` container for exact thresholded (`threshold=10.0`) and unrestricted (`threshold=None`) Myopic MCES molecular distances on CUDA with automatic in-process SciPy HiGHS (`scipy.optimize.milp`) fallback and zero new required dependencies.
- Verified `2,240/2,240` exact oracle parity against `myopic-mces 2.3.0` across threshold-10 and unrestricted benchmarks (`92×` faster than 8-core HiGHS and `690×` faster than 8-core CBC on 1,000 mixed pairs; see [benchmarks/myopic_mces_rtx4060.json](benchmarks/myopic_mces_rtx4060.json)).
- Supports `Spectrum` sequences, `SpectraCollection`, one-shot MGF generators, SMILES lists, RDKit `Mol` lists, and prepacked `MolecularGraphs`, with automatic unique-compound deduplication and GPU-side `sparse_matrix(..., max_distance=..., exact_only=...)` filtering.

## 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.
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,32 @@ The default cosine tensor has shape `(2, n_refs, n_queries)`, with score and mat
| `CudaModifiedCosineLinear` | `ModifiedCosineLinear` | Linear matching with a precursor shift and conflict resolution |
| `CudaBinnedEmbeddingSimilarity` | `BinnedEmbeddingSimilarity` | Cosine or Euclidean similarity of binned intensities |
| `CudaFingerprintSimilarity` | `FingerprintSimilarity` | Tanimoto or cosine over molecular fingerprints |
| `CudaMyopicMCES` | `myopic-mces` (`MCES`) | Exact thresholded or unrestricted Myopic MCES molecular distance (GPU bounds + bounded graph search + SciPy HiGHS fallback) |

`CudaModifiedCosine` is an alias for `CudaModifiedCosineGreedy`. Fingerprint matrices are indexed by valid unique compounds, in matchms `Fingerprints.inchikeys` order on each axis. Use a chemap-compatible generator with valid InChIKey and SMILES or InChI metadata, or pass prepared containers as `fingerprints_1` and `fingerprints_2`. A precursor mask for fingerprint scoring must use those same compound axes. A spectrum-level mask is directly reusable when each spectrum represents a different valid compound on its axis. RDKit generators with JSON support can be exported through `to_dict()` and reconstructed from the saved parameters. Embedding, entropy and fingerprint scorers return a single score field.

Binned embeddings and precomputed fingerprints also run on CPU. The six spectral CUDA scorers require a CUDA device or the Numba simulator. For simulator tests, set `NUMBA_ENABLE_CUDASIM=1` before starting Python.

## Myopic MCES (`CudaMyopicMCES`)

`CudaMyopicMCES` computes exact thresholded (`threshold=10.0`) or unrestricted (`threshold=None`) weighted Maximum Common Edge Subgraph distances matching `myopic-mces 2.3.0`, with zero extra dependencies beyond SimMS's core install (`numba-cuda`, `rdkit`, and SciPy's in-process HiGHS `scipy.optimize.milp`). Duplicate SMILES/structures are deduplicated automatically and pairs exceeding `max_frames` or `max_gpu_atoms` fall back to exact in-process HiGHS before returning or sparse filtering.

```python
from simms import MolecularGraphs
from simms.similarity import CudaMyopicMCES

graphs = MolecularGraphs.from_smiles(["CC(=O)Oc1ccccc1C(=O)O", "O=C(O)c1ccccc1O", "Cn1cnc2c1c(=O)n(C)c(=O)n2C"])
mces = CudaMyopicMCES(threshold=10.0)
scores = mces.matrix(graphs)
close_pairs = mces.sparse_matrix(graphs, max_distance=10.0, exact_only=True)
```

On the RTX 4060 Laptop GPU (`2,240/2,240` exact oracle parity vs `myopic-mces 2.3.0`, max diff `1.66e-12`; [benchmarks/myopic_mces_rtx4060.json](benchmarks/myopic_mces_rtx4060.json)):

- **1,000 mixed pairs (`threshold=10`):** `17.9 ms` (`92.2×` vs 8-core upstream HiGHS, `690×` vs 8-core CBC)
- **120 `filter2` survivors (`threshold=10`):** `444 ms` (`4.24×` vs 8-core upstream HiGHS, `24.9×` vs 8-core CBC)
- *(Honest baseline note: an 8-core Numba CPU port of the same graph-native algorithm ran `1.1×–3.6×` faster than Numba CUDA on these 120–1,000 pair laptop batches, showing that most of the speedup over upstream `myopic-mces` comes from replacing generic MILP setup with compact integer graph bounds + in-process HiGHS fallback.)*

## Transitive alignment

`CudaTransitiveAlignment` builds an undirected network from one collection of spectra. Its defaults retain direct modified-cosine edges with a score of at least 0.7 and at least six matches. Each reachable non-edge uses the fewest-hop path with the highest sum of direct scores. Set `max_hops` to limit path length. [Wang et al., JASMS 2024](https://doi.org/10.1021/jasms.4c00208)
Expand Down
Loading
Loading