Skip to content

solver: optimize the encoding of the model#51612

Merged
alalazo merged 13 commits intospack:developfrom
alalazo:solver/improve-encoding-choice
Nov 21, 2025
Merged

solver: optimize the encoding of the model#51612
alalazo merged 13 commits intospack:developfrom
alalazo:solver/improve-encoding-choice

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Nov 19, 2025

This PR is part of an on-going effort to speed up the solver. The commits are all independent, so they may be rebased and merged, rather than squashed.

The optimizations here are mostly aimed at reducing the size of the grounded problem. In particular:

  1. The condition_nodes/3 facts have been decoupled from the TriggerID and turned into condition_nodes/2. This reduces the amount of grounded rules considerably.
  2. The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to force a clear order over priorities of the guesses in the solver.

Results are the following:

radiuss.develop.csv
radiuss.pr.usc.csv

comparison

We can experiment further with heuristics in following PRs, but this seems a promising starting point.

If the node has a variant, it must have _at least_ one value

Signed-off-by: Massimiliano Culpo <[email protected]>
Version selection based on "version_satisfies" only
applies to virtual nodes.

Signed-off-by: Massimiliano Culpo <[email protected]>
Unify two rules, and keep the error with a high weight.
This reduces the size of the grounded problem.

Signed-off-by: Massimiliano Culpo <[email protected]>
This makes the grounded size of the two rules
increase like O(ndupes), instead of O(ndupes **2)

Signed-off-by: Massimiliano Culpo <[email protected]>
Decoupling condition_nodes from TriggerID greatly reduces
the grounded size of the problem, since we compute the nodes
on which another node can act, without associating them with
the rule that triggered the node lookup.

Signed-off-by: Massimiliano Culpo <[email protected]>
Conflicts very often occur within the same package.
Split the conflict rule to avoid an expensive "join"
over unification sets most of the time.

Signed-off-by: Massimiliano Culpo <[email protected]>
It turns out that "levels" are relative weights used by
the heuristics to decide which atoms to guess first.

Here we ask clingo to decide on DAG facts before guessing
on facts representing internal states.

Signed-off-by: Massimiliano Culpo <[email protected]>
@alalazo alalazo force-pushed the solver/improve-encoding-choice branch from ce6d6e9 to 9f00eed Compare November 20, 2025 07:48
@tgamblin tgamblin self-requested a review November 20, 2025 15:35
The improved encoding behaves much better with
the default "oll" tactics.

Signed-off-by: Massimiliano Culpo <[email protected]>
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Nov 20, 2025

It seems the improved encoding performs better with the default usc tactics, than with the one,1 tactics we were using before. In particular problematic specs seem much faster, and exhibit less variance. See the updated image in the description.

@alalazo alalazo added v1.0.3 PRs to backport for v1.0.3 v1.1.1 labels Nov 20, 2025
Copy link
Copy Markdown
Member

@haampie haampie left a comment

Choose a reason for hiding this comment

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

LGTM! Nice to see also the variance go down 👍

@alalazo alalazo merged commit 417913a into spack:develop Nov 21, 2025
31 of 32 checks passed
@alalazo alalazo deleted the solver/improve-encoding-choice branch November 21, 2025 08:13
psakievich pushed a commit to psakievich/spack that referenced this pull request Dec 1, 2025
The optimizations here are mostly aimed at reducing the size of the grounded problem. 

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into 
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
harshula pushed a commit to ACCESS-NRI/spack that referenced this pull request Dec 9, 2025
* Cherry-picked upstream commit 417913a

The optimizations here are mostly aimed at reducing the size of the grounded problem.

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
@becker33 becker33 mentioned this pull request Jan 10, 2026
2 tasks
becker33 pushed a commit that referenced this pull request Jan 11, 2026
The optimizations here are mostly aimed at reducing the size of the grounded problem. 

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into 
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 11, 2026
The optimizations here are mostly aimed at reducing the size of the grounded problem.

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Gregory Becker <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 12, 2026
The optimizations here are mostly aimed at reducing the size of the grounded problem.

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Gregory Becker <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 15, 2026
The optimizations here are mostly aimed at reducing the size of the grounded problem.

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Gregory Becker <[email protected]>
vjranagit pushed a commit to vjranagit/spack that referenced this pull request Jan 18, 2026
The optimizations here are mostly aimed at reducing the size of the grounded problem.

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Gregory Becker <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 22, 2026
The optimizations here are mostly aimed at reducing the size of the grounded problem.

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Gregory Becker <[email protected]>
becker33 pushed a commit that referenced this pull request Jan 26, 2026
The optimizations here are mostly aimed at reducing the size of the grounded problem.

In particular:

* The `condition_nodes/3` facts have been decoupled from the `TriggerID` and turned into
   `condition_nodes/2`. This reduces the amount of grounded rules considerably.
* The conflict rule has been split, to avoid in most cases an expensive join over unification sets

Besides that, the heuristics has been reworked, and we started using "levels". This allow us to
force a clear order over priorities of the guesses in the solver.

Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Gregory Becker <[email protected]>
@becker33
Copy link
Copy Markdown
Member

This PR does not apply cleanly to releases/v1.0, and will be dropped from v1.0.3

@becker33 becker33 removed the v1.0.3 PRs to backport for v1.0.3 label Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants