Skip to content

Add .deb installation and pimpl / name-keyed Configuration - #2

Merged
mmmarinho merged 1 commit into
mainfrom
add-deb-and-pimpl-configuration
Sep 29, 2026
Merged

mmmarinho merged 1 commit into
mainfrom
add-deb-and-pimpl-configuration

Conversation

@mmmarinho

Copy link
Copy Markdown
Contributor

Mirrors the best practices from marinhoLab/solver-qpoases.

This PR was created by an AI agent (OpenHands) on behalf of the user.

1. pimpl + std::variant name-keyed Configuration

The public header include/marinholab/solvers/osqp.h is now OSQP-free:

  • Solver uses the pimpl idiom (struct Impl; std::unique_ptr<Impl> impl_;).
  • Configuration is keyed by option name with a typed
    OptionValue = std::variant<bool, long long, double, std::string>, exposing
    set(key, value) / set(key, const char*) / get / has / keys /
    reset / reset_all / defaults. Values are validated and converted to
    the option's kind at set() time (so a wrong type/key raises
    std::invalid_argument immediately, not at solve time).
  • Defaults are taken directly from OSQP's osqp_set_default_settings()
    (detail::default_values), with one documented exception: verbose
    defaults to false (quiet) instead of OSQP's own true.
  • The pybind11 module binds the name-keyed Configuration with native Python
    values (bool/int/float/str + enum-by-name). The OSQP enums move out of the
    compiled extension into a pure-Python _options.py
    (LinsysSolverType, PreconditionerType, Status), so the C++ header has
    no OSQP types.

API change: the old attribute style (config.eps_abs = 1e-9) becomes the
name-keyed style (config.set("eps_abs", 1e-9)), matching solver-qpoases.
Examples, evaluation/, and README.md are updated accordingly.

2. Debian (.deb) packaging for the C++ part

  • New debian/ (package libmarinholab-solver-osqp): control, copyright
    (LGPL-2.1+ wrapper + Apache-2.0 OSQP), changelog, rules (CMake, -O3,
    -fno-lto), source/format.
  • cmake/GetVersion.cmake computes a rolling YY.MM.NN version (from
    tools/version.sh, with a fallback).
  • tools/version.sh + tools/bump-changelog.sh.
  • docker/build-deb.sh + docker/deb.Dockerfile build the .deb in an
    Ubuntu noble container (optionally --test to install it and build/run a
    find_package consumer).

The vendored OSQP is built static and bundled, so the .deb depends only
on the C++ runtime (libc6, libgcc-s1, libstdc++6). Verified end-to-end:
dpkg-buildpackage → dpkg -i → find_package(marinholab_solver_osqp)
consumer builds and solves.

Supporting changes

  • CMakeLists.txt: shared-by-default marinholab_osqp library (alias
    marinholab::solvers::osqp), a BUILD_PYTHON option, version + install
    rules, and a CMake package config (cmake/marinholab_solver_osqp-config.cmake.in)
    for find_package consumers.
  • Vendored OSQP's linear-solver qdldl as a git submodule and pointed OSQP's
    FetchContent at it, so configure time needs no network access
    (reproducible, offline-friendly).
  • setup.py passes -DBUILD_PYTHON=ON; docker/compose.yml runs the pytest
    suite before the example.
  • New tests/test_solver.py (solver reuse across shape changes +
    Configuration conversion/defaults); updated README.md and AGENTS.md.

Verification (local)

  • C++: cmake -DBUILD_EXAMPLES=ON builds; example prints x = [0.2, 1.0].
  • Python: pip install . + osqp_example run; 46/46 pytest pass.
  • Type checking: pyright → 0 errors / 0 warnings.
  • .deb: built with docker/build-deb.sh --test; consumer x = [0.2, 1.0].

Note: I attempted to also add --exit-code-from solver_osqp to
.github/workflows/build.yml (as solver-qpoases does), but the branch
could not be pushed with a token lacking the workflow scope, so that
one-line CI change is left out of this PR.

Mirror the best practices from marinhoLab/solver-qpoases:

- pimpl + std::variant Configuration (keyed by option name):
  The public header include/marinholab/solvers/osqp.h is now OSQP-free.
  Solver uses the pimpl idiom, and Configuration is keyed by name with
  typed OptionValue = std::variant<bool, long long, double, std::string>
  (exposing set/get/has/keys/defaults/reset). Defaults are taken directly
  from OSQP's osqp_set_default_settings(), with verbose defaulting to off
  so the solver is quiet. The pybind11 module binds the name-keyed
  Configuration with native Python values; the OSQP enums move to a
  pure-Python _options.py (LinsysSolverType, PreconditionerType, Status).

- Debian (.deb) packaging for the C++ part:
  Added debian/ (libmarinholab-solver-osqp), cmake/GetVersion.cmake
  (rolling YY.MM.NN version), tools/version.sh + tools/bump-changelog.sh,
  and docker/build-deb.sh + docker/deb.Dockerfile. The vendored OSQP is
  built static and bundled; the .deb depends only on the C++ runtime.

Supporting changes:
- CMakeLists.txt now produces a shared-by-default marinholab_osqp library
  (alias marinholab::solvers::osqp) with a BUILD_PYTHON option and a CMake
  package config for find_package consumers.
- Vendored OSQP's linear-solver qdldl as a git submodule and pointed
  OSQP's FetchContent at it, so configure time needs no network access.
- setup.py passes -DBUILD_PYTHON=ON; docker/compose.yml now runs the pytest
  suite before the example.
- Added tests/test_solver.py (solver reuse + Configuration conversion) and
  updated examples/README/AGENTS.md to the new name-keyed API.

Co-authored-by: openhands <openhands@all-hands.dev>

@mmmarinho mmmarinho left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

@mmmarinho
mmmarinho merged commit b752ffd into main Sep 29, 2026
11 checks passed
@mmmarinho
mmmarinho deleted the add-deb-and-pimpl-configuration branch September 29, 2026 11:35
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.

1 participant