Fix-dist fit upper bound - #133
Open
ishikaghosh2201 wants to merge 3 commits into
Open
ishikaghosh2201 wants to merge 3 commits into
ishikaghosh2201 wants to merge 3 commits into
Conversation
ishikaghosh2201
requested review from
lizliz
and
a balanced review from Copilot
October 3, 2026 04:03
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
solve_ilp_dist()(incereeberus/distance/ilp.py) built its constraints by iterating over the union of both graphs' function values. It assumed every level had boundary, assignment and distance blocks for the starting graph. When the two graphs have different ranges (for exampleG = F.smoothing(n), which extends[0..3]to[-1..4]), the solver looked up a block that doesn't exist and raisedKeyError.Changes:
ilp.py/solve_ilp_dist()if block not in myAssgn.all_func_vals(map=starting_map): continue.all_func_vals(map=starting_map)[-1]), not the top of the combined range.solve_ilp()already handles this.block + 1lookup is safe because the top level is skipped. No other changes were needed.interleave.py/Interleave.dist_fit()best_bound = n + lossand tighten the binary search's upper end withhigh = min(high, best_bound - 1)after each nonzero-loss trial, so the search narrows faster.TestDistOptimizeUnequalRangetotests/test_interleaving.py.blackon the changed files.Motivation and Context
Fixes #132
Minimal reproduction:
The feasibility path finds a zero-loss 1-interleaving, so the expected result is 0.
Interleave(F, G).dist_fit()failed the same way.How has this been tested?
TestDistOptimizeUnequalRange:test_graph_vs_smoothing:line(0,3)against its 1-smoothing, in both orders. Checks thatoptimize()succeeds withloss() == 0, thatdist_optimize() == 0, and thatdist_fit() == 1.test_offset_ranges:line(0,3)againstline(1,5)withn=2. Checks thatdist_optimize() == 0.masterwithKeyErrorand pass with this change.dist_optimize()agrees withoptimize()/loss(), anddist_fit()withfit(), on these pairs:line(0,3)withline(1,5)line(0,3)withline(2,4)simple_loopswith its smoothingtests/test_interleaving.pypass, and the rest of the suite is unaffected.LpVariable.dicts, which breaks both ILP solvers, so testing usedpulp<4. This should probably be pinned in a separate PR.Types of changes
Checklist
pyproject.tomlfile if a new version needs to be pushed to pypi. Note that if the number isn't incremented, the package will not be pushed to pypi, which is useful if this PR is only for updating documentation.make formatto clean up the code withblack.make tests).