Skip to content

[MRG] Compute value in ot.solve_sample with reg and lazy=True - #861

Open
itzzdev09 wants to merge 2 commits into
PythonOT:masterfrom
itzzdev09:solve-sample-lazy-value
Open

itzzdev09 wants to merge 2 commits into
PythonOT:masterfrom
itzzdev09:solve-sample-lazy-value

Conversation

@itzzdev09

Copy link
Copy Markdown
Contributor

Types of changes

  • Bug fix

Description

ot.solve_sample(X_a, X_b, a, b, reg=..., lazy=True) returns an OTResult whose value is None: the lazy regularized branch sets value_linear, the potentials and the lazy plan, but never the regularized value. Because of this, the debiased lazy Sinkhorn divergence fails:

import numpy as np, ot
rng = np.random.RandomState(0)
xs, xt = rng.randn(6, 2), rng.randn(5, 2) + 1
ot.solve_sample(xs, xt, reg=1.0, lazy=True).value               # None
ot.solve_sample(xs, xt, reg=1.0, lazy=True, debias=True).value  # TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

The value is now computed as in the non-lazy ot.solve (value_linear + reg * R(plan), with R the KL to a b^T or the negative entropy). The plan is read from lazy_plan in batches of batch_size rows, so memory use stays O(batch_size × n_b).

The lazy solver is always the entropic Sinkhorn, so it now raises NotImplementedError for another reg_type (for example "L2") instead of silently solving a different problem, as the non-lazy path already does for unsupported values.

How has this been tested

Added test_solve_sample_lazy_value, which checks value against the non-lazy solver for reg_type "KL" and "entropy" (with batches smaller than the problem), and for debias=True and "split". It fails on master. test/test_solvers.py passes (337 passed, 5 skipped).

Checklist

  • I have added tests to cover my changes.
  • I have updated the RELEASES.md file.

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.37%. Comparing base (10c74a1) to head (5dd8c6b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #861      +/-   ##
==========================================
- Coverage   96.86%   95.37%   -1.49%     
==========================================
  Files         128      128              
  Lines       26181    26212      +31     
==========================================
- Hits        25359    25001     -358     
- Misses        822     1211     +389     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant