Commit graph

4297 commits

Author SHA1 Message Date
Todd Gamblin
51cb49743e tests: add framework to mock targets 2020-11-17 10:04:13 -08:00
Todd Gamblin
43e7255e19 concretizer: split platforms, OS, and targets apart in Python and ASP 2020-11-17 10:04:13 -08:00
Todd Gamblin
cb919c2e39 concretizer: targets are inherited like compilers 2020-11-17 10:04:13 -08:00
Todd Gamblin
afa74ea155 concretizer: change single-letter variables to descriptive names
The original implementation was difficult to read, as it only had
single-letter variable names.  This converts all of them to descriptive
names, e.g., P -> Package, V -> Virtual/Version/Variant, etc.
2020-11-17 10:04:13 -08:00
Todd Gamblin
35ae4c0ddd concretizer: handle compiler existence check settings
To handle unknown compilers propely in tests (and elsewhere), we need to
add unknown compilers from the spec to the list of possible compilers.

Rework how the compiler list is generated and includes compilers from
specs if the existence check is disabled.
2020-11-17 10:04:13 -08:00
Todd Gamblin
3b648c294e concretizer: add initial package existence check 2020-11-17 10:04:13 -08:00
Todd Gamblin
520b71e89b concretizer: handle virtual spec constraints better
Specs like hdf5 ^mpi were unsatisfiable because we added a requierment
for `node("mpi").`.  This can't be resolved because "mpi" is not a
package.

- [x] Introduce `virtual_node()`, which says *some* provider must be in
      the DAG.
2020-11-17 10:04:13 -08:00
Todd Gamblin
3ef7c06a48 concretizer: solve with compiler flags but preserve order
This adds compiler flags to the ASP solve so that we can have conditions
based on them in the solve.  But, it keeps order out of the solve to
avoid unneeded complexity and combinatorial explosions.

The solver determines which flags are on a spec, but the order is
determined by DAG precedence (childrens' flags take precedence over
parents' and are added on the right) and order (order flags were
specified on the command line is respected).

The solver is responsible for determining when to propagate flags, when
to inheit them from other nodes, when to take them from compiler
preferences, etc.
2020-11-17 10:04:13 -08:00
Todd Gamblin
7a1b5ca65e concretizer: add timers around phases 2020-11-17 10:04:13 -08:00
Todd Gamblin
5185ed1d28 concretizer: optimize microarchitectures, constrained by compiler support
Weight microarchitectures and prefers more rercent ones.  Also disallow
nodes where the compiler does not support the selected target.

We should revisit this at some point as it seems like if I play around
with the compiler support for different architectures, the solver runs
very slowly.  See notes in comments -- the bad case was gcc supporting
broadwell and skylake with clang maxing out at haswell.
2020-11-17 10:04:13 -08:00
Todd Gamblin
71726a9b33 concretizer bugfix: require at least one value for multi-value variants
We didn't have a cardinality constraint for multi-valued variants, so the
solver wasn't filling them in.

- [x] add a requirement for at least one value for multi-valued variants
2020-11-17 10:04:13 -08:00
Todd Gamblin
309ae856ab commands: add --json argument to spack solve 2020-11-17 10:04:13 -08:00
Todd Gamblin
cb8ca505ef concretizer: make some rules into facts 2020-11-17 10:04:13 -08:00
Todd Gamblin
810542d4fe concretizer bugfix: all variants need possible values
Variants like `cpu_target` on `openblas` don't have defineed values, but
they have a default.  Ensure that the default is always a possible value
for the solver.
2020-11-17 10:04:13 -08:00
Todd Gamblin
9b1f05df00 concretizer bugfix: fix generations of conditionals for dependencies
Spack was generating the same dependency connstraints twice in the output ASP:

```
declared_dependency("abinit", "hdf5", "link")
    :- node("abinit"),
       variant_value("abinit", "mpi", "True"),
       variant_value("abinit", "mpi", "True").
```

This was because `AspFunction` was modifying itself when called.

- [x] fix `AspFunction` so that every call returns a new object
2020-11-17 10:04:13 -08:00
Todd Gamblin
e31be3da56 concretizer bugfix: *at most* one provider for any virtual 2020-11-17 10:04:13 -08:00
Todd Gamblin
04295f6531 concretizer: optimized for preferred virtuals before recent versions 2020-11-17 10:04:13 -08:00
Todd Gamblin
f365373a3d concretizer: handle compiler preferences with optimization
- [x] Add support for packages.yaml and command-line compiler preferences.
- [x] Rework compiler version propagation to use optimization rather than
  hard logic constraints
2020-11-17 10:04:13 -08:00
Todd Gamblin
1859ff31c9 concretizer: deterministic order for asp output for better diffs
Technically the ASP output order does not matter, but it's hard to diff
two different solve fomulations unless we order it.

- [x] make sure ASP output is emitted in a deterministic order (by
      sorting all hash keys)
2020-11-17 10:04:13 -08:00
Todd Gamblin
36dae9ee05 concretizer: rename --dump to --show 2020-11-17 10:04:13 -08:00
Todd Gamblin
da215b50a3 concretizer: handle package namespaces 2020-11-17 10:04:13 -08:00
Todd Gamblin
4d34363c1d concretizer: handle constraints on dependencies, adjust optimization
This needs more thought, as I am pretty sure the weights are not correct.
Or, at least, I'm not convinced that they do what we want in all cases.
See note in concretize.lp.
2020-11-17 10:04:13 -08:00
Todd Gamblin
db62b00d58 concretizer: handle dependency types 2020-11-17 10:04:13 -08:00
Todd Gamblin
cde10692b0 concretizer: prioritize versions by package pref, newest, preferred, actual
Solver now prefers newer versions like the old concretizer.  Prefer
package preferences from packages.yaml, preferred=True, package
definition, and finally each version itself.
2020-11-17 10:04:13 -08:00
Todd Gamblin
18fba433f6 concretizer: Use "competition" output format to avoid extra parsing
Competition output only prints out one model, so we do not have to
unnecessarily parse all the non-optimal models.  We'll just look at the
best model and bring that in.

In practice, this saves a lot of JSON parsing and spec construction time.
2020-11-17 10:04:13 -08:00
Todd Gamblin
b4e6d9d28e concretizer: handle virtual provider preferences from packages.yaml 2020-11-17 10:04:13 -08:00
Todd Gamblin
36ec66d997 concretizer: use clingo json output instead of text
Clingo actually has an option to output JSON -- use that instead of
parsing the raw otuput ourselves.

This also allows us to pick the best answer -- modify the parser to
*only* construct a spec for that one rather than building all of them
like we did before.
2020-11-17 10:04:13 -08:00
Todd Gamblin
a332981f2f concretizer: require only one provider for any virtual in the DAG 2020-11-17 10:04:13 -08:00
Todd Gamblin
501cb371c9 concretizer: handle variant defaults with optimization
- Instead of using default logic, handle variant defaults by minimizing
  the number of non-default variants in the solution.

- This actually seems to be pretty fast, and it fixes the long-standing
  issue that writing this:

      spack install hdf5 ^mpich

  will fail if you don't specify hdf5+mpi.  With optimization and
  allowing enums to be enumerated, the solver seems to be able to quickly
  discover that +mpi is the only way hdf5 can depend on mpich, and it
  forces the switch to be thrown.
2020-11-17 10:04:13 -08:00
Todd Gamblin
1cab1b1994 concretizer: support conditional dependencies 2020-11-17 10:04:13 -08:00
Todd Gamblin
51af590e64 variants: allow MultiValuedVariants to be constructed incrementally 2020-11-17 10:04:13 -08:00
Todd Gamblin
be10568a6a concretizer: initial support for virtual dependencies
Add initial support for virtual dependencies.  Solver now knows about all
virtuals and can choose one to resolve a dependency.
2020-11-17 10:04:13 -08:00
Todd Gamblin
3f93553a08 concretizer: print out virtuals 2020-11-17 10:04:13 -08:00
Todd Gamblin
8a6207aa70 concretizer: handle versions with choice construct rather than conflicts
Use '1 { version(x); version(y); version(z) } 1.' instead of declaring
conflicts for non-matching versions.  This keeps the sense of version
clauses positive, which will allow them to be used more easily in
conditionals later.

Also refactor `spec_clauses()` method to return clauses that can be used
in conditions, etc. instead of just printing out facts.
2020-11-17 10:04:13 -08:00
Todd Gamblin
6e31430bec concretizer: add another definition pragma.
- single_value_variant may not be defined by the generated program.  Mark
  it to avoid warnings.
2020-11-17 10:04:13 -08:00
Todd Gamblin
a81258663c concretizer: cleanup 2020-11-17 10:04:13 -08:00
Todd Gamblin
6bbc64555b concretizer: use conditional literals for versions. 2020-11-17 10:04:13 -08:00
Todd Gamblin
4288639770 concretizer: mark depends_on/2 defined for solves without dependencies. 2020-11-17 10:04:13 -08:00
Todd Gamblin
60cf3fdb34 concretizer: add basic semantics for compilers
- This handles setting the compiler and falling back to a default
  compiler, as well as providing default values for compilers/compiler
  versions.

- Versions still aren't quite right -- you can't properly override
  versions on compiler specs.
2020-11-17 10:04:13 -08:00
Todd Gamblin
f7dce19754 concretizer: simplify and move architecture semantics into concretize.lp
- Model architecture default settings and propagation off of variants

- Leverage ASP default logic to set architecture to default if it's not
  set otherwise.

- Move logic out of Python and into concretize.lp as first-order rules.
2020-11-17 10:04:13 -08:00
Todd Gamblin
34ea3d20cf concretizer: break output up into easier-to-understand sections 2020-11-17 10:04:13 -08:00
Todd Gamblin
d94d957536 concretizer: simplify and suppress warnings for variant handling
We are relying on default logic in the variant handling in that we set a
default value if we never see `variant_set(P, V, X)`.

- Move the logic for this into `concretize.lp` instead of generating it
  for every package.

- For programs that don't have explicit variant settings, clingo warns
  that variant_set(P, V, X) doesn't appear in any rule head, because a
  setting is never generated.

  - Specifically suppress this warning.
2020-11-17 10:04:13 -08:00
Todd Gamblin
b171ac5050 concretizer: split long lines in ASP programs 2020-11-17 10:04:13 -08:00
Todd Gamblin
573a2612dc concretizer: split main logic program out into files
- Add `concretize.lp` and `display.lp` as independent files
- Dump them instead of embedded strings
2020-11-17 10:04:13 -08:00
Todd Gamblin
8bc1092f41 concretizer: colorize ASP output 2020-11-17 10:04:13 -08:00
Todd Gamblin
3637b611a7 concretizer: move dump logic into solver.asp
- moving the dump logic into spack.solver.asp.solve() allows us to print
  out useful debug info sooner

- prior approach required a successful solve to print out anyhting.
2020-11-17 10:04:13 -08:00
Todd Gamblin
81e187e410 concretizer: first rudimentary round-trip with asp-based solver 2020-11-17 10:04:13 -08:00
Todd Gamblin
c7812f7e10 concretizer: add rudimentary variants with defaults to ASP solve 2020-11-17 10:04:13 -08:00
Todd Gamblin
a8a6d943d6 concretizer: beginnings of solve() command
- `spack solve` command outputs a really basic ASP program that handles
  unconditional dependencies, architecture and versions

- doesn't yet handle conflicts, picking latest versions, preferred
  versions, compilers, etc.

- doesn't handle variants
2020-11-17 10:04:13 -08:00
Todd Gamblin
5b725a37bc repo: Add all_package_classes() method.
- We were able to get names and instances previously
- Add a convenience function to get package classes
2020-11-17 10:04:13 -08:00