Skip to content

environment: allow group of specs with dependencies#51891

Merged
alalazo merged 32 commits intospack:developfrom
alalazo:feature/environment-with-groups
Feb 26, 2026
Merged

environment: allow group of specs with dependencies#51891
alalazo merged 32 commits intospack:developfrom
alalazo:feature/environment-with-groups

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Jan 28, 2026

closes #49097

Currently, there are scenarios and use cases that are difficult to express with a single spack.yaml file. For instance:

  1. Start with an old system compiler to bootstrap a new toolchain, and then software on top of that
  2. Deploy a highly heterogeneous stack (different compilers, different options for the same set of specs) while ensuring a fine control over dependencies

These use cases are usually dealt with multiple environments1 or by "abusing" certain concretization strategies2. Both methods are sub-optimal and error prone.

In this PR we solve these kind of issues by allowing named group of specs, as shown in #49097. Each named group of specs:

  • Can have dependencies on other groups. If that happens, the dependency groups are concretized before the current group, and their roots specs are always available for reuse in the current concretization.
  • Can override configuration scopes with details that matter only for the current group, since the override is then used only for the concretization of the current group

An example environment using these features is:

# Bootstrap [email protected], then use it to build the same
# set of specs for x86_64_v3 and x86_64_v4
spack:
  definitions:
  - apps: [hdf5, mpileaks]

  packages:
    all: {prefer: [target=x86_64_v3]}

  specs:
  - group: compiler
    specs:
    - [email protected]

  - group: apps-x86_64_v4
    needs: [compiler]
    specs:
    - $apps
    override:
      packages:
        all: {prefer: [target=x86_64_v4]}
        c: {prefer: [[email protected]]}
        cxx: {prefer: [[email protected]]}
        fortran: {prefer: [[email protected]]}

  - group: apps-x86_64_v3
    needs: [compiler]
    specs:
    - $apps
    override:
      packages:
        c: {prefer: [[email protected]]}
        cxx: {prefer: [[email protected]]}
        fortran: {prefer: [[email protected]]}

The groups can also be used to create tailored views. For instance, an entry like:

views:
  x86_64_v3:
    root: ...
    group: apps-x86_64_v3

will just put specs from the apps-x86_64_v3 group into the view.

Benchmark

Trying this PR in spack/spack-packages#3175 already shows:

  • A drastic reduction in the specs to be built for the ml-*-x86_64 stacks, when they are unified
  • The correct concretization of the tutorial stack using unify:false, which is currently broken on develop when using the unify:when_possible hack

Notes

This PR requires a bump of the lockfile for environments, from v6 to v7. Nonetheless, to preserve backward compatbility, if the feature is not used Spack will continue to write lockfiles in v6 format, which are undersatood by previous version of Spack.

To do in following PRs

  • Hook "groups" into commands other than concretization e.g. modules etc. (can be split in other PRs)
  • Add a behavior similar to concrete included environments between groups (can also be in a following PR)
  • Parallelize concretization among groups

Footnotes

  1. See for instance the ml-* stack in out public pipelines

  2. See the tutorial pipeline where we use unify:when_possible to bootstrap gcc@12

@haampie
Copy link
Copy Markdown
Member

haampie commented Jan 29, 2026

Looks useful. From a first high-level pass:

  1. The feature seems to be introduced with a particular use case in mind: group 1 adds a compiler, group 2 uses that compiler. From that perspective it makes sense that unify: true/when_possible applies only within a group. But I wonder if there are use cases where unify: true/when_possible would apply to the current group and its dependencies combined. How do you express that? I think there's precedence for that:
    • included envs were supposed to be like that: unify stuff on top of a base
    • the incremental concretization pattern spack add a b spack concretize spack add c d spack concretize is kinda like that, where the first group is [a, b] and the second is [c, d].
  2. Concretization of independent group is sequential (I guess this was simpler to implement)

Further, I think more work is needed to let users select a particular group for views. Presumably they wanna have the end product in the view and omit the first group (?). What would that look like? Currently, users would have two environments, and care about the view of the second env.

@alalazo alalazo force-pushed the feature/environment-with-groups branch from fe6f26a to 893f783 Compare February 5, 2026 11:03
alecbcs pushed a commit to spack/spack-packages that referenced this pull request Feb 6, 2026
* Revert "ci: disable tutorial pipeline (#3249)"

* Revert "tutorial stack: use when_possible and bootstrap gcc12 (new container) (#2277)"

This commit re-enables the tutorial stack without using `when_possible` which was leading to extremely long multi round concretization times post spack/spack#51796. Although this implementation of the tutorial stack is not technically correct when using compilers as nodes, it'll allow us to continue to ensure that all of the components of the stack build and are not accidentally broken due to a package PR.

The long term solution here is to merge spack/spack#51891 which allows for multiple concretization groups in an environment and thus allows us to bootstrap a gcc compiler and then use it to build additional specs in the tutorial.

---------

Signed-off-by: Gregory Becker <[email protected]>
@alalazo alalazo force-pushed the feature/environment-with-groups branch 2 times, most recently from 1f7ebba to 43dd4a1 Compare February 9, 2026 17:21
@github-actions github-actions bot added the docs label Feb 9, 2026
@alalazo alalazo force-pushed the feature/environment-with-groups branch 2 times, most recently from 1f14eee to 86d35bb Compare February 10, 2026 16:11
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Feb 10, 2026

So, with respect to "unify specs from multiple groups" that is possible, and there is a well defined place to change for that:

https://github.com/alalazo/spack/blob/86d35bb2e0b422dae3fc6a5b43202000e40b69f5/lib/spack/spack/environment/environment.py#L2643-L2647

I would introduce this behavior in a following PR, since the current behavior of included environments is buggy and so would be good to first sort that out, then mimic it with groups. What we'd need is just a way to know which groups are unified and which needs just to be reused.

Likewise, I'd keep parallelizing the concretization for another PR.

Support for groups in views has been implemented and documented.

@alalazo alalazo marked this pull request as ready for review February 10, 2026 17:28
Signed-off-by: Massimiliano Culpo <[email protected]>
This should break the additional circular imports

Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
@alalazo alalazo force-pushed the feature/environment-with-groups branch from fdbd4bf to 5be798d Compare February 20, 2026 19:49
Leftover from refactoring

Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
@alalazo alalazo force-pushed the feature/environment-with-groups branch from 2fa6d0f to 76fcd24 Compare February 24, 2026 22:17
@alalazo alalazo requested a review from haampie February 25, 2026 06:58
@alalazo alalazo merged commit bdfad3c into spack:develop Feb 26, 2026
33 checks passed
@alalazo alalazo deleted the feature/environment-with-groups branch February 26, 2026 07:45
@tgamblin tgamblin added this to the v1.2.0 milestone Mar 10, 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.

Allow dependencies between specs in environments

3 participants