Skip to content

Avoid best-effort expansion of stacks#40792

Merged
haampie merged 2 commits intospack:developfrom
alalazo:bugfix/matrix-expansion-should-be-consistent
Sep 5, 2024
Merged

Avoid best-effort expansion of stacks#40792
haampie merged 2 commits intospack:developfrom
alalazo:bugfix/matrix-expansion-should-be-consistent

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Oct 30, 2023

fixes #40791

Currently, stacks behave differently if used in unify:false environments, which leads to inconsistencies during concretization.

For instance, we might have two abstract user specs that do not intersect with each other map to the same concrete spec in the environment. This is clearly wrong.

This PR removes the best effort expansion, so that user specs are always applied strictly.

@spackbot-app spackbot-app bot added commands core PR affects Spack core functionality tests General test capability(ies) labels Oct 30, 2023
@alalazo alalazo force-pushed the bugfix/matrix-expansion-should-be-consistent branch from fc2df49 to 625b64d Compare October 31, 2023 17:18
@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Oct 31, 2023

I don't think we should remove best-effort expansion, because people are actually using it. If I look at the original issue, it seems like to me that the env should emit a warning (or maybe an error? I don't really care) if a variant couldn't apply to any spec in the matrix, but I wouldn't remove best-effort expansion.

That said, I agree that the current way we handle this is somewhat inconsistent. In particular I think we could adopt the change in this PR if we still had a way to do best-effort. Something like:

spack:
    specs:
    - zstd
    - prefer: +shrd

Where prefer: indicates it should be best-effort. This would be consistent with introducing a prefer: syntax that is symmetric with require:, and we could just say the default for matrices is require:. Until we have that, though, I think we should keep allowing best-effort, because not having it makes variants in matrices much less useful.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Oct 31, 2023

I don't think we should remove best-effort expansion, because people are actually using it. If I look at the original issue, it seems like to me that the env should emit a warning (or maybe an error? I don't really care) if a variant couldn't apply to any spec in the matrix, but I wouldn't remove best-effort expansion.

For what is worth, best-effort expansion is only used with unify:false. Both unify:when_possible and unify:true will not use it. It can result in abstract user specs that do not intersect being mapped to the same concrete spec. This is logically a big inconsistency imo.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Dec 6, 2023

If I look at the original issue, it seems like to me that the env should emit a warning (or maybe an error? I don't really care) if a variant couldn't apply to any spec in the matrix, but I wouldn't remove best-effort expansion.

There are a couple of things I want to note. The behavior is not only inconsistent across different unification modes, it's just wrong, and the issue is not only about variants but about everything:

spack:
  specs:
  - matrix:
    - [zlib]
    - ["^trilinos", "~shrd"]
  concretizer:
    unify: false
  view: false

Here we concretize a zlib that depends on trilinos, except it does not:
Screenshot from 2023-12-06 10-08-12

The corresponding lockfile is:

spack.lock

{
  "_meta": {
    "file-type": "spack-lockfile",
    "lockfile-version": 5,
    "specfile-version": 4
  },
  "spack": {
    "version": "0.22.0.dev0",
    "type": "git",
    "commit": "84999b699682f8505908e7c5f7e767f9d3be6c79"
  },
  "roots": [
    {
      "hash": "qnzaxw3i5na6hu4fr23buxys7ht74w2v",
      "spec": "zlib ^trilinos"
    },
    {
      "hash": "qnzaxw3i5na6hu4fr23buxys7ht74w2v",
      "spec": "zlib~shrd"
    }
  ],
  "concrete_specs": {
    "qnzaxw3i5na6hu4fr23buxys7ht74w2v": {
      "name": "zlib",
      "version": "1.3",
      "arch": {
        "platform": "linux",
        "platform_os": "ubuntu20.04",
        "target": {
          "name": "icelake",
          "vendor": "GenuineIntel",
          "features": [
            "adx",
            "aes",
            "avx",
            "avx2",
            "avx512_bitalg",
            "avx512_vbmi2",
            "avx512_vnni",
            "avx512_vpopcntdq",
            "avx512bw",
            "avx512cd",
            "avx512dq",
            "avx512f",
            "avx512ifma",
            "avx512vbmi",
            "avx512vl",
            "bmi1",
            "bmi2",
            "clflushopt",
            "clwb",
            "f16c",
            "fma",
            "gfni",
            "mmx",
            "movbe",
            "pclmulqdq",
            "popcnt",
            "rdpid",
            "rdrand",
            "rdseed",
            "sha_ni",
            "sse",
            "sse2",
            "sse4_1",
            "sse4_2",
            "ssse3",
            "vaes",
            "vpclmulqdq",
            "xsavec",
            "xsaveopt"
          ],
          "generation": 0,
          "parents": [
            "cascadelake",
            "cannonlake"
          ]
        }
      },
      "compiler": {
        "name": "gcc",
        "version": "9.4.0"
      },
      "namespace": "builtin",
      "parameters": {
        "build_system": "makefile",
        "optimize": true,
        "pic": true,
        "shared": true,
        "cflags": [],
        "cppflags": [],
        "cxxflags": [],
        "fflags": [],
        "ldflags": [],
        "ldlibs": []
      },
      "package_hash": "u7vqvwmacj5j7zngg2evhytlxmzhad35mxlxna6tmr4bjyeisgsa====",
      "dependencies": [
        {
          "name": "gmake",
          "hash": "li5apiwbiexfsusfyv73rualbl6q35wt",
          "parameters": {
            "deptypes": [
              "build"
            ],
            "virtuals": []
          }
        }
      ],
      "hash": "qnzaxw3i5na6hu4fr23buxys7ht74w2v"
    },
    "li5apiwbiexfsusfyv73rualbl6q35wt": {
      "name": "gmake",
      "version": "4.4.1",
      "arch": {
        "platform": "linux",
        "platform_os": "ubuntu20.04",
        "target": {
          "name": "icelake",
          "vendor": "GenuineIntel",
          "features": [
            "adx",
            "aes",
            "avx",
            "avx2",
            "avx512_bitalg",
            "avx512_vbmi2",
            "avx512_vnni",
            "avx512_vpopcntdq",
            "avx512bw",
            "avx512cd",
            "avx512dq",
            "avx512f",
            "avx512ifma",
            "avx512vbmi",
            "avx512vl",
            "bmi1",
            "bmi2",
            "clflushopt",
            "clwb",
            "f16c",
            "fma",
            "gfni",
            "mmx",
            "movbe",
            "pclmulqdq",
            "popcnt",
            "rdpid",
            "rdrand",
            "rdseed",
            "sha_ni",
            "sse",
            "sse2",
            "sse4_1",
            "sse4_2",
            "ssse3",
            "vaes",
            "vpclmulqdq",
            "xsavec",
            "xsaveopt"
          ],
          "generation": 0,
          "parents": [
            "cascadelake",
            "cannonlake"
          ]
        }
      },
      "compiler": {
        "name": "gcc",
        "version": "9.4.0"
      },
      "namespace": "builtin",
      "parameters": {
        "build_system": "generic",
        "guile": false,
        "cflags": [],
        "cppflags": [],
        "cxxflags": [],
        "fflags": [],
        "ldflags": [],
        "ldlibs": []
      },
      "package_hash": "ghstvqlc3r7kgiikwx24xhcxdxcqdk5viinrzgm2mssqigfonika====",
      "hash": "li5apiwbiexfsusfyv73rualbl6q35wt"
    }
  }
}

Neither of the roots satisfies the concrete spec they point to, which is in my opinion a severe breakage of the invariants that are supposed to hold for concretization.

@alalazo alalazo force-pushed the bugfix/matrix-expansion-should-be-consistent branch from 625b64d to 98d787e Compare January 16, 2024 14:58
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 24, 2024

@tgamblin We have a prefer: semantic in packages.yaml since #41832 Is there anything else needed to consider merging this fix? The issue described in #40792 (comment) is pretty bad imo.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 30, 2024

Ping @tgamblin

@alalazo alalazo force-pushed the bugfix/matrix-expansion-should-be-consistent branch from 98d787e to 23da877 Compare February 19, 2024 16:51
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Mar 1, 2024

@tgamblin

@alalazo alalazo force-pushed the bugfix/matrix-expansion-should-be-consistent branch from 23da877 to 60b45f7 Compare April 11, 2024 09:52
fixes spack#40791

Currently stacks behave differently if used in unify:false
environments, which leads to inconsistencies during concretization.

For instance, we might have two abstract user specs that do not
intersect with each other map to the same concrete spec in the
environment. This is clearly wrong.

This PR removes the best effort expansion, so that user specs
are always applied strictly.
@alalazo alalazo added this to the v0.23.0 milestone Sep 5, 2024
@alalazo alalazo force-pushed the bugfix/matrix-expansion-should-be-consistent branch from 60b45f7 to b9b28dd Compare September 5, 2024 08:28
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Sep 5, 2024

Since #45215 it doesn't make much sense to keep best-effort expansion. It was never supported by the new concretizer.

@haampie haampie enabled auto-merge (squash) September 5, 2024 12:54
@haampie haampie merged commit c4d1867 into spack:develop Sep 5, 2024
@alalazo alalazo deleted the bugfix/matrix-expansion-should-be-consistent branch September 5, 2024 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands concretization core PR affects Spack core functionality environments stacks tests General test capability(ies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Best effort enforcement of constraints in matrices result in inconsistent environments

3 participants