Skip to content

Commit a37d515

Browse files
authored
Memory leak fixes in the wrapper (#199)
* memory leak fixes * Tweaks for workflow for CI changes since last merge.
1 parent 72ec3c1 commit a37d515

5 files changed

Lines changed: 22 additions & 14 deletions

File tree

.github/workflows/build_default.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646
cibw_archs: "auto"
4747
- os: windows-2022
4848
cibw_archs: "auto64"
49-
# Include macos-13 to get Intel x86_64 macs and maos-latest to get the Aaarch64 macs
50-
- os: macos-13
49+
# Include macos-15-intel to get Intel x86_64 macs and macos-latest to get the Aaarch64 macs
50+
- os: macos-15-intel
5151
cibw_archs: "x86_64"
5252
- os: macos-latest
5353
cibw_archs: "arm64"

.github/workflows/build_mkl.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
# macos-latest now uses arm64 runners, but MKL is x86_64 only, so restrict to the macos-13 runners
20+
# macos-latest now uses arm64 runners, but MKL is x86_64 only, so restrict to the macos-15-intel runners
2121
# to get x86_64 architecture.
22-
os: [ubuntu-latest, macos-13]
22+
os: [ubuntu-latest, macos-15-intel]
2323

2424
steps:
2525
- uses: actions/checkout@master

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cmake_minimum_required(VERSION 3.15...3.26)
22
project(ext)
33

4+
set(CMAKE_CXX_STANDARD 14)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
47
set(PYTHON "ON")
58
set(OSQP_BUILD_UNITTESTS "OFF")
69
set(OSQP_USE_LONG "OFF")

cibuildwheel.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ before-build = "rm -rf {package}/osqp_sources/build"
66
# Install CPU-only version of torch beforehand since that allows cibuildwheel
77
# to satisfy the "test" dependency group install, but much faster. The runtime
88
# cost of torch-based osqp tests are considered negligible so torch-cpu is ok.
9-
before-test = "pip install torch --index-url https://download.pytorch.org/whl/cpu"
9+
before-test = 'pip install scipy --prefer-binary && pip install torch --index-url https://download.pytorch.org/whl/cpu'
1010
test-groups = ["test"]
1111
test-command = "python -m pytest -s {project}/src/osqp/tests"
12-
# 09/10/25 - Skip testing on cp313-manylinux_aarch64 because torch/numpy deps are unsatisfiable
13-
test-skip = "cp313-manylinux_aarch64"
1412

15-
[tool.cibuildwheel.macos]
16-
# 02/13/25 - Skip testing on cp313-macosx_x86_64 because torch/numpy deps are unsatisfiable
17-
test-skip = "cp313-macosx_x86_64"
13+
[[tool.cibuildwheel.overrides]]
14+
# Platforms on which installing pytorch is problematic, so we skip testing
15+
# the `osqp.nn` module
16+
select = "*manylinux_aarch64 cp313-macosx_x86_64"
17+
before-test = 'pip install scipy --prefer-binary'
18+
test-groups = ["test-no-nn"]
19+
test-command = "python -m pytest -s {project}/src/osqp/tests --continue-on-collection-errors --ignore={project}/src/osqp/tests/nn_test.py"
1820

1921
[tool.cibuildwheel.pyodide]
2022
build = "cp312-pyodide_wasm32"

src/bindings.cpp.in

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <iostream>
2+
#include <memory>
23
#include <pybind11/pybind11.h>
34
#include <pybind11/numpy.h>
45

@@ -132,6 +133,7 @@ class PyOSQPSolver {
132133
const CSC& _A;
133134
py::array_t<OSQPFloat> _u;
134135
OSQPSolver *_solver;
136+
std::unique_ptr<PyOSQPSolution> _solution_cache;
135137
};
136138

137139
PyOSQPSolver::PyOSQPSolver(
@@ -143,8 +145,7 @@ PyOSQPSolver::PyOSQPSolver(
143145
OSQPInt m,
144146
OSQPInt n,
145147
const OSQPSettings *settings
146-
): m(m), n(n), _P(P), _A(A) {
147-
this->_solver = new OSQPSolver();
148+
): m(m), n(n), _P(P), _A(A), _solver(nullptr) {
148149
this->_q = q;
149150
this->_l = l;
150151
this->_u = u;
@@ -164,8 +165,10 @@ OSQPSettings* PyOSQPSolver::get_settings() {
164165
}
165166

166167
PyOSQPSolution& PyOSQPSolver::get_solution() {
167-
PyOSQPSolution* solution = new PyOSQPSolution(*this->_solver->solution, this->m, this->n);
168-
return *solution;
168+
if (!_solution_cache) {
169+
_solution_cache = std::make_unique<PyOSQPSolution>(*this->_solver->solution, this->m, this->n);
170+
}
171+
return *_solution_cache;
169172
}
170173

171174
OSQPInfo* PyOSQPSolver::get_info() {

0 commit comments

Comments
 (0)