Repository navigation
Use SciPy MILP for default spatial matching - #940
anshurajbisoyi98-ctrl wants to merge 3 commits into
Conversation
Signed-off-by: Anshu Raj Bisoyi <anshurajbisoyi98@gmail.com>
Signed-off-by: Anshu Raj Bisoyi <anshurajbisoyi98@gmail.com>
Signed-off-by: Anshu Raj Bisoyi <anshurajbisoyi98@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #940 +/- ##
=======================================
+ Coverage 85.9% 86.0% +0.1%
=======================================
Files 151 152 +1
Lines 16511 16626 +115
=======================================
+ Hits 14184 14301 +117
+ Misses 2327 2325 -2
🚀 New features to boost your workflow:
|
|
Thanks for this, and for the careful write-up and the AI-assistance disclosure. I checked the SciPy formulation against the existing PuLP model and it matches: within a dataset, integer matching requires at least k matches per point and partial matching exactly k; between datasets, each target gets at least k and each source at most k; bounds are 0–1, and edge order is the same as before. On random 60×80 point sets covering all 8 combinations of within/between, integer/partial and k=1/3, SciPy and CBC gave identical objectives and identical edge sets, with SciPy 2–10× faster. So the core change looks good to me. A few things before merging: 1. Tie-breaking changes the default output. On a regular 6×6 lattice, SciPy (HiGHS) and CBC return different edge sets for both k=1 and k=2. The total distance is the same, but the graph differs. This means 2. The existing known-answer tests don't exercise the new default path. 3. The infeasibility fallback. When HiGHS reports a problem infeasible, re-solving it with CBC gives the same infeasible result plus a warning and non-integer weights that mean nothing. It also solves large problems twice, and users without PuLP get an 4. Rebase. Smaller points:
Keeping PuLP as an optional extra for |
@sjsrey which changelog entry? Our changelog is autogenerated from PR titles... |
Good point. I think a note in the docstring should suffice. |
|
In principle, I think this is the right move. I think we should explore using scipy instead of moving to pulp 5---no knock on pulp 5, but using scipy's linear assignment method is more in keeping with the purposes of the library. This renders redundant the other projects to update the matching engine for pulp (#963,#960,#907 and I think #939 will need to be updated). I would like to see the following. Guide your botnet accordingly.
|
Description
Related to #916.
Default spatial matching currently requires PuLP to construct and solve its optimization problem. This change uses
scipy.optimize.milp, which supports the existing within-dataset and between-dataset constraints, multiple matches, and fractional weights. A one-to-one bipartite assignment solver alone cannot cover all of these cases.The implementation constructs a sparse edge-incidence matrix and preserves the existing objective and degree bounds. Successful default calls no longer need PuLP. Explicit PuLP solvers and
return_mip=Truecontinue to use the existing implementation. If SciPy optimization is unsuccessful, the code falls back to PuLP and retains its existing warning behavior. PuLP therefore remains an optional dependency rather than being removed entirely.Precomputed distances now receive positional IDs, fixing the previously uninitialized IDs in that path. The matching docstrings describe solver selection and fallback requirements.
Validation
git diff --checkpassed.k=2) showed approximately 2–14x lower median runtime than PuLP/CBC. These are small-case measurements, not a general performance guarantee.The installed macOS Pandarm wheel lacked its OpenMP runtime linkage. For the complete graph run, Homebrew's
libompwas loaded withctypes.CDLL(..., mode=ctypes.RTLD_GLOBAL)inside the Python process before callingpytest.main, leaving CBC subprocesses unaffected. No workaround was added to project code. Both travel-network tests passed.The full project suite, other platforms, and remote CI have not been verified.
CI compatibility
CI and docs environments now use
pulp<4, matching the existing optional dependency requirement. This avoids removed PuLP APIs in the compatibility paths and documentation example. Sparse constraint construction uses solver-compatible indices for SciPy 1.14. All 18 matching tests passed locally with both SciPy 1.14.1 and 1.18.1, and every code cell in the matching documentation notebook executed successfully.Review request
Please review whether using SciPy MILP by default with the PuLP compatibility paths is the intended scope for #916. No maintainer approval of this approach is implied.
Contributor checklist
main(the template still refers tomaster).AI assistance
Codex assisted with investigation, implementation, regression tests and local verification. I take responsibility for the submitted changes and reviewer interactions.