Skip to content

BE-514: HashQL: implement iterative adjustment passes in placement solver#8635

Merged
indietyp merged 14 commits into
mainfrom
bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence
May 29, 2026
Merged

BE-514: HashQL: implement iterative adjustment passes in placement solver#8635
indietyp merged 14 commits into
mainfrom
bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence

Conversation

@indietyp
Copy link
Copy Markdown
Member

🌟 What is the purpose of this PR?

This PR enhances the placement solver in the MIR dataflow analysis framework by implementing iterative adjustment passes that alternate direction until convergence. Instead of a simple two-pass approach (forward then backward), the solver now continues refining assignments in alternating directions until no further improvements are found, converging to a better local minimum.

🔍 What does this change?

  • Adds a reverse() method to the Direction enum to toggle between Forward and Backward directions
  • Replaces the single backward refinement pass with iterative adjustment passes that alternate direction until convergence
  • Modifies adjust_trivial() and adjust_cyclic() methods to return boolean flags indicating whether assignments changed
  • Introduces a new run_adjustment() method that processes regions in the specified direction and tracks changes
  • Updates documentation to reflect the new iterative convergence approach rather than the previous two-pass strategy

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🛡 What tests cover this?

  • Existing placement solver tests continue to validate the functionality
  • Updated test in backward_pass_keeps_assignment_when_csp_fails() to handle the new return signature

❓ How to test this?

  1. Checkout the branch
  2. Run the existing MIR placement solver tests
  3. Confirm that placement optimization still works correctly with the new iterative approach

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview, Comment May 28, 2026 1:35pm
petrinaut Ready Ready Preview May 28, 2026 1:35pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
hashdotdesign Ignored Ignored Preview May 28, 2026 1:35pm
hashdotdesign-tokens Ignored Ignored Preview May 28, 2026 1:35pm

Copy link
Copy Markdown
Member Author

indietyp commented Apr 16, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown
Member Author

remind me to add a test case for the reason this fails before merging:

3-node chain A → B → C:

 - Unary costs: u_A(0)=3, u_A(1)=0; u_B(0)=u_B(1)=0; u_C(0)=0
 - Edge costs: A–B mismatch cost 2, B–C mismatch cost 1
 - Start from labeling 000

Backward sweep (sinks first): C stays 0, B stays 0 (given A=0, C=0), A switches to 1 (given B=0). Final: 1,0,0.

But changing only B from 0 to 1 lowers total cost — so the result after one sweep is not a 1-opt local minimum.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 91.78082% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.10%. Comparing base (a8da2f8) to head (798b079).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
...shql/mir/src/pass/transform/inline/loop_breaker.rs 90.00% 9 Missing and 4 partials ⚠️
...l/mir/src/pass/analysis/data_dependency/resolve.rs 93.33% 1 Missing and 3 partials ⚠️
...@local/hashql/mir/src/pass/transform/inline/mod.rs 89.65% 1 Missing and 2 partials ⚠️
...hashql/mir/src/pass/transform/inst_simplify/mod.rs 0.00% 2 Missing ⚠️
...shql/mir/src/pass/execution/placement/solve/mod.rs 97.87% 1 Missing ⚠️
...local/hashql/mir/src/pass/transform/inline/find.rs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8635      +/-   ##
==========================================
+ Coverage   59.04%   59.10%   +0.05%     
==========================================
  Files        1341     1342       +1     
  Lines      129387   129587     +200     
  Branches     5837     5851      +14     
==========================================
+ Hits        76398    76587     +189     
- Misses      52088    52096       +8     
- Partials      901      904       +3     
Flag Coverage Δ
apps.hash-ai-worker-ts 1.41% <ø> (ø)
apps.hash-api 0.00% <ø> (ø)
local.hash-backend-utils 2.81% <ø> (ø)
local.hash-graph-sdk 9.63% <ø> (ø)
local.hash-isomorphic-utils 0.00% <ø> (ø)
rust.hash-graph-api 2.52% <ø> (ø)
rust.hashql-compiletest 28.26% <ø> (ø)
rust.hashql-eval 75.69% <ø> (ø)
rust.hashql-mir 86.84% <91.78%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 16, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks
⏩ 56 skipped benchmarks1


Comparing bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence (798b079) with bm/be-500-hashql-forward-substitution-unified-param-resolution (a6a0edb)2

Open in CodSpeed

Footnotes

  1. 56 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on bm/be-500-hashql-forward-substitution-unified-param-resolution (53acbb7) during the generation of this report, so 266df53 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@indietyp indietyp marked this pull request as ready for review April 29, 2026 15:42
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 29, 2026

PR Summary

Medium Risk
Changes how execution targets are chosen across the MIR placement pass; incorrect convergence or cost-mode wiring could shift runtime placement without obvious compile errors.

Overview
Replaces the placement solver’s single backward refinement pass with iterative adjustment passes that walk regions in alternating directions (backward, forward, …) until no region assignment changes, aiming for a better local minimum with fuller boundary context.

Adds Direction::reverse() for the dataflow framework and a new run_adjustment path that drives trivial and cyclic re-evaluation via adjust_trivial / adjust_cyclic, which now report whether anything changed. Cyclic solving gains ConstraintSatisfactionMode (Initial vs Adjustment), mapping to CostEstimationConfig::LOOP during forward/initial CSP work and TRIVIAL during adjustments; forward pass and rewind still use Initial mode.

Reviewed by Cursor Bugbot for commit 798b079. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 211c141. Configure here.

Comment thread libs/@local/hashql/mir/src/pass/execution/placement/solve/mod.rs
@graphite-app graphite-app Bot requested review from a team April 29, 2026 15:48
@indietyp indietyp force-pushed the bm/be-500-hashql-forward-substitution-unified-param-resolution branch from 93fba40 to ffe8840 Compare April 29, 2026 15:51
@indietyp indietyp force-pushed the bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence branch from 211c141 to 080f3e8 Compare April 29, 2026 15:51
@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Apr 29, 2026

🤖 Augment PR Summary

Summary: Enhances the HashQL MIR placement solver by iterating adjustment passes (alternating direction) until assignments stop improving, instead of doing a single backward refinement.

Changes:

  • Added Direction::reverse() to toggle between forward and backward traversal.
  • Introduced ConstraintSatisfactionMode to switch CSP cost-estimation weighting between initial solving and later adjustments.
  • Updated PlacementSolver::run_in to run the forward pass once, then repeat adjustment passes (backward/forward/…) until a pass makes no assignment changes.
  • Refactored adjust_trivial / adjust_cyclic to return whether they changed assignments, and used this to drive convergence.
  • Updated CSP/solver tests for the new constructor signature and return values.

Technical Notes: Adjustment solving for cyclic regions now evaluates candidates with full boundary weighting (via TRIVIAL) and threads this choice through CSP cost estimation via the new mode.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread libs/@local/hashql/mir/src/pass/execution/placement/solve/mod.rs
@indietyp indietyp force-pushed the bm/be-500-hashql-forward-substitution-unified-param-resolution branch from ffe8840 to f3d71ce Compare April 30, 2026 08:53
@indietyp indietyp force-pushed the bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence branch from 080f3e8 to 0ca8770 Compare April 30, 2026 08:53
@indietyp indietyp force-pushed the bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence branch from 0ca8770 to b02766e Compare April 30, 2026 09:02
@indietyp indietyp force-pushed the bm/be-500-hashql-forward-substitution-unified-param-resolution branch from f3d71ce to b0024c0 Compare April 30, 2026 09:02
@indietyp indietyp force-pushed the bm/be-500-hashql-forward-substitution-unified-param-resolution branch from b0024c0 to ff39943 Compare April 30, 2026 09:04
@indietyp indietyp force-pushed the bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence branch from b02766e to f2b4e96 Compare April 30, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests type/eng > backend Owned by the @backend team

Development

Successfully merging this pull request may close these issues.

2 participants