Skip to content

Add parameter setting API and simplify presolve apply functions#40

Merged
termoshtt merged 8 commits intomainfrom
feature/parameter-api
Mar 10, 2026
Merged

Add parameter setting API and simplify presolve apply functions#40
termoshtt merged 8 commits intomainfrom
feature/parameter-api

Conversation

@termoshtt
Copy link
Copy Markdown
Member

@termoshtt termoshtt commented Mar 10, 2026

Summary

New Feature: Parameter Setting API

  • libpapilo_presolve_set_param_bool / set_param_int / set_param_double / parse_param
  • libpapilo_param_result_t enum for proper error handling
    • LIBPAPILO_PARAM_OK, NOT_FOUND, WRONG_TYPE, INVALID_VALUE

API Cleanup

  • Removed: libpapilo_presolve_apply (convenience function → can be implemented at higher layers)
  • Removed: libpapilo_presolve_apply_simple (replaced by apply_full)
  • Kept: libpapilo_presolve_apply_full (main presolve entry point)
  • Kept: 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

libpapilo_presolve_t* presolve = libpapilo_presolve_create(message);
libpapilo_presolve_add_default_presolvers(presolve);

// Disable parallel column detection
libpapilo_param_result_t result = 
    libpapilo_presolve_set_param_bool(presolve, "parallelcols.enabled", 0);
if (result != LIBPAPILO_PARAM_OK) {
    // Handle error
}

// Run presolve with full output
libpapilo_postsolve_storage_t* postsolve = nullptr;
libpapilo_statistics_t* statistics = nullptr;
libpapilo_presolve_apply_full(presolve, problem, &postsolve, &statistics);

libpapilo_presolve_free(presolve);

Test Plan

  • Parameter API tests (8 test cases)
    • set_param_bool, set_param_int, set_param_double, parse_param
    • Error cases (unknown key, parse error, before presolvers added)
  • Behavioral test: verify parallelcols.enabled=0 actually prevents ParallelCol detection

Breaking Changes

  • libpapilo_presolve_apply removed
  • libpapilo_presolve_apply_simple removed

Migrate to libpapilo_presolve_apply_full if using these functions.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings March 10, 2026 05:37
@termoshtt termoshtt self-assigned this Mar 10, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_full to 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.

termoshtt and others added 6 commits March 10, 2026 14:49
- 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>
@termoshtt termoshtt force-pushed the feature/parameter-api branch from 38bc3e3 to ad45250 Compare March 10, 2026 06:18
@termoshtt termoshtt changed the title Add parameter setting API for presolve configuration Add parameter setting API and simplify presolve apply functions Mar 10, 2026
@termoshtt termoshtt requested a review from Copilot March 10, 2026 06:25
@termoshtt
Copy link
Copy Markdown
Member Author

@codex please review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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>
@termoshtt termoshtt merged commit ccb054e into main Mar 10, 2026
4 checks passed
@termoshtt termoshtt deleted the feature/parameter-api branch March 10, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants