Skip to content

ASP-based solver: don't error for type mismatch on preferences#41138

Merged
haampie merged 4 commits intospack:developfrom
alalazo:bugfix/preference-not-error
Nov 23, 2023
Merged

ASP-based solver: don't error for type mismatch on preferences#41138
haampie merged 4 commits intospack:developfrom
alalazo:bugfix/preference-not-error

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Nov 17, 2023

fixes #41134

This PR discards type mismatches or failures to validate a package preference during concretization. The values discarded are logged as debug level messages. It also adds a config audit to help users spot misconfigurations in packages.yaml preferences.

@spackbot-app spackbot-app bot added core PR affects Spack core functionality stand-alone-tests Stand-alone (or smoke) tests for installed packages tests General test capability(ies) labels Nov 17, 2023
@alalazo alalazo mentioned this pull request Nov 17, 2023
36 tasks
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Nov 17, 2023

As an example audit, with:

packages:
  llvm:
    variants: ["+openmp+foo", "clang=absolutely"]

  zlib:
    variants: "+openmp +foo clang=absolutely"

we get the following warnings:
Screenshot from 2023-11-17 15-45-04

spec.update_variant_validate(variant_name, values)
try:
spec.update_variant_validate(variant_name, values)
except spack.error.SpackError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a more specific exception for this? Like VariantValueError or whatever?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what about requirements?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what about requirements?

Requirements are fine already. They will error, unless the requirement comes from the all: section in packages.yaml:

except Exception as e:
if rule.kind != RequirementKind.DEFAULT:
raise RuntimeError(
"cannot emit requirements for the solver: " + str(e)
) from e
continue

The overall idea there is that, since requirements are stricter, we shouldn't silently skip them if they cannot be applied.1

Footnotes

  1. Think of a typo like +opnmp. It would be better to error, than to skip and concretize to the opposite value.

Copy link
Copy Markdown
Member

@haampie haampie Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why guard against a typo +opnmp if +openmp errors because the vast majority of the package don't have that variant. It's guarding against typos so in return you can do ... nothing?

Copy link
Copy Markdown
Member Author

@alalazo alalazo Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll repeat. For requirements all: is permissive, specific packages are not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment below

This comment was marked as outdated.

@alalazo alalazo force-pushed the bugfix/preference-not-error branch from 847311f to 645ee8d Compare November 20, 2023 21:26
@alalazo alalazo requested a review from haampie November 21, 2023 08:43
@haampie
Copy link
Copy Markdown
Member

haampie commented Nov 22, 2023

To me the sensible thing to do is make requirements behave the same:

packages:
  all:
    require: +cuda

should require pkg +cuda for all pkg defining this variant.

That's the only way in which all-type variant requirements can possibly be useful, cause no variant exists (except for build_system) that is shared across all packages, making it impossible to use by definition.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Nov 22, 2023

@haampie Reconstructed what is happening here. This dates back to #35037 We have all the semantic we need and an awful syntax. My proposal is to add syntactic sugar for the all: case in a separate PR. The idea is to map any simple string in the requirement to the infamous any_of: [..., "@:"].

@haampie
Copy link
Copy Markdown
Member

haampie commented Nov 23, 2023

The any_of concept is not exactly equivalent though, cause you're giving the concretizer the option to ignore it.

It's equivalent to a preference that's stronger than reuse?

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Nov 23, 2023

The any_of concept is not exactly equivalent though, cause you're giving the concretizer the option to ignore it.

Yes. It will be mostly equivalent due to the priority we give to requirements, but not exactly equivalent to a requirement specified on the package.

The fact that we are a bit more permissive with all: in the enforcement of the requirement is in line with favoring usability. With:

spack:
  zlib:
    require: +shared

users cannot concretize or solve anything that explicitly needs ~shared:

$ spack spec zlib~shared
==> Error: concretization failed for the following reasons:

   1. cannot satisfy a requirement for package 'zlib'.

With:

spack:
  all:
    require: 
    - any_of: ["+shared", "@:"]

explicits request are possible:

$ spack spec zlib~shared
Input spec
--------------------------------
 -   zlib~shared

Concretized
--------------------------------
 -   [email protected]%[email protected]+optimize+pic~shared build_system=makefile arch=linux-ubuntu20.04-icelake
 -       ^[email protected]%[email protected]~guile build_system=generic arch=linux-ubuntu20.04-icelake

We can also have the same semantic for the two cases, which favors consistency, but in that case the occasional concretization of ~shared requires changing the config. Whatever we decide to do, I'd do that in a following PR and document the behavior, since I think there will still be edge cases that need the other solution.

@haampie
Copy link
Copy Markdown
Member

haampie commented Nov 23, 2023

Variants aren't the only requirement you can add in all, would be weird if %gcc or target=... were ignored.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Nov 23, 2023

Variants aren't the only requirement you can add in all, would be weird if %gcc or target=... were ignored.

They will be ignored when either explicitly set or required in a spec literal. That said, I also pointed out the other option and the consequence:

We can also have the same semantic for the two cases, which favors consistency, but in that case the occasional concretization of ~shared requires changing the config.

I don't have a preferred option, and both are doable.

@haampie
Copy link
Copy Markdown
Member

haampie commented Nov 23, 2023

I feel like "enforce when applicable" is the least surprising interpretation of requirements under all.

  • all:require:%gcc currently can be applied uniformly and people are already familiar with its semantics. To make the transition to non-binary packages non-breaking it can only mean "require gcc if the package needs a compiler".
  • all:require:+cuda can follow the same rule: enforce +cuda if the package defines the variant.

This leaves room for people to relax from strong requirement to "strong preference" with that any_of construct (for which we can always still improve syntax).

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Nov 23, 2023

So let's get this bug fix in and work on the improvement in the next PR?

@haampie haampie merged commit ee0d3a3 into spack:develop Nov 23, 2023
@alalazo alalazo deleted the bugfix/preference-not-error branch November 23, 2023 10:31
gabrielctn pushed a commit to gabrielctn/spack that referenced this pull request Nov 24, 2023
…#41138)

This commit discards type mismatches or failures to validate a package preference during concretization. The values discarded are logged as debug level messages. It also adds a config audit to help users spot misconfigurations in packages.yaml preferences.
mtaillefumier pushed a commit to mtaillefumier/spack that referenced this pull request Dec 14, 2023
…#41138)

This commit discards type mismatches or failures to validate a package preference during concretization. The values discarded are logged as debug level messages. It also adds a config audit to help users spot misconfigurations in packages.yaml preferences.
alalazo added a commit that referenced this pull request Jan 2, 2024
This commit discards type mismatches or failures to validate a package preference during concretization. The values discarded are logged as debug level messages. It also adds a config audit to help users spot misconfigurations in packages.yaml preferences.
alalazo added a commit that referenced this pull request Jan 10, 2024
This commit discards type mismatches or failures to validate a package preference during concretization. The values discarded are logged as debug level messages. It also adds a config audit to help users spot misconfigurations in packages.yaml preferences.
haampie pushed a commit that referenced this pull request Jan 11, 2024
This commit discards type mismatches or failures to validate a package preference during concretization. The values discarded are logged as debug level messages. It also adds a config audit to help users spot misconfigurations in packages.yaml preferences.
RikkiButler20 pushed a commit to RikkiButler20/spack that referenced this pull request Jan 31, 2024
…#41138)

This commit discards type mismatches or failures to validate a package preference during concretization. The values discarded are logged as debug level messages. It also adds a config audit to help users spot misconfigurations in packages.yaml preferences.
vjranagit pushed a commit to vjranagit/spack that referenced this pull request Jan 18, 2026
…#41138)

This commit discards type mismatches or failures to validate a package preference during concretization. The values discarded are logged as debug level messages. It also adds a config audit to help users spot misconfigurations in packages.yaml preferences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core PR affects Spack core functionality stand-alone-tests Stand-alone (or smoke) tests for installed packages tests General test capability(ies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concretization errors if a preference doesn't match the type of the variant for a package

2 participants