Repository navigation
Make LibSVM a private CMake dependency (#8547, #8558) - #9701
timosachsenberg merged 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughWalkthroughLibSVM is moved to private linkage. ChangesLibSVM Privatization and SimpleSVM Encapsulation
Sequence Diagram(s)sequenceDiagram
participant FeatureFindingMetabo
participant SimpleSVM
participant LibSVM
FeatureFindingMetabo->>SimpleSVM: loadModel(model_filename)
SimpleSVM->>LibSVM: svm_load_model(filename)
LibSVM-->>SimpleSVM: model pointer
FeatureFindingMetabo->>SimpleSVM: predict(features)
SimpleSVM->>LibSVM: svm_predict(model, nodes)
LibSVM-->>SimpleSVM: label
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/tests/class_tests/openms/source/SimpleSVM_test.cpp (1)
605-605: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
TEST_TRUE/TEST_FALSEinstead ofTEST_EQUAL(expr, true/false).Four new assertions use the
TEST_EQUAL(expr, true/false)pattern instead of the preferred boolean macros.♻️ Proposed fix
- TEST_EQUAL((label_loaded == 0.0) || (label_loaded == 1.0), true) + TEST_TRUE((label_loaded == 0.0) || (label_loaded == 1.0))- TEST_EQUAL(svm_reset.getScaling().empty(), false) + TEST_FALSE(svm_reset.getScaling().empty())- TEST_EQUAL(fw.empty(), false) + TEST_FALSE(fw.empty())- TEST_EQUAL(svm_reset.getScaling().empty(), true) + TEST_TRUE(svm_reset.getScaling().empty())As per path instructions for
src/tests/class_tests/**/*_test.cpp: "PreferTEST_TRUE(expr)andTEST_FALSE(expr)overTEST_EQUAL(expr, true)andTEST_EQUAL(expr, false)for boolean assertions."Also applies to: 639-639, 642-642, 650-650
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tests/class_tests/openms/source/SimpleSVM_test.cpp` at line 605, The boolean assertions in SimpleSVM_test should use the dedicated boolean macros instead of TEST_EQUAL(expr, true/false). Update the affected assertions in the test body around the existing label_loaded checks to use TEST_TRUE or TEST_FALSE as appropriate, keeping the same conditions but matching the preferred style used by the test framework.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/openms/source/ML/SVM/SimpleSVM.cpp`:
- Around line 542-554: In SimpleSVM::loadModel, the Exception::ParseError call
is passing its arguments in the wrong order. Update the throw site so the
filename is used as the expression/context argument and the “Could not load SVM
model...” text is used as the message/detail argument. Keep the rest of the
failure handling in loadModel unchanged.
---
Nitpick comments:
In `@src/tests/class_tests/openms/source/SimpleSVM_test.cpp`:
- Line 605: The boolean assertions in SimpleSVM_test should use the dedicated
boolean macros instead of TEST_EQUAL(expr, true/false). Update the affected
assertions in the test body around the existing label_loaded checks to use
TEST_TRUE or TEST_FALSE as appropriate, keeping the same conditions but matching
the preferred style used by the test framework.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9c5fdaa0-8b1f-4336-9cab-18094828d40a
📒 Files selected for processing (8)
CHANGELOGcmake/OpenMSConfig.cmake.insrc/openms/CMakeLists.txtsrc/openms/include/OpenMS/FEATUREFINDER/FeatureFindingMetabo.hsrc/openms/include/OpenMS/ML/SVM/SimpleSVM.hsrc/openms/source/FEATUREFINDER/FeatureFindingMetabo.cppsrc/openms/source/ML/SVM/SimpleSVM.cppsrc/tests/class_tests/openms/source/SimpleSVM_test.cpp
LIBSVM types are no longer exposed in any public OpenMS header, so libOpenMS's LibSVM dependency moves from PUBLIC to PRIVATE and downstream consumers no longer need LibSVM's include paths. FeatureFindingMetabo previously leaked `struct svm_model` through its public header. Its isotope-pattern filter now goes through the existing SimpleSVM wrapper, which encapsulates LIBSVM via the Pimpl idiom: - SimpleSVM gains loadModel()/saveModel() and a dense-vector predict() overload returning a raw class label (no probability estimates). - SimpleSVM::Impl::clear_() now resets all training-derived state (nodes_/scaling_/predictor_names_/performance_/log2_*), so a model loaded via loadModel() cannot inherit stale state from a prior setup(); getFeatureWeights() guards against a loaded model with no predictor names. - FeatureFindingMetabo holds a std::unique_ptr<SimpleSVM>; the prediction math (feature scaling, dense 4-feature vector, ==2.0 legality check) is byte-for-byte unchanged. XercesC stays PUBLIC because its types are part of the public API (XMLHandler derives from xercesc::DefaultHandler and takes xercesc::Attributes). The exported OpenMSConfig no longer find_dependency(LIBSVM): it is now private and libOpenMS is always shared. Tests: extended SimpleSVM_test (load/save/predict round-trip + lifecycle reset regression); FeatureFindingMetabo and TOPP FeatureFinderMetabo tests pass with byte-identical output. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The ParseError constructor renders its message as `<message> in: <expression>`,
so the filename belongs in the expression slot. The two arguments were swapped,
producing garbled output ("<filename> in: Could not load SVM model from
'<filename>'"). Now: filename as expression, description as message, yielding
"Could not load SVM model in: <filename>".
Co-Authored-By: Claude Opus 4.8 <[email protected]>
91ae87c to
80454c2
Compare
jpfeuffer
left a comment
There was a problem hiding this comment.
good to go if tests pass.
Description
Makes LibSVM a private CMake dependency of
libOpenMS, resolving #8547. The blocker was that the public headerFeatureFindingMetabo.hleaked the LIBSVM typestruct svm_model(a forward-declaredsvm_model*member), so LibSVM's headers propagated to every downstream consumer oflibOpenMS. That blocker was tracked separately as #8558.Changes
SimpleSVM(which already encapsulates LIBSVM via the Pimpl idiom) gains the API needed to fully wrap LIBSVM usage:loadModel()/saveModel()— load/save a model in LIBSVM's native format.double predict(const std::vector<double>&) constoverload that returns a raw class label without probability estimates.Impl::clear_()now resets all training-derived state (nodes_,scaling_,predictor_names_,performance_,log2_*) so a model loaded vialoadModel()cannot inherit stale state from a priorsetup();getFeatureWeights()now guards against a loaded model that has no predictor names.FeatureFindingMetabonow holds astd::unique_ptr<SimpleSVM>instead of a rawsvm_model*. Thestruct svm_model;forward declaration and#include "svm.h"are removed from the public header/source. The isotope-pattern legality check builds astd::vector<double>of scaled features and callsSimpleSVM::predict; the prediction math (feature scaling, dense 4-feature vector,== 2.0legality check) is byte-for-byte unchanged.LibSVM::LibSVMmoved fromOPENMS_DEP_LIBRARIES(public) toOPENMS_DEP_PRIVATE_LIBRARIES(private);find_dependency(LIBSVM)moved to the commented-out "private linked libraries" block inOpenMSConfig.cmake.in(consistent with the other private deps;libOpenMSis always built shared).XMLHandlerderives fromxercesc::DefaultHandlerand takesxercesc::Attributes), so it cannot be made private without an API break.Verification
libOpenMSrebuilds cleanly with LibSVM as a private dependency; the LibSVM include path no longer propagates to downstream consumers' compile flags.SimpleSVM_testpasses, including a new load/save/predict round-trip test and a lifecycle-reset regression test.FeatureFindingMetabo_testand all 13TOPP_FeatureFinderMetabotests pass with byte-identical output (they exercise the realMetaboliteIsoModelNoised5.svmmodel through the new code path).Closes #8547
Closes #8558
Checklist
FeatureFindingMetabobinding only exposesrun(), which is unaffected.🤖 Generated with Claude Code
Summary by CodeRabbit
loadModel()/saveModel()for reuse across sessions.predict(features)) for models loaded from disk.