From cba347e0b77aad24bdd4f140c983f50075885e6b Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Thu, 4 Jul 2024 08:19:52 +0200 Subject: [PATCH] Heuristic decays to default over time (#45023) This modifies heuristic to decay to clingo default over time. The hope is that this helps with specs that have an optimal solution with a high penalty. Let target and compiler heuristic decay too, do not guess compiler --- lib/spack/spack/solver/asp.py | 2 +- lib/spack/spack/solver/heuristic.lp | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index 3730bc6e38..f26a83f9e2 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -95,7 +95,7 @@ def default_clingo_control(): control = clingo().Control() control.configuration.configuration = "tweety" control.configuration.solver.heuristic = "Domain" - control.configuration.solver.opt_strategy = "usc,one,1" + control.configuration.solver.opt_strategy = "usc,one" return control diff --git a/lib/spack/spack/solver/heuristic.lp b/lib/spack/spack/solver/heuristic.lp index 1f31d7eae0..a5d6767ff2 100644 --- a/lib/spack/spack/solver/heuristic.lp +++ b/lib/spack/spack/solver/heuristic.lp @@ -8,13 +8,17 @@ %============================================================================= % No duplicates by default (most of them will be true) -#heuristic attr("node", node(1..X-1, Package)) : max_dupes(Package, X), not virtual(Package), X > 1. [100, false] -#heuristic attr("virtual_node", node(1..X-1, Package)) : max_dupes(Package, X), virtual(Package) , X > 1. [100, false] +#heuristic attr("node", node(PackageID, Package)). [100, init] +#heuristic attr("node", node(PackageID, Package)). [ 2, factor] +#heuristic attr("virtual_node", node(VirtualID, Virtual)). [100, init] +#heuristic attr("node", node(1..X-1, Package)) : max_dupes(Package, X), not virtual(Package), X > 1. [-1, sign] +#heuristic attr("virtual_node", node(1..X-1, Package)) : max_dupes(Package, X), virtual(Package) , X > 1. [-1, sign] % Pick preferred version -#heuristic attr("version", node(PackageID, Package), Version) : pkg_fact(Package, version_declared(Version, 0 )), attr("node", node(PackageID, Package)). [40, true] -#heuristic attr("version", node(PackageID, Package), Version) : pkg_fact(Package, version_declared(Version, Weight)), attr("node", node(PackageID, Package)), Weight > 0. [40+5*Weight, false] -#heuristic version_weight(node(PackageID, Package), 0) : pkg_fact(Package, version_declared(Version, 0 )), attr("node", node(PackageID, Package)). [40, true] +#heuristic attr("version", node(PackageID, Package), Version) : pkg_fact(Package, version_declared(Version, Weight)), attr("node", node(PackageID, Package)). [40, init] +#heuristic version_weight(node(PackageID, Package), 0) : pkg_fact(Package, version_declared(Version, 0 )), attr("node", node(PackageID, Package)). [ 1, sign] +#heuristic attr("version", node(PackageID, Package), Version) : pkg_fact(Package, version_declared(Version, 0 )), attr("node", node(PackageID, Package)). [ 1, sign] +#heuristic attr("version", node(PackageID, Package), Version) : pkg_fact(Package, version_declared(Version, Weight)), attr("node", node(PackageID, Package)), Weight > 0. [-1, sign] % Use default variants #heuristic attr("variant_value", node(PackageID, Package), Variant, Value) : variant_default_value(Package, Variant, Value), attr("node", node(PackageID, Package)). [40, true] @@ -25,10 +29,10 @@ #heuristic attr("node_platform", node(PackageID, Package), Platform) : allowed_platform(Platform), attr("root", node(PackageID, Package)). [40, true] % Use default targets -#heuristic attr("node_target", node(PackageID, Package), Target) : target_weight(Target, 0), attr("node", node(PackageID, Package)). [30, true] -#heuristic attr("node_target", node(PackageID, Package), Target) : target_weight(Target, Weight), attr("node", node(PackageID, Package)), Weight > 0. [30, false] -#heuristic node_target_weight(node(PackageID, Package), 0) : attr("node", node(PackageID, Package)). [30, true] +#heuristic attr("node_target", node(PackageID, Package), Target) : target_weight(Target, Weight), attr("node", node(PackageID, Package)). [30, init] +#heuristic attr("node_target", node(PackageID, Package), Target) : target_weight(Target, Weight), attr("node", node(PackageID, Package)). [ 2, factor] +#heuristic attr("node_target", node(PackageID, Package), Target) : target_weight(Target, 0), attr("node", node(PackageID, Package)). [ 1, sign] +#heuristic attr("node_target", node(PackageID, Package), Target) : target_weight(Target, Weight), attr("node", node(PackageID, Package)), Weight > 0. [-1, sign] % Use the default compilers -#heuristic node_compiler(node(0, Package), ID) : compiler_weight(ID, 0) , compiler_id(ID), attr("node", node(0, Package)). [30, true] -#heuristic node_compiler(node(0, Package), ID) : compiler_weight(ID, Weight), compiler_id(ID), attr("node", node(0, Package)), Weight > 0. [30, false] +#heuristic node_compiler(node(PackageID, Package), ID) : compiler_weight(ID, 0), compiler_id(ID), attr("node", node(PackageID, Package)). [30, init]