spack.solver package

Submodules

spack.solver.asp module

class spack.solver.asp.ConcreteSpecsByHash[source]

Bases: Mapping

Mapping containing concrete specs keyed by DAG hash.

The mapping is ensured to be consistent, i.e. if a spec in the mapping has a dependency with hash X, it is ensured to be the same object in memory as the spec keyed by X.

add(spec: Spec) bool[source]

Adds a new concrete spec to the mapping. Returns True if the spec was just added, False if the spec was already in the mapping.

Calling this function marks the spec as added explicitly.

Parameters:

spec – spec to be added

Raises:

ValueError – if the spec is not concrete

data: Dict[str, Spec]
explicit: Set[str]
explicit_items() Iterator[Tuple[str, Spec]][source]

Iterate on items that have been added explicitly, and not just as a dependency of other nodes.

class spack.solver.asp.ConcretizationCache(root: str | None = None)[source]

Bases: object

Store for Spack concretization results and statistics

Serializes solver result objects and statistics to json and stores at a given endpoint in a cache associated by the sha256 of the asp problem and the involved control files.

cache_entries()[source]

Generator producing cache entries within a bucket

cleanup()[source]

Prunes the concretization cache according to configured entry count limits. Cleanup is done in LRU ordering.

fetch(problem: str) Tuple[Result, Dict] | Tuple[None, None][source]

Returns the concretization cache result for a lookup based on the given problem.

Checks the concretization cache for the given problem, and either returns the Python objects cached on disk representing the concretization results and statistics or returns none if no cache entry was found.

read_transaction(path: Path, timeout: float | None = None) ReadTransaction[source]

Read transactions for concretization cache entries.

Parameters:
  • path – absolute or relative path to the concretization cache entry to be locked

  • timeout – give up after this many seconds

store(problem: str, result: Result, statistics: List) None[source]

Creates entry in concretization cache for problem if none exists, storing the concretization Result object and statistics in the cache as serialized json joined as a single file.

Hash membership is computed based on the sha256 of the provided asp problem.

write_transaction(path: Path, timeout: float | None = None) WriteTransaction[source]

Write transactions for concretization cache entries

Parameters:
  • path – absolute or relative path to the concretization cache entry to be locked

  • timeout – give up after this many seconds

class spack.solver.asp.ConditionContext[source]

Bases: SourceContext

Tracks context in which a condition (i.e. SpackSolverSetup.condition) is generated (e.g. for a depends_on).

This may modify the required/imposed specs generated as relevant for the context.

impose_context() ConditionIdContext[source]
requirement_context() ConditionIdContext[source]
transform_imposed: Callable[[str, Spec, List[AspFunction]], List[AspFunction]] | None
transform_required: Callable[[str, Spec, List[AspFunction]], List[AspFunction]] | None
wrap_node_requirement: bool | None
class spack.solver.asp.ConditionIdContext[source]

Bases: SourceContext

Derived from a ConditionContext: for clause-sets generated by imposed/required specs, stores an associated transform.

This is primarily used for tracking whether we are generating clauses in the context of a required spec, or for an imposed spec.

Is not a subclass of ConditionContext because it exists in a lower-level context with less information.

transform: Callable[[str, Spec, List[AspFunction]], List[AspFunction]] | None
class spack.solver.asp.ConstraintOrigin(*values)[source]

Bases: Enum

Generates identifiers that can be passed into the solver attached to constraints, and then later retrieved to determine the origin of those constraints when SpecBuilder creates Specs from the solve result.

CONDITIONAL_SPEC
DEPENDS_ON
REQUIRE
static append_type_suffix(pkg_id: str, kind: ConstraintOrigin) str[source]

Given a package identifier and a constraint kind, generate a string ID.

static strip_type_suffix(source: str) Tuple[int, str | None][source]

Take a combined package/type ID generated by append_type_suffix, and extract the package ID and an associated weight.

spack.solver.asp.DEFAULT_OUTPUT_CONFIGURATION

Default output configuration for a solve

exception spack.solver.asp.DeprecatedVersionError(message: str, long_message: str | None = None)[source]

Bases: SpackError

Raised when user directly requests a deprecated version.

class spack.solver.asp.ErrorHandler(model, input_specs: List[Spec])[source]

Bases: object

get_cause_tree(cause: Tuple[str, str]) List[str][source]

Get the cause tree associated with the given cause.

Parameters:

cause – The root cause of the tree (final condition)

Returns:

A list of strings describing the causes, formatted to display tree structure.

handle_error(msg, *args)[source]

Handle an error state derived by the solver.

message(errors) str[source]
multiple_values_error(attribute, pkg)[source]
no_value_error(attribute, pkg)[source]
raise_if_errors()[source]
exception spack.solver.asp.InternalConcretizerError(msg)[source]

Bases: UnsatisfiableSpecError

Errors that indicate a bug in Spack.

exception spack.solver.asp.InvalidDependencyError(message: str, long_message: str | None = None)[source]

Bases: SpackError

Raised when an explicit dependency is not a possible dependency.

exception spack.solver.asp.InvalidExternalError(message: str, long_message: str | None = None)[source]

Bases: SpackError

Raised when there is no possible compiler

exception spack.solver.asp.InvalidSpliceError(message: str, long_message: str | None = None)[source]

Bases: SpackError

For cases in which the splice configuration is invalid.

exception spack.solver.asp.InvalidVersionError(message: str, long_message: str | None = None)[source]

Bases: SpackError

Raised when a version can’t be satisfied by any possible versions.

exception spack.solver.asp.NoCompilerFoundError(message: str, long_message: str | None = None)[source]

Bases: SpackError

Raised when there is no possible compiler

class spack.solver.asp.OptimizationCriteria(priority: int, value: int, name: str, kind: OptimizationKind)[source]

Bases: NamedTuple

A named tuple describing an optimization criteria.

kind: OptimizationKind

Alias for field number 3

name: str

Alias for field number 2

priority: int

Alias for field number 0

value: int

Alias for field number 1

class spack.solver.asp.OptimizationKind[source]

Bases: object

Enum for the optimization KIND of a criteria.

It’s not using enum.Enum since it must be serializable.

BUILD
CONCRETE
OTHER
class spack.solver.asp.OutputConfiguration(timers: bool, stats: bool, out: IOBase | None, setup_only: bool)[source]

Bases: NamedTuple

Data class that contains configuration on what a clingo solve should output.

out: IOBase | None

Optional output stream for the generated ASP program

setup_only: bool

If True, stop after setup and don’t solve

stats: bool

Whether to output Clingo’s internal solver statistics

timers: bool

Print out coarse timers for different solve phases

exception spack.solver.asp.OutputDoesNotSatisfyInputError(input_to_output: List[Tuple[Spec, Spec | None]])[source]

Bases: InternalConcretizerError

class spack.solver.asp.ProblemInstanceBuilder[source]

Bases: object

Provides an interface to construct a problem instance.

Once all the facts and rules have been added, the problem instance can be retrieved with:

>>> builder = ProblemInstanceBuilder()
>>> ...
>>> problem_instance = builder.value()

The problem instance can be added directly to the “control” structure of clingo.

append(rule: str) None[source]
asp_problem: List[str]
fact(atom: AspFunction) None[source]
h1(header: str) None[source]
h2(header: str) None[source]
h3(header: str)[source]
newline()[source]
title(header: str, char: str) None[source]
class spack.solver.asp.PyclingoDriver(conc_cache: ConcretizationCache | None = None)[source]

Bases: object

control: Any
solve(setup: SpackSolverSetup, specs: List[Spec], reuse: List[Spec] | None = None, packages_with_externals=None, output: OutputConfiguration | None = None, control: Any | None = None, allow_deprecated: bool = False) Tuple[Result, Timer | None, Dict | None][source]

Set up the input and solve for dependencies of specs.

Parameters:
  • setup – An object to set up the ASP problem.

  • specs – List of Spec objects to solve for.

  • reuse – list of concrete specs that can be reused

  • output – configuration object to set the output of this solve.

  • control – configuration for the solver. If None, default values will be used

  • allow_deprecated – if True, allow deprecated versions in the solve

Returns:

A tuple of the solve result, the timer for the different phases of the solve, and the internal statistics from clingo.

class spack.solver.asp.Result(specs)[source]

Bases: object

Result of an ASP solve.

static format_unsolved(unsolved_specs)[source]

Create a message providing info on unsolved user specs and for each one show the associated candidate spec from the solver (if there is one).

static from_dict(obj: dict)[source]

Returns Result object from compatible dictionary

raise_if_unsat()[source]

Raise a generic internal error if the result is unsatisfiable.

property specs

List of concretized specs satisfying the initial abstract request.

property specs_by_input: Dict[Spec, Spec]
to_dict() dict[source]

Produces dict representation of Result object

Does not include anything related to unsatisfiability as we are only interested in storing satisfiable results

property unsolved_specs

List of tuples pairing abstract input specs that were not solved with their associated candidate spec from the solver (if the solve completed).

class spack.solver.asp.Solver(*, specs_factory: Callable[[Callable[[Spec], bool], Configuration], List[SpecFilter]] | None = None)[source]

Bases: object

This is the main external interface class for solving.

It manages solver configuration and preferences in one place. It sets up the solve and passes the setup method to the driver, as well.

solve(specs: Sequence[Spec], **kwargs) Result[source]

Convenience function for concretizing a set of specs and ignoring timing and statistics. Uses the same kwargs as solve_with_stats.

solve_in_rounds(specs: Sequence[Spec], out: IOBase | None = None, timers: bool = False, stats: bool = False, tests: bool | Iterable[str] = False, allow_deprecated: bool = False) Generator[Result, None, None][source]

Solve for a stable model of specs in multiple rounds.

This relaxes the assumption of solve that everything must be consistent and solvable in a single round. Each round tries to maximize the reuse of specs from previous rounds.

The function is a generator that yields the result of each round.

Parameters:
  • specs (list) – list of Specs to solve.

  • out – Optionally write the generate ASP program to a file-like object.

  • timers (bool) – print timing if set to True

  • stats (bool) – print internal statistics if set to True

  • tests (bool) – add test dependencies to the solve

  • allow_deprecated (bool) – allow deprecated version in the solve

solve_with_stats(specs: Sequence[Spec], out: IOBase | None = None, timers: bool = False, stats: bool = False, tests: bool | Iterable[str] = False, setup_only: bool = False, allow_deprecated: bool = False) Tuple[Result, Timer | None, Dict | None][source]

Concretize a set of specs and track the timing and statistics for the solve

Parameters:
  • specs – List of Spec objects to solve for.

  • out – Optionally write the generate ASP program to a file-like object.

  • timers – Print out coarse timers for different solve phases.

  • stats – Print out detailed stats from clingo.

  • tests – If True, concretize test dependencies for all packages. If a tuple of package names, concretize test dependencies for named packages (defaults to False: do not concretize test dependencies).

  • setup_only – if True, stop after setup and don’t solve (default False).

  • allow_deprecated – allow deprecated version in the solve

exception spack.solver.asp.SolverError(provided)[source]

Bases: InternalConcretizerError

For cases where the solver is unable to produce a solution.

Such cases are unexpected because we allow for solutions with errors, so for example user specs that are over-constrained should still get a solution.

class spack.solver.asp.SpackSolverSetup(tests: bool | Iterable[str] = False)[source]

Bases: object

Class to set up and run a Spack concretization solve.

collect_virtual_constraints()[source]

Define versions for constraints on virtuals.

Must be called before define_version_constraints().

compiler_mixing()[source]
concrete_specs()[source]

Emit facts for reusable specs

condition(required_spec: Spec, imposed_spec: Spec | None = None, *, required_name: str | None = None, imposed_name: str | None = None, msg: str | None = None, context: ConditionContext | None = None) int[source]

Generate facts for a dependency or virtual provider condition.

Parameters:
  • required_spec – the constraints that triggers this condition

  • imposed_spec – the constraints that are imposed when this condition is triggered

  • required_name – name for required_spec (required if required_spec is anonymous, ignored if not)

  • imposed_name – name for imposed_spec (required if imposed_spec is anonymous, ignored if not)

  • msg – description of the condition

  • context – if provided, indicates how to modify the clause-sets for the required/imposed specs based on the type of constraint they are generated for (e.g. depends_on)

Returns:

id of the condition created by this function

Return type:

int

config_compatible_os()[source]

Facts about compatible os’s specified in configs

conflict_rules(pkg)[source]
default_targets: List
define_ad_hoc_versions_from_specs(specs, origin, *, allow_deprecated: bool, require_checksum: bool)[source]

Add concrete versions to possible versions from lists of CLI/dev specs.

define_auto_variant(name: str, multi: bool)[source]
define_concrete_input_specs(specs: tuple, possible: set)[source]
define_package_versions_and_validate_preferences(possible_pkgs: Set[str], *, require_checksum: bool, allow_deprecated: bool)[source]

Declare any versions in specs not declared in packages.

define_runtime_constraints() List[Spec][source]

Define the constraints to be imposed on the runtimes, and returns a list of injected packages.

define_target_constraints()[source]
define_variant(pkg: Type[PackageBase], name: str, when: Spec, variant_def: Variant)[source]
define_variant_values()[source]

Validate variant values from the command line.

Add valid variant values from the command line to the possible values for variant definitions.

define_version_constraints()[source]

Define what version_satisfies(…) means in ASP logic.

deprecated_versions: Dict[str, Set[GitVersion | StandardVersion]]
effect_rules()[source]

Flushes all the effect rules collected so far, and clears the cache.

emit_facts_from_requirement_rules(rules: List[RequirementRule])[source]

Generate facts to enforce requirements.

Parameters:

rules – rules for which we want facts to be emitted

enable_splicing: bool
explicitly_required_namespaces: Dict[str, str]
external_packages(packages_with_externals)[source]

Facts on external packages, from packages.yaml and implicit externals.

gen: ProblemInstanceBuilder
generate_conditional_dep_conditions(spec: Spec, condition_id: int)[source]

Generate a subcondition in the trigger for any conditional dependencies.

Dependencies are always modeled by a condition. For conditional dependencies, the when-spec is added as a subcondition of the trigger to ensure the dependency is only activated when the subcondition holds.

git_commit_versions: Dict[str, Dict[GitVersion | StandardVersion, str]]
impossible_dependencies_check(specs) None[source]
input_spec_version_check(specs, allow_deprecated: bool) None[source]

Raise an error early if no versions available in the solve can satisfy the inputs.

libcs: List[Spec]
literal_specs(specs)[source]
os_defaults(specs)[source]
package_dependencies_rules(pkg)[source]

Translate depends_on directives into ASP logic.

package_provider_rules(pkg: Type[PackageBase]) None[source]
package_requirement_rules(pkg)[source]
package_splice_rules(pkg)[source]
pkg_class(pkg_name: str) Type[PackageBase][source]
pkg_rules(pkg, tests)[source]
pkg_version_rules(pkg: Type[PackageBase]) None[source]

Declares known versions, their origins, and their weights.

pkgs: Set[str]
platform_defaults()[source]
possible_compilers: List[Spec]
possible_oses: Set
possible_versions: Dict[str, Dict[GitVersion | StandardVersion, List[Provenance]]]
possible_virtuals: Set[str]
preferred_variants(pkg_name)[source]

Facts on concretization preferences, as read from packages.yaml

register_concrete_spec(spec, possible: set)[source]
rejected_compilers: Set[Spec]
reusable_and_possible: ConcreteSpecsByHash
setup(specs: Sequence[Spec], *, reuse: List[Spec] | None = None, packages_with_externals=None, allow_deprecated: bool = False) ProblemInstanceBuilder[source]

Generate an ASP program with relevant constraints for specs.

This calls methods on the solve driver to set up the problem with facts and rules from all possible dependencies of the input specs, as well as constraints from the specs themselves.

Parameters:
  • specs – list of Specs to solve

  • reuse – list of concrete specs that can be reused

  • packages_with_externals – precomputed packages config with implicit externals

  • allow_deprecated – if True adds deprecated versions into the solve

Returns:

A ProblemInstanceBuilder populated with facts and rules for an ASP solve.

spec_clauses(spec: Spec, *, name: str | None = None, body: bool = False, transitive: bool = True, expand_hashes: bool = False, concrete_build_deps=False, include_runtimes=False, required_from: str | None = None, context: SourceContext | None = None) List[AspFunction][source]

Wrap a call to _spec_clauses() into a try/except block with better error handling.

Arguments are as for _spec_clauses() except required_from.

Parameters:

required_from – name of package that caused this call.

spec_versions(spec: Spec, *, name: str | None = None) List[AspFunction][source]

Return list of clauses expressing spec’s version constraints.

target_constraints: Set
target_defaults(specs)[source]

Add facts about targets and target compatibility.

target_preferences()[source]
target_ranges(spec: Spec, single_target_fn, *, name: str | None = None) List[AspFunction][source]
trigger_rules()[source]

Flushes all the trigger rules collected so far, and clears the cache.

validate_and_define_versions_from_requirements(*, allow_deprecated: bool, require_checksum: bool)[source]

If package requirements mention concrete versions that are not mentioned elsewhere, then we need to collect those to mark them as possible versions. If they are abstract and statically have no match, then we need to throw an error. This function assumes all possible versions are already registered in self.possible_versions.

variant_ids_by_def_id: Dict[int, int]
variant_rules(pkg: Type[PackageBase])[source]
variant_values_from_specs: Set
version_constraints: Dict[str, Set]
versions_from_yaml: Dict[str, List[GitVersion | StandardVersion]]
virtual_requirements_and_weights()[source]
class spack.solver.asp.SpecBuilder(specs, hash_lookup=None)[source]

Bases: object

Class with actions to rebuild a spec from ASP results.

build_specs(function_tuples: List[Tuple[str, Tuple[str | NodeId, ...]]]) List[Spec][source]
depends_on(parent_node, dependency_node, type)[source]
deprecated(node: NodeId, version: str) None[source]
execute_explicit_splices()[source]
hash(node, h)[source]
ignored_attributes

Regex for attributes that don’t need actions b/c they aren’t used to construct specs.

static make_node(*, pkg: str) NodeId[source]

Given a package name, returns the string representation of the “min_dupe_id” node in the ASP encoding.

Parameters:

pkg – name of a package

namespace(node, namespace)[source]
node(node)[source]
node_flag(node, node_flag)[source]
node_os(node, os)[source]
node_platform(node, platform)[source]
node_target(node, target)[source]
reorder_flags()[source]

For each spec, determine the order of compiler flags applied to it.

The solver determines which flags are on nodes; this routine imposes order afterwards. The order is:

  1. Flags applied in compiler definitions should come first

  2. Flags applied by dependents are ordered topologically (with a dependency on traverse to resolve the partial order into a stable total order)

  3. Flags from requirements are then applied (requirements always come from the package and never a parent)

  4. Command-line flags should come last

Additionally, for each source (requirements, compiler, command line, and dependents), flags from that source should retain their order and grouping: e.g. for y cflags="-z -a" -z and -a should never have any intervening flags inserted, and should always appear in that order.

splice_at_hash(parent_node: NodeId, splice_node: NodeId, child_name: str, child_hash: str)[source]
variant_selected(node, name: str, value: str, variant_type: str, variant_id)[source]
version(node, version)[source]
virtual_on_edge(parent_node, provider_node, virtual)[source]
exception spack.solver.asp.UnsatisfiableSpecError(msg)[source]

Bases: UnsatisfiableSpecError

There was an issue with the spec that was requested (i.e. a user error).

spack.solver.asp.build_criteria_names(costs, arg_tuples)[source]

Construct an ordered mapping from criteria names to costs.

spack.solver.asp.build_priority_offset

Priority offset for “build” criteria (regular criterio shifted to higher priority for specs we have to build)

spack.solver.asp.c_compiler_runs(compiler) bool[source]
spack.solver.asp.check_packages_exist(specs)[source]

Ensure all packages mentioned in specs exist.

spack.solver.asp.dag_closure_by_deptype(name: str, spec: Spec, facts: List[AspFunction]) List[AspFunction][source]
spack.solver.asp.default_clingo_control()[source]

Return a control object with the default settings used in Spack

spack.solver.asp.dependency_holds(*, dependency_flags: int, pkg_cls: Type[PackageBase]) Callable[[str, Spec, List[AspFunction]], List[AspFunction]][source]
spack.solver.asp.extend_flag_list(flag_list, new_flags)[source]

Extend a list of flags, preserving order and precedence.

Add new_flags at the end of flag_list. If any flags in new_flags are already in flag_list, they are moved to the end so that they take higher precedence on the compile line.

spack.solver.asp.fixed_priority_offset

Priority offset of “fixed” criteria (those w/o build criteria)

spack.solver.asp.high_fixed_priority_offset

High fixed priority offset for criteria that supersede all build criteria

spack.solver.asp.identity_for_facts(name: str, spec: Spec, facts: List[AspFunction]) List[AspFunction][source]
spack.solver.asp.libc_is_compatible(lhs: Spec, rhs: Spec) bool[source]
spack.solver.asp.possible_compilers(*, configuration) Tuple[Set[Spec], Set[Spec]][source]
spack.solver.asp.remove_facts(*to_be_removed: str) Callable[[str, Spec, List[AspFunction]], List[AspFunction]][source]

Returns a transformation function that removes facts from the input list of facts.

spack.solver.asp.specify(spec)[source]
spack.solver.asp.strip_asp_problem(asp_problem: Iterable[str]) List[str][source]

Remove comments and empty lines from an ASP program.

spack.solver.core module

Low-level wrappers around clingo API and other basic functionality related to ASP

class spack.solver.core.AspFunction(name: str, args: Tuple[Any, ...] = ())[source]

Bases: object

A term in the ASP logic program

args
name
class spack.solver.core.AspVar(name: str)[source]

Bases: object

Represents a variable in an ASP rule, allows for conditionally generating rules

name
class spack.solver.core.NodeFlag(flag_type, flag, flag_group, source)[source]

Bases: NamedTuple

flag: str

Alias for field number 1

flag_group: str

Alias for field number 2

flag_type: str

Alias for field number 0

source: str

Alias for field number 3

class spack.solver.core.NodeId(id: str, pkg: str)[source]

Bases: NamedTuple

Represents a node in the DAG

id: str

Alias for field number 0

pkg: str

Alias for field number 1

class spack.solver.core.SourceContext(*, source: str | None = None)[source]

Bases: object

Tracks context in which a Spec’s clause-set is generated (i.e. with SpackSolverSetup.spec_clauses).

Facts generated for the spec may include this context.

wrap_node_requirement: bool | None
spack.solver.core.ast_sym(node)
spack.solver.core.ast_type(node)
spack.solver.core.clingo() ModuleType[source]

Lazy imports the Python module for clingo, and returns it.

spack.solver.core.clingo_cffi() bool[source]

Returns True if clingo uses the CFFI interface

spack.solver.core.extract_args(model, predicate_name)[source]

Extract the arguments to predicates with the provided name from a model.

Pull out all the predicates with name predicate_name from the model, and return their intermediate representation.

spack.solver.core.fn

Global AspFunction builder

spack.solver.core.intermediate_repr(sym)[source]

Returns an intermediate representation of clingo models for Spack’s spec builder.

Currently, transforms symbols from clingo models either to strings or to NodeId objects.

Returns:

This will turn a clingo.Symbol into a string or NodeId, or a sequence of clingo.Symbol objects into a tuple of those objects.

spack.solver.core.parse_files(*args, **kwargs)[source]

Wrapper around clingo parse_files, that dispatches the function according to clingo API version.

spack.solver.core.parse_term(*args, **kwargs)[source]

Wrapper around clingo parse_term, that dispatches the function according to clingo API version.

spack.solver.core.using_libc_compatibility() bool[source]

Returns True if we are currently using libc compatibility

spack.solver.input_analysis module

Classes to analyze the input of a solve, and provide information to set up the ASP problem

class spack.solver.input_analysis.Counter(specs: List[Spec], tests: bool | Iterable[str], possible_graph: PossibleDependencyGraph)[source]

Bases: object

Computes the possible packages and the maximum number of duplicates allowed for each of them.

Parameters:
  • specs – abstract specs to concretize

  • tests – if True, add test dependencies to the list of possible packages

ensure_cache_values() None[source]

Ensure the cache values have been computed

possible_dependencies() Set[str][source]

Returns the list of possible dependencies

possible_packages_facts(gen: ProblemInstanceBuilder, fn) None[source]

Emit facts associated with the possible packages

possible_virtuals() Set[str][source]

Returns the list of possible virtuals

class spack.solver.input_analysis.FullDuplicatesCounter(specs: List[Spec], tests: bool | Iterable[str], possible_graph: PossibleDependencyGraph)[source]

Bases: MinimalDuplicatesCounter

possible_packages_facts(gen, fn)[source]

Emit facts associated with the possible packages

class spack.solver.input_analysis.MinimalDuplicatesCounter(specs: List[Spec], tests: bool | Iterable[str], possible_graph: PossibleDependencyGraph)[source]

Bases: NoDuplicatesCounter

possible_packages_facts(gen, fn)[source]

Emit facts associated with the possible packages

class spack.solver.input_analysis.NoDuplicatesCounter(specs: List[Spec], tests: bool | Iterable[str], possible_graph: PossibleDependencyGraph)[source]

Bases: Counter

possible_packages_facts(gen: ProblemInstanceBuilder, fn) None[source]

Emit facts associated with the possible packages

class spack.solver.input_analysis.NoStaticAnalysis(*, configuration: Configuration, repo: RepoPath)[source]

Bases: PossibleDependencyGraph

Implementation that tries to minimize the setup time (i.e. defaults to give fast answers), rather than trying to reduce the ASP problem size with more complex analysis.

can_be_installed(*, pkg_name) bool[source]

Returns True if a package can be installed, False otherwise.

candidate_targets() List[Microarchitecture][source]

Returns a list of targets that are candidate for concretization

is_allowed_on_this_platform(*, pkg_name: str) bool[source]

Returns true if a package is allowed on the current host

is_virtual(name: str) bool[source]
possible_dependencies(*specs: Spec | str, allowed_deps: int, transitive: bool = True, strict_depflag: bool = False, expand_virtuals: bool = True) PossibleGraph[source]

Returns the set of possible dependencies, and the set of possible virtuals.

Runtime packages, which may be injected by compilers, needs to be added to specs if the dependency is not explicit in the package.py recipe.

Parameters:
  • transitive – return transitive dependencies if True, only direct dependencies if False

  • allowed_deps – dependency types to consider

  • strict_depflag – if True, only the specific dep type is considered, if False any deptype that intersects with allowed deptype is considered

  • expand_virtuals – expand virtual dependencies into all possible implementations

providers_for(virtual_str: str) List[Spec][source]

Returns a list of possible providers for the virtual string in input.

unreachable(*, pkg_name: str, when_spec: Spec) bool[source]

Returns true if the context can determine that the condition cannot ever be met on pkg_name.

class spack.solver.input_analysis.PossibleDependencyGraph[source]

Bases: object

Returns information needed to set up an ASP problem

candidate_targets() List[Microarchitecture][source]

Returns a list of targets that are candidate for concretization

possible_dependencies(*specs: Spec | str, allowed_deps: int, transitive: bool = True, strict_depflag: bool = False, expand_virtuals: bool = True) PossibleGraph[source]

Returns the set of possible dependencies, and the set of possible virtuals.

Runtime packages, which may be injected by compilers, needs to be added to specs if the dependency is not explicit in the package.py recipe.

Parameters:
  • transitive – return transitive dependencies if True, only direct dependencies if False

  • allowed_deps – dependency types to consider

  • strict_depflag – if True, only the specific dep type is considered, if False any deptype that intersects with allowed deptype is considered

  • expand_virtuals – expand virtual dependencies into all possible implementations

unreachable(*, pkg_name: str, when_spec: Spec) bool[source]

Returns true if the context can determine that the condition cannot ever be met on pkg_name.

class spack.solver.input_analysis.PossibleGraph(real_pkgs, virtuals, edges)[source]

Bases: NamedTuple

edges: Dict[str, Set[str]]

Alias for field number 2

real_pkgs: Set[str]

Alias for field number 0

virtuals: Set[str]

Alias for field number 1

class spack.solver.input_analysis.StaticAnalysis(*, configuration: Configuration, repo: RepoPath, store: Store, binary_index: BinaryIndexCache)[source]

Bases: NoStaticAnalysis

Performs some static analysis of the configuration, store, etc. to provide more precise answers on whether some packages can be installed, or used as a provider.

It increases the setup time, but might decrease the grounding and solve time considerably, especially when requirements restrict the possible choices for providers.

buildcache_specs() List[Spec][source]
can_be_installed(*, pkg_name) bool[source]

Returns True if a package can be installed, False otherwise.

providers_for(virtual_str: str) List[Spec][source]

Returns a list of possible providers for the virtual string in input.

unreachable(*, pkg_name: str, when_spec: Spec) bool[source]

Returns true if the context can determine that the condition cannot ever be met on pkg_name.

spack.solver.input_analysis.create_counter(specs: List[Spec], tests: bool | Iterable[str], possible_graph: PossibleDependencyGraph) Counter[source]
spack.solver.input_analysis.create_graph_analyzer() PossibleDependencyGraph[source]

spack.solver.requirements module

class spack.solver.requirements.RequirementKind(*values)[source]

Bases: Enum

Purpose / provenance of a requirement

DEFAULT

Default requirement expressed under the ‘all’ attribute of packages.yaml

PACKAGE

Requirement expressed on a specific package

VIRTUAL

Requirement expressed on a virtual package

class spack.solver.requirements.RequirementOrigin(*values)[source]

Bases: Enum

Origin of a requirement

CONFLICT_YAML
DIRECTIVE
INPUT_SPECS
PREFER_YAML
REQUIRE_YAML
class spack.solver.requirements.RequirementParser(configuration: Configuration)[source]

Bases: object

Parses requirements from package.py files and configuration, and returns rules.

parse_rules_from_input_specs(specs: Sequence[Spec])[source]
preferences_from_input: List[Tuple[Spec, str]]
reject_requirement_constraint(pkg_name: str, *, constraint: Spec, kind: RequirementKind) bool[source]

Returns True if a requirement constraint should be rejected

rules(pkg: PackageBase) List[RequirementRule][source]
rules_from_conflict(pkg: PackageBase) List[RequirementRule][source]
rules_from_input_specs(pkg: PackageBase) List[RequirementRule][source]
rules_from_package_py(pkg: PackageBase) List[RequirementRule][source]
rules_from_prefer(pkg: PackageBase) List[RequirementRule][source]
rules_from_require(pkg: PackageBase) List[RequirementRule][source]
rules_from_virtual(virtual_str: str) List[RequirementRule][source]
class spack.solver.requirements.RequirementRule(pkg_name: str, policy: str, origin: RequirementOrigin, requirements: Sequence[Spec], condition: Spec, kind: RequirementKind, message: str | None)[source]

Bases: NamedTuple

Data class to collect information on a requirement

condition: Spec

Alias for field number 4

kind: RequirementKind

Alias for field number 5

message: str | None

Alias for field number 6

origin: RequirementOrigin

Alias for field number 2

pkg_name: str

Alias for field number 0

policy: str

Alias for field number 1

requirements: Sequence[Spec]

Alias for field number 3

spack.solver.requirements.conflict(pkg_name: str, constraint: Spec, condition: Spec = spack.spec.EMPTY_SPEC, origin: RequirementOrigin = RequirementOrigin.CONFLICT_YAML, kind: RequirementKind = RequirementKind.PACKAGE, message: str | None = None) RequirementRule[source]

Returns a conflict rule

spack.solver.requirements.parse_spec_from_yaml_string(string: str, *, named: bool = False) Spec[source]

Parse a spec from YAML and add file/line info to errors, if it’s available.

Parse a Spec from the supplied string, but also intercept any syntax errors and add file/line information for debugging using file/line annotations from the string.

Parameters:
  • string – a string representing a Spec from config YAML.

  • named – if True, the spec must have a name

spack.solver.requirements.preference(pkg_name: str, constraint: Spec, condition: Spec = spack.spec.EMPTY_SPEC, origin: RequirementOrigin = RequirementOrigin.PREFER_YAML, kind: RequirementKind = RequirementKind.PACKAGE, message: str | None = None) RequirementRule[source]

Returns a preference rule

spack.solver.reuse module

class spack.solver.reuse.ReusableSpecsSelector(*, configuration: Configuration, external_parser: ExternalSpecsParser, packages_with_externals: Any, factory: Callable[[Callable[[Spec], bool], Configuration], List[SpecFilter]] | None = None)[source]

Bases: object

Selects specs that can be reused during concretization.

reusable_specs(specs: List[Spec]) List[Spec][source]
class spack.solver.reuse.ReuseStrategy(*values)[source]

Bases: Enum

DEPENDENCIES
NONE
ROOTS
spack.solver.reuse.create_external_parser(packages_with_externals: Any, completion_mode: str) ExternalSpecsParser[source]

Get externals from a pre-processed packages.yaml (with implicit externals).

spack.solver.reuse.spec_filter_from_buildcache(*, packages_with_externals, include, exclude) SpecFilter[source]

Constructs a filter that takes the specs from the configured buildcaches.

spack.solver.reuse.spec_filter_from_environment(*, packages_with_externals, include, exclude, env) SpecFilter[source]
spack.solver.reuse.spec_filter_from_packages_yaml(*, external_parser: ExternalSpecsParser, packages_with_externals, include, exclude) SpecFilter[source]
spack.solver.reuse.spec_filter_from_store(configuration, *, packages_with_externals, include, exclude) SpecFilter[source]

Constructs a filter that takes the specs from the current store.

spack.solver.runtimes module

class spack.solver.runtimes.RuntimePropertyRecorder(setup)[source]

Bases: object

An object of this class is injected in callbacks to compilers, to let them declare properties of the runtimes they support and of the runtimes they provide, and to add runtime dependencies to the nodes using said compiler.

The usage of the object is the following. First, a runtime package name or the wildcard “*” are passed as an argument to __call__, to set which kind of package we are referring to. Then we can call one method with a directive-like API.

Examples

>>> pkg = RuntimePropertyRecorder(setup)
>>> # Every package compiled with %gcc has a link dependency on 'gcc-runtime'
>>> pkg("*").depends_on(
...     "gcc-runtime",
...     when="%gcc",
...     type="link",
...     description="If any package uses %gcc, it depends on gcc-runtime"
... )
>>> # The version of gcc-runtime is the same as the %gcc used to "compile" it
>>> pkg("gcc-runtime").requires("@=9.4.0", when="%gcc@=9.4.0")
consume_facts()[source]

Consume the facts collected by this object, and emits rules and facts for the runtimes.

default_flags(spec: Spec)[source]
depends_on(dependency_str: str, *, when: str, type: str, description: str) None[source]

Injects conditional dependencies on packages.

Conditional dependencies can be either “real” packages or virtual dependencies.

Parameters:
  • dependency_str – the dependency spec to inject

  • when – anonymous condition to be met on a package to have the dependency

  • type – dependency type

  • description – human-readable description of the rule for adding the dependency

static node_for(name: str) str[source]
propagate(constraint_str: str, *, when: str)[source]
requires(impose: str, *, when: str)[source]

Injects conditional requirements on a given package.

Parameters:
  • impose – constraint to be imposed

  • when – condition triggering the constraint

reset()[source]

Resets the current state.

rule_body_from(when_spec: Spec) Tuple[str, str][source]

Computes the rule body from a “when” spec, and returns it, along with the node variable.

spack.solver.runtimes.all_libcs() Set[Spec][source]

Return a set of all libc specs targeted by any configured compiler. If none, fall back to libc determined from the current Python process if dynamically linked.

spack.solver.runtimes.external_config_with_implicit_externals(configuration: Configuration) Dict[str, Any][source]

spack.solver.splicing module

class spack.solver.splicing.Splice(splice_spec, child_name, child_hash)[source]

Bases: NamedTuple

child_hash: str

The hash of the child that splice_spec is replacing

child_name: str

The name of the child that splice spec is replacing

splice_spec: Spec

The spec being spliced into a parent

spack.solver.versions module

class spack.solver.versions.Provenance(*values)[source]

Bases: IntEnum

Enumeration of the possible provenances of a version.

DEV_SPEC
INSTALLED
INSTALLED_GIT_VERSION
PACKAGES_YAML
PACKAGES_YAML_GIT_VERSION
PACKAGE_PY
PACKAGE_REQUIREMENT
RUNTIME
SPEC
VIRTUAL_CONSTRAINT