Add parameter setting API and simplify presolve apply functions#40
Add parameter setting API and simplify presolve apply functions#40
Conversation
This commit adds C API functions for setting parameters on presolve objects,
enabling fine-grained control over individual presolvers:
New parameter setting functions:
- libpapilo_presolve_set_param_bool: Set boolean parameters (e.g., presolver enable/disable)
- libpapilo_presolve_set_param_int: Set integer parameters
- libpapilo_presolve_set_param_double: Set double parameters
- libpapilo_presolve_parse_param: Parse string value for any parameter type
New presolve execution function:
- libpapilo_presolve_apply_full: Run presolve with a user-configured presolve object
and return postsolve storage and statistics (unlike apply_simple which only
returns status)
Example usage to disable ParallelColDetection:
libpapilo_presolve_set_param_bool(presolve, "parallelcols.enabled", 0);
Note: Parameters are only available after presolvers are added via
add_default_presolvers().
Tests include both API tests and a behavioral test verifying that disabling
parallelcols.enabled actually prevents parallel column detection.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR extends the libpapilo C API to allow configuring presolve behavior via parameter keys on a user-managed presolve object, and adds a new “full output” presolve entry point suitable for downstream integrations that need to disable specific presolvers (e.g., parallelcols) before running presolve.
Changes:
- Add C API functions to set/parse presolve parameters (
set_param_bool,set_param_int,set_param_double,parse_param). - Add
libpapilo_presolve_apply_fullto run presolve using a caller-configured presolve object and return postsolve storage + statistics. - Add a new Catch2 test suite covering the new APIs and a behavioral test for disabling
parallelcols.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/libpapilo.h |
Declares the new parameter-setting APIs and presolve_apply_full with added documentation. |
src/libpapilo.cpp |
Implements parameter-setting wrappers and the new presolve_apply_full entry point. |
test/libpapilo/ParameterTest.cpp |
Adds API-level tests and a behavioral test verifying parallelcols.enabled behavior. |
test/libpapilo/CMakeLists.txt |
Registers the new test file and its individual Catch2 test cases with CTest. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Replace int return values with libpapilo_param_result_t enum - Define states: LIBPAPILO_PARAM_OK, NOT_FOUND, WRONG_TYPE, INVALID_VALUE - Update all parameter setting functions and tests to use the new type - Follows pattern from original papilolib PAPILO_PARAM_RESULT enum Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
CMake list parsing splits strings on spaces, causing test registration to fail. Changed all ParameterTest names to use hyphens. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add per-presolver statistics to apply_full (was missing) - Add set_param_double test with success and failure cases - Add cliquemerging.enabled to presolver disable list - Check return values in disableAllPresolversExcept helper - Update parse_param documentation for boolean parsing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
DRY up the common try-catch pattern across all 4 parameter setting functions by extracting a helper template function. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
API cleanup: - Remove libpapilo_presolve_apply (convenience function) - Remove libpapilo_presolve_apply_simple (subset of apply_full) - Keep libpapilo_presolve_apply_full as the main presolve entry point - Keep libpapilo_presolve_apply_reductions for low-level control The removed functions can be implemented at higher layers (e.g., Rust) if convenience wrappers are needed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
38bc3e3 to
ad45250
Compare
|
@codex please review |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad45250779
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Distinguish parse errors from missing keys in run_param_op by checking exception message for "could not parse" - Add catch-all handlers to prevent exceptions crossing C API boundary - Update parse_param documentation to accurately describe accepted values - Fix test to expect INVALID_VALUE for parse errors instead of NOT_FOUND - Add nullptr checks in test cases for message/presolve/builder objects Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
New Feature: Parameter Setting API
libpapilo_presolve_set_param_bool/set_param_int/set_param_double/parse_paramlibpapilo_param_result_tenum for proper error handlingLIBPAPILO_PARAM_OK,NOT_FOUND,WRONG_TYPE,INVALID_VALUEAPI Cleanup
libpapilo_presolve_apply(convenience function → can be implemented at higher layers)libpapilo_presolve_apply_simple(replaced byapply_full)libpapilo_presolve_apply_full(main presolve entry point)libpapilo_presolve_apply_reductions(low-level API)Motivation
Enable fine-grained control over individual presolvers. This API allows enabling/disabling specific presolvers before running presolve.
Example Usage
Test Plan
set_param_bool,set_param_int,set_param_double,parse_paramparallelcols.enabled=0actually prevents ParallelCol detectionBreaking Changes
libpapilo_presolve_applyremovedlibpapilo_presolve_apply_simpleremovedMigrate to
libpapilo_presolve_apply_fullif using these functions.🤖 Generated with Claude Code