Skip to content

fix: RE91 solution creation and dominance fast-path correctness - #194

Merged
cbarba merged 10 commits into
jMetal:mainfrom
rgallegocode:fix/release-1.10-review
Nov 18, 2026
Merged

cbarba merged 10 commits into
jMetal:mainfrom
rgallegocode:fix/release-1.10-review

Conversation

@rgallegocode

Copy link
Copy Markdown

Fixes found while reviewing the 1.10 release.

Changes

  • RE91 create_solution (src/jmetal/problem/multiobjective/re.py): the random variables (indices 7-10) have infinite bounds, so sampling them gave NaN (random.uniform) or raised OverflowError (Generator.uniform). The previous reset to 0.0 had no effect because FloatSolution.variables returns a copy. Now only the 7 decision variables are sampled and the whole list is assigned.
  • Comparator subclasses in fast paths (src/jmetal/util/ranking.py, src/jmetal/util/archive.py): FastNonDominatedRanking and the non-dominated archives chose their vectorized/moocore paths with isinstance, so subclasses such as GDominanceComparator were silently treated as plain Pareto dominance. They now require the exact DominanceComparator type.
  • NonDominatedSolutionsArchive.add_batch duplicates (src/jmetal/util/archive.py): it kept exact and near-duplicate solutions (within objective_tolerance) that add() rejects. It now drops them and prefers solutions already in the archive.

Each fix has its own regression tests (tests/problem/multiobjective/test_re91.py, tests/util/test_g_dominance_fast_paths.py, tests/util/test_archive.py).

Verification

  • ruff check src/ tests/ examples/: clean.
  • Tests for the affected modules (RE91, archive, ranking, g-dominance): 77 passed.
  • The full suite was not run to completion locally; relying on the test CI workflow.

Roberto Gallego Barbarán and others added 6 commits November 16, 2026 11:38
The random variables (indices 7-10) have infinite bounds, so sampling them
gave NaN with random.uniform or raised OverflowError with Generator.uniform.
The previous reset to 0.0 had no effect because FloatSolution.variables
returns a copy. Sample the 7 decision variables and assign the whole list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sses

FastNonDominatedRanking and the non-dominated archives used isinstance()
to pick their vectorized/moocore paths, so DominanceComparator subclasses
such as GDominanceComparator were silently ranked with plain Pareto
dominance. Require the exact DominanceComparator type instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…atch

add_batch() kept every non-dominated row, so exact and near-duplicate
solutions (within objective_tolerance) that add() rejects ended up in the
archive. Keep weakly non-dominated rows and drop duplicates, preferring
solutions already in the archive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cbarba

cbarba commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for these fixes, all three bugs are real. I ran the full suite locally on this branch, both on its own and merged with #193. Everything passes and ruff is clean. But one change makes something much slower, so I'd like that fixed before merging.

Good to go

  • RE91 create_solution: right diagnosis and right fix. The infinite bounds gave NaN or OverflowError, and the old solution.variables[i] = 0.0 did nothing because variables returns a copy.
  • type(...) is DominanceComparator instead of isinstance: agreed. GDominanceComparator was silently treated as plain Pareto dominance in FastNonDominatedRanking and in both archives. The regression tests in test_g_dominance_fast_paths.py cover it well.

Needs changes: duplicate filtering in NonDominatedSolutionsArchive.add_batch

Making add_batch reject the same (near-)duplicates as add() is correct. The problem is how it's done:

for index in np.flatnonzero(keep):
    if kept_indices and np.any(np.all(np.abs(objectives[kept_indices] - objectives[index]) <= self.objective_tolerance, axis=1)):

This is a Python loop that runs one NumPy operation per kept solution against all the solutions kept so far. Its cost grows with the square of the number of solutions, in the method that exists to avoid exactly that. On my machine:

Test main this PR
test_nsgaii_integration.py::...::test_should_reach_the_expected_hypervolume_on_dtlz2_with_an_unbounded_archive 1.55 s 172.8 s

That's about 110x slower, and the whole suite goes from ~25 s to ~200 s. Any real run that uses an unbounded archive on a many-objective problem would see the same slowdown.

Some options:

  • Handle exact duplicates without a Python loop (e.g. np.unique(objectives[keep], axis=0, return_index=True), keeping the lowest index so solutions already in the archive win). Then only take the slow tolerance check when there's actually something to check, or check only neighbours after a lexicographic sort.
  • Or move this third fix to its own PR, so the RE91 and comparator fixes can be merged now.

Whichever you choose, it would help to run the full make test locally, since the slowdown only shows up in the integration tests.

Minor

  • The new AddBatchDuplicatesTestCases class in tests/util/test_archive.py comes after the if __name__ == "__main__": unittest.main() block. Could you move it above, and preferably write it as a pytest class Test...: with @pytest.mark.parametrize over the archive classes, following CODING_GUIDELINES.md?
  • Heads-up: perf(util): defer vectorized archive fast path #193 touches VectorizedNonDominatedSolutionsArchive too. The two merge cleanly, but its add_batch still uses isinstance(self.comparator, DominanceComparator). Whichever PR lands second should switch it to type(...) is for consistency. Results aren't affected, because add() checks the type first.

Roberto Gallego Barbarán added 2 commits November 17, 2026 08:52
The near-duplicate filter in NonDominatedSolutionsArchive.add_batch
compared each kept row against all rows kept so far in a Python loop,
which made the DTLZ2 unbounded-archive integration test ~110x slower.

Remove exact duplicates with np.unique (lowest index wins), then sort
by a weighted sum of the objectives so near-duplicates end up next to
each other, and only run the tolerance check inside those small groups.
The result is the same as the previous loop.
Move the duplicate tests above the __main__ block, rewrite them as a
pytest class parametrized over both archive classes, and cover chains
of near-duplicates, a shared coordinate and a linear front.
@rgallegocode

Copy link
Copy Markdown
Author

Thanks for catching this. I took the first option:

  • Exact duplicates are removed with np.unique(..., return_index=True). The lowest index wins, so solutions already in the archive are kept.
  • For near-duplicates, the rows are sorted by a weighted sum of the objectives. Rows within objective_tolerance of each other always end up next to each other in that order, so the tolerance check only runs inside small groups of neighbours. The weights are deliberately uneven, so linear fronts (e.g. DTLZ1) and objectives that are always 0 don't fall back to the full pairwise check.

It gives exactly the same result as the previous loop: I compared the two on 3000 random batches full of exact and near-duplicates (2–5 objectives).

Timings on my machine, which is slower than yours overall:

Measurement main this PR (updated)
test_should_reach_the_expected_hypervolume_on_dtlz2_with_an_unbounded_archive 13.35 s 13.77 s
Duplicate filtering alone, 20 000 solutions × 5 objectives (one objective fixed at 0) — 0.04 s

So the integration test now takes the same time as on main, and the ~110x slowdown you measured (1.55 s → 172.8 s) is gone. Full make test on this branch: 1175 passed, 1 failed, in 195.7 s. I didn't time the full suite on main on this machine. The failure is tests/lab/test_experiment.py::TestExperimentRun::test_should_propagate_an_exception_raised_inside_a_job, a FileNotFoundError in the multi-process run on Windows. It fails the same way on main here, so it isn't caused by this PR. ruff check is clean.

The duplicate tests are now a pytest TestAddBatchDuplicates class above the __main__ block, parametrized over both archive classes. It covers exact and near-duplicates, a chain of near-duplicates, three objectives that share a value, and a linear front.

Roberto Gallego Barbarán added 2 commits November 17, 2026 09:00
VectorizedNonDominatedSolutionsArchive.add_batch, added in jMetal#193, still
used isinstance(), unlike the other default-comparator fast paths.
Results were unaffected because add() already checks the exact type.
@rgallegocode

Copy link
Copy Markdown
Author

Since #193 landed first, I merged main into this branch and switched VectorizedNonDominatedSolutionsArchive.add_batch from isinstance(self.comparator, DominanceComparator) to type(self.comparator) is DominanceComparator, matching the other fast paths.

After the merge, ruff check is clean and the full suite gives 1176 passed, 1 failed in 173.7 s. The failure is the same Windows-only test_experiment.py failure that also happens on main. The DTLZ2 unbounded-archive test takes 12.34 s on my machine; on main it took 13.35 s here.

@cbarba
cbarba merged commit 1fc0d4f into jMetal:main Nov 18, 2026
7 checks passed
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