From 06d77f2cdfad99cee8f783b82b42d73aed739d0b Mon Sep 17 00:00:00 2001 From: niekdejonge Date: Mon, 2 Feb 2026 17:02:41 +0100 Subject: [PATCH 1/4] Fixed bug with load validation of spectrum file, which breaks loading of models --- ms2deepscore/SettingsMS2Deepscore.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ms2deepscore/SettingsMS2Deepscore.py b/ms2deepscore/SettingsMS2Deepscore.py index 76a14261..db8605a8 100644 --- a/ms2deepscore/SettingsMS2Deepscore.py +++ b/ms2deepscore/SettingsMS2Deepscore.py @@ -93,8 +93,6 @@ class SettingsMS2Deepscore: If True the model will do separate pair sampling for training for each ionmode. This gives better balance over the ionmodes. Initial results showed a decrease in pos-pos prediction accuracy. Which you can find in the notebook model_benchmarking/Compare balanced cross ion moe sampling.ipynb - additional_metadata: - Additional metadata that should be used in training the model. e.g. precursor_mz dropout_rate: The dropout rate that should be used during training learning_rate: @@ -272,8 +270,6 @@ def __init__(self, validate_settings=True, **settings): np.random.seed(self.random_seed) if self.spectrum_file_path is not None: - if not os.path.isfile(self.spectrum_file_path): - raise ValueError("The spectrum file specified is not an existing file") root_dir = os.path.dirname(self.spectrum_file_path) spectrum_file_name = os.path.basename(self.spectrum_file_path) @@ -304,7 +300,10 @@ def validate_settings(self): validate_bin_order(self.same_prob_bins) if self.balanced_sampling_across_ionmodes and self.ionisation_mode != "both": raise ValueError("Balanced sampling across ionmodes only works if you train on both ionmodes") - + if self.spectrum_file_path is not None: + if not os.path.isfile(self.spectrum_file_path): + raise ValueError("The spectrum file specified is not an existing file") + def create_model_directory_name(self): """Creates a directory name using metadata, it will contain the metadata, the binned spectra and final model""" binning_file_label = "" From c9aaf3a9a3d0df28a2116eb6bb99d44f6ab28237 Mon Sep 17 00:00:00 2001 From: niekdejonge Date: Mon, 2 Feb 2026 17:10:44 +0100 Subject: [PATCH 2/4] Change test for loading models to include spectrum_file_path, to capture old bug --- tests/test_load_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_load_model.py b/tests/test_load_model.py index e70d61c2..c559ca47 100644 --- a/tests/test_load_model.py +++ b/tests/test_load_model.py @@ -10,7 +10,7 @@ def _dummy_siamese_model(): """Helper function to create a dummy SiameseSpectralModel.""" - settings = SettingsMS2Deepscore(base_dims=(100, 100), embedding_dim=10) + settings = SettingsMS2Deepscore(base_dims=(100, 100), embedding_dim=10, spectrum_file_path="./nonexisting_path.mgf", validate_settings=False) model = SiameseSpectralModel(settings=settings) return model From efa2c1dac919260dcf40e8b493eab362f132cbcf Mon Sep 17 00:00:00 2001 From: niekdejonge Date: Thu, 5 Feb 2026 12:17:30 +0100 Subject: [PATCH 3/4] Add a check if a file exists, before it gave the "this is a legacy file error" if a file did not exist --- ms2deepscore/models/load_model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ms2deepscore/models/load_model.py b/ms2deepscore/models/load_model.py index 7695addf..776b9fc4 100644 --- a/ms2deepscore/models/load_model.py +++ b/ms2deepscore/models/load_model.py @@ -1,3 +1,4 @@ +import os from typing import Union, Dict, Optional, Any, Callable import json from pathlib import Path @@ -130,6 +131,8 @@ def _load_model_generic( 3) Instantiate model via model_factory(settings), then load state_dict. 4) If safe path fails and allow_legacy=True, attempt unsafe legacy path. """ + if not os.path.isfile(filename): + raise ValueError(f"The file given does not exist: {filename}") # --- preferred safe path try: ckpt = _load_ckpt_safe(filename) From e97649f41a1e1b9e9226f61210af01ae9f031711 Mon Sep 17 00:00:00 2001 From: niekdejonge Date: Thu, 5 Feb 2026 12:22:14 +0100 Subject: [PATCH 4/4] Update changelog and version --- CHANGELOG.md | 5 +++++ ms2deepscore/__version__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a29c39af..7d8decbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.7.1 +### Fixed +- In 2.7.0 a bug was introduced, failing the loading of models. Here this is fixed. +- Added a check that a model file exists, for clearer error handling. + ## 2.7.0 ### Added - The training pair sampling for both ionmodes is now balanced over the different ionmode pairs. diff --git a/ms2deepscore/__version__.py b/ms2deepscore/__version__.py index 766ce2d0..e90ba7fa 100644 --- a/ms2deepscore/__version__.py +++ b/ms2deepscore/__version__.py @@ -1 +1 @@ -__version__ = '2.7.0' +__version__ = '2.7.1'