Repository navigation
Print final conflict set when search is exhaustive - #3960
Conversation
| @@ -40,25 +40,25 @@ logToProgress mbj l = let | |||
| -- and ignores repeated backjumps. If proc reaches the backjump limit, it truncates | |||
There was a problem hiding this comment.
This comment needs updating.
| replace _ (Done x) = Done x | ||
| replace cs' (Fail cs) = -- 'Nothing' means backjump limit not reached. | ||
| replace cs' (Fail (exh, cs)) = -- 'Nothing' means backjump limit not reached. | ||
| -- Prefer first error over later error. |
There was a problem hiding this comment.
This comment needs updating (something about doing something specifically when you exhaust search space?)
| currlimit Nothing = "" | ||
| go ms _ (Fail (exh, cs)) = Fail $ "Could not resolve dependencies:\n" ++ if exh | ||
| then "Dependency tree exhaustively searched.\n" ++ | ||
| "Final conflict set is: " ++ CS.showCS cs |
There was a problem hiding this comment.
Not something you need to do for this patchset, but someday we should explain to mere mortals what a conflict set is :)
|
Since this is just user visible business, it doesn't look that easy to automated test. But it would be nice if the commit messages included some sample output, i.e., "What would I expect to see with this new change?" For example, something like in da38822 |
|
@ezyang Thank you for your review comments! I have addressed them in my updates. Also I have changed the message to a slightly less technical »I've had most trouble fulfilling the following goals: …«. |
f34346a to
8b25ed4
Compare
|
Thanks! Really helpful. CI failure is real though; try building locally with -Werror. I wonder if we should print the conflict counts in non-verbose mode. They don't seem that useful for someone who doesn't know what they are. |
8b25ed4 to
56b1c5f
Compare
|
@ezyang: I had this discussion with @kosmikus as well. On one hand, the absolute numbers do not provide any useful metric. On the other hand, their relative values do provide a tendency how severe a conflict is (there is a difference between
The warning should be gone now, I overlooked a |
|
I'm OK with leaving the counts, I just want to open up a discussion. Actually, while we're at it, why don't we talk about what the conflict counts mean in the first place. My understanding is they is they specify how many times a package shows up in a "conflict set", which is a set of packages that have incompatible constraints that cause a solution to be unsat. Is this accurate? This makes me wonder: the solver is supposed to bail out early when it encounters a conflict. So the actual conflict counts are going to be heavily dependent on the order the solver attempted to solve packages in. |
Yes, this shows up for example in #3961 where the counts are heavily dependent on how we accumulate them while backjumping. So these numbers are not an exact science, but they give a good indication nevertheless. I personally would probably prefer from a user perspective to have percentages (»This package was involved in about n% of all conflicts«) and a sensible cutoff. |
|
@GrayJay, use import Prelude ()
import Distribution.Client.Compat.Prelude(related to |
sebright
left a comment
There was a problem hiding this comment.
I have a few comments, but everything else looks good. Thanks for adding this!
| @@ -67,8 +67,6 @@ backjump (EnableBackjumping enableBj) var initial xs = | |||
|
|
|||
There was a problem hiding this comment.
I just realized that the line above updates the conflict map even when countConflicts is false. It should probably be something like if countConflicts then (cs, updateCM initial cm) else (cs, cm) to avoid creating a thunk from the conflict map when it isn't used.
There was a problem hiding this comment.
Good catch, changed it in the PR.
There was a problem hiding this comment.
This change avoids modifying the map, but it still creates a thunk when the map isn't read, because cm' is never evaluated. We had to prevent a similar space leak here by only calling a function on the map in the --count-conflicts case: https://github.com/fmthoma/cabal/blob/9cb4b0cd3bb89801edd02d8e95440ce1772e1c3f/cabal-install/Distribution/Solver/Modular/Explore.hs#L121-L123
Or you could use seq:
in cm' `seq` failWith (Failure cs Backjump) (cs, cm')
There was a problem hiding this comment.
| messages :: Progress step fail done -> [step] | ||
| messages = foldProgress (:) (const []) (const []) | ||
|
|
||
| data Exhaustive = Exhaustive | NotExhaustive |
There was a problem hiding this comment.
I think Exhaustiveness would be clearer.
| replace _ (Done x) = Done x | ||
| replace cs' (Fail cs) = -- 'Nothing' means backjump limit not reached. | ||
| replace _ (Fail (Exhaustive, cs, cm)) = Fail (Exhaustive, cs, cm) | ||
| replace cs' (Fail (NotExhaustive, cs, cm)) = -- Backjump limit not reached. |
There was a problem hiding this comment.
Should this be "Backjump limit reached"?
There was a problem hiding this comment.
Indeed, I'll change the data Exhaustive to data Exhaustiveness = Exhaustive | BackjumpLimitReached so the comment is now unnecessary.
| currlimit Nothing = "" | ||
| go ms _ (Fail (exh, cs, cm)) = Fail $ | ||
| "Could not resolve dependencies:\n" ++ | ||
| unlines (messages $ showMessages (L.foldr (\ v _ -> v `CS.member` cs) True) False ms) ++ |
There was a problem hiding this comment.
It looks like cs is the first conflict set when the backjump limit is reached and the last conflict set when the search is exhaustive. Shouldn't this line always filter the short log using the first conflict set? The final conflict set might not contain the first error, which would cause the error to be filtered out.
Another option is to remove the filtered log altogether, to avoid showing two possibly unrelated errors.
There was a problem hiding this comment.
In the BackjumpLimitReached case, the behavior is unchanged (cs being the first conflict set). In the Exhaustive case, cs is indeed the final conflict set, but it seems to me that also the displayed error is the final error? Maybe I'm looking at this the wrong way...
BTW, what is the original rationale anyway for showing the first rather than the last error in case the backjump limit is reached?
There was a problem hiding this comment.
The solver always prints ms, which is the log to the first error. It truncates the log on the line es = proc (Just 0) l -- catch first error (always) above.
BTW, what is the original rationale anyway for showing the first rather than the last error in case the backjump limit is reached?
According to the discussion in #941, the first error was chosen because the solver has made fewer compromises at that point, and the conflicts are more likely to be relevant. Also, I don't think that there is an obvious place to start printing the summarized log leading up to the final error. The log wouldn't always include the top of the tree.
There was a problem hiding this comment.
Okay, so to summarize:
- We always print the first error encountered.
- In case the backjump limit is reached, we print the first conflict set (which coincides with the first error).
- For an exhaustive search, we print the final conflict set (which may not coincide with the first error).
So this could be solved
- either by choosing to print the first rather than the final conflict set also in the exhaustive case (what would this imply?),
- or by printing the error only in the non-exhaustive case and thus avoiding the problem (in fact, in an early version of the PR, @kosmikus and I had printed the error message only in the non-exhaustive case, but we changed it),
- or by printing the last error in the
non-exhaustive case.
My understanding of the issue is still somewhat incomplete, but it seems to me that using the reasoning from #941 also applies to the exhaustive case, so option (1) looks to me like the soundest one?
(EDIT: non-exhaustive ↦ exhaustive in option (3).)
There was a problem hiding this comment.
I like option (2).
- either by choosing to print the first rather than the final conflict set also in the exhaustive case (what would this imply?),
I think that the first conflict set isn't very useful, because it comes from the first node where the solver backjumps, which is near the leaves of the tree. It contains the same information as the first error. However, the final conflict set is assigned to the root of the tree (in the exhaustive case), and it summarizes all conflicts in the tree. It means that any solution to the dependency problem would need to assign a value that isn't available in the search tree to at least one of the variables in the conflict set.
The solver's conflict sets differ from the ones in Modular lazy search for Constraint Satisfaction Problems because they can also contain variables that are below the current node. That difference makes the final conflict set more useful.
3 . or by printing the last error in the non-exhaustive case.
I'm not sure how this makes the behavior more consistent, or did you mean the exhaustive case?
There was a problem hiding this comment.
How about a message conveying that the error does not need to be in line with the final conflict set:
> cabal install --dry-run cabal-install-1.24.0.0 cabal-install-1.22.9.0
Resolving dependencies...
cabal: Could not resolve dependencies:
next goal: cabal-install (user goal)
rejecting: cabal-install-1.24.0.0 (constraint from user target requires
==1.22.9.0)
rejecting: cabal-install-1.22.9.0 (constraint from user target requires
==1.24.0.0)
rejecting: cabal-install-1.22.8.0, cabal-install-1.22.7.0,
cabal-install-1.22.6.0, cabal-install-1.22.5.0, cabal-install-1.22.4.0,
cabal-install-1.22.3.0, cabal-install-1.22.2.0, cabal-install-1.22.0.1,
cabal-install-1.22.0.0, cabal-install-1.20.2.0, cabal-install-1.20.1.0,
cabal-install-1.20.0.6, cabal-install-1.20.0.5, cabal-install-1.20.0.4,
cabal-install-1.20.0.3, cabal-install-1.20.0.2, cabal-install-1.20.0.1,
cabal-install-1.20.0.0, cabal-install-1.18.2.0, cabal-install-1.18.1.0,
cabal-install-1.18.0.8, cabal-install-1.18.0.7, cabal-install-1.18.0.6,
cabal-install-1.18.0.5, cabal-install-1.18.0.4, cabal-install-1.18.0.3,
cabal-install-1.18.0.2, cabal-install-1.18.0.1, cabal-install-1.18.0,
cabal-install-1.16.1.0, cabal-install-1.16.0.2, cabal-install-1.16.0.1,
cabal-install-1.16.0, cabal-install-0.14.1, cabal-install-0.14.0,
cabal-install-0.10.2, cabal-install-0.10.0, cabal-install-0.8.2,
cabal-install-0.8.0, cabal-install-0.6.4, cabal-install-0.6.2,
cabal-install-0.6.0, cabal-install-0.5.2, cabal-install-0.5.1,
cabal-install-0.5.0, cabal-install-0.4.0 (constraint from user target requires
==1.22.9.0)
After searching the rest of the dependency exhaustively, these were the goals
I had most trouble fulfilling: cabal-install (49)
There was a problem hiding this comment.
That looks good. Should it be "the rest of the dependencies"?
There was a problem hiding this comment.
»rest of the dependency tree«, actually. Just pushed the change.
EDIT: And rebased onto master to resolve conflicts.
There was a problem hiding this comment.
That looks good. So I think the only thing left is changing the summarized log so that it is always filtered with the first conflict set.
There was a problem hiding this comment.
Please have a look at the last commit. Now the summarized log should be filtered with the first conflict set. This involved removing useFirstError and changing the traversal of the log in the go function, making go partial again, so I hope I didn't break anything.
| Exhaustive -> | ||
| "Dependency tree exhaustively searched.\n" ++ | ||
| "I've had most trouble fulfilling the following goals: " | ||
| ++ CS.showCSWithFrequency cm cs |
There was a problem hiding this comment.
I wonder if we should only show the counts at higher verbosity, since there are cases where they could be misleading. For example, the solver could immediately stop after finding a missing dependency, which would give the missing dependency a count of 1, even though it is part of a minimal conflict set.
|
@GrayJay, @ezyang: I think it makes sense to show the conflict counts only on a higher verbosity level. However, this requires either passing the verbosity to the solver (which is kind of an intrusive change), or to change the return type of the solver (which is also quite intrusive). I am working on this, but I would rather suggest we merge this pull request without this change, and I open another one with the conflict counts only on verbose. |
Fine with me. |
3ed9af4 to
64306bf
Compare
9cb4b0c to
4839eaf
Compare
4839eaf to
ad04e74
Compare
Keep information about the final conflict set and print it in case of exhaustive search. The original error message is not printed any more.
Conflicts are sorted by conflict counts, so high-rated conflicts appear early in the list. Currently the raw count is printed.
Output the last error message in addition to the final conflict set, and give a less technical description of the conflict set for the user message. An example for the expected output is: > cabal install --dry-run DPM CurryDB DAV DSH Digit HList MagicHaskeller bamboo cabal: Could not resolve dependencies: trying: CurryDB-0.1.1.0 (user goal) trying: base-4.8.0.0/installed-1b6... (dependency of CurryDB-0.1.1.0) trying: unix-2.7.1.0/installed-e59... (dependency of process-1.2.3.0/installed-3b1...) trying: directory-1.2.2.0/installed-b49... (dependency of process-1.2.3.0/installed-3b1...) Dependency tree exhaustively searched. I've had most trouble fulfilling the following goals: haskell98 (36850), base (26359), directory (9599), HTF (5092), bamboo (3788), DPM (3452), unix (3208), CurryDB (107)
The error displayed is the first error, which matches the first conflict set in the non-exhaustive case. In the exhaustive case, however, we display the last conflict set alongside the first error. The change in the error message, »the rest of the dependency tree«, should make it clearer that the error may not come from the final branches of the dependency tree, but that there may be a lot of branches being traversed between the first error and the final conflict set, so they may not be congruent. (Reasoning for displaying the first rather than the last error in the non-exhaustive case: Both the first and the last error may be occur near the leaves, so the conflict set may be incomplete. At the first backjump, however, the conflicts are more likely to be relevant as the solver has made fewer compromises at that point. In the exhaustive case, this is not relevant as the final conflict set is located at the root, so the conflict set contains all the conflicts of a certain path through the tree. This is much more useful than the first conflict set.) Example: ``` > ./.stack-work/install/x86_64-linux-nix/ghc-8.0.1/8.0.1/bin/cabal install --dry-run cabal-install-1.24.0.0 cabal-install-1.22.9.0 Warning: The package list for 'hackage.haskell.org' is 46 days old. Run 'cabal update' to get the latest list of available packages. Resolving dependencies... cabal: Could not resolve dependencies: next goal: cabal-install (user goal) rejecting: cabal-install-1.24.0.0 (constraint from user target requires ==1.22.9.0) rejecting: cabal-install-1.22.9.0 (constraint from user target requires ==1.24.0.0) rejecting: cabal-install-1.22.8.0, cabal-install-1.22.7.0, cabal-install-1.22.6.0, cabal-install-1.22.5.0, cabal-install-1.22.4.0, cabal-install-1.22.3.0, cabal-install-1.22.2.0, cabal-install-1.22.0.1, cabal-install-1.22.0.0, cabal-install-1.20.2.0, cabal-install-1.20.1.0, cabal-install-1.20.0.6, cabal-install-1.20.0.5, cabal-install-1.20.0.4, cabal-install-1.20.0.3, cabal-install-1.20.0.2, cabal-install-1.20.0.1, cabal-install-1.20.0.0, cabal-install-1.18.2.0, cabal-install-1.18.1.0, cabal-install-1.18.0.8, cabal-install-1.18.0.7, cabal-install-1.18.0.6, cabal-install-1.18.0.5, cabal-install-1.18.0.4, cabal-install-1.18.0.3, cabal-install-1.18.0.2, cabal-install-1.18.0.1, cabal-install-1.18.0, cabal-install-1.16.1.0, cabal-install-1.16.0.2, cabal-install-1.16.0.1, cabal-install-1.16.0, cabal-install-0.14.1, cabal-install-0.14.0, cabal-install-0.10.2, cabal-install-0.10.0, cabal-install-0.8.2, cabal-install-0.8.0, cabal-install-0.6.4, cabal-install-0.6.2, cabal-install-0.6.0, cabal-install-0.5.2, cabal-install-0.5.1, cabal-install-0.5.0, cabal-install-0.4.0 (constraint from user target requires ==1.22.9.0) After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: cabal-install (49) ```
ad04e74 to
2fe9c40
Compare
Before this change, the behavior in the exhaustive case was to filter the log up until the first error with the final conflict set, leading to possibly inconsistently filtered error messages. Now we always use the conflict set from the first error to filter the the log, and then display the final conflict set as an additional hint.
| @@ -70,19 +60,29 @@ logToProgress mbj l = let | |||
| -- | |||
| -- The third argument is the full log, ending with either the solution or the | |||
| -- exhaustiveness and first conflict set. | |||
There was a problem hiding this comment.
This is now the final conflict set.
| Fail (isNothing cs, cs' <|> cs) | ||
| replace Nothing (Step x@(Failure cs Backjump) xs) = Step x $ replace (Just cs) xs | ||
| replace cs' (Step x xs) = Step x $ replace cs' xs | ||
|
|
|
It's green, so I'll merge it. Thanks, @fmthoma! |
Pull request for #3570.
The final confilct set is printed along with the conflict count of each conflict, if available.
Open for discussion: