Skip to content

Print final conflict set when search is exhaustive - #3960

Merged
sebright merged 9 commits into
haskell:masterfrom
fmthoma:fmthoma/print-conflict-set
Dec 3, 2016
Merged

sebright merged 9 commits into
haskell:masterfrom
fmthoma:fmthoma/print-conflict-set

Conversation

@fmthoma

@fmthoma fmthoma commented Oct 8, 2016

Copy link
Copy Markdown
Collaborator

Pull request for #3570.

The final confilct set is printed along with the conflict count of each conflict, if available.

Open for discussion:

  • The original error message is thrown away, we currently only show the conflilct set. Should we restore it and print both?
  • The conflict count is not actually a useful metric. Should we expose it, or should we rescale it to something more useful to the user?

@mention-bot

Copy link
Copy Markdown

@fmthoma, thanks for your PR! By analyzing the history of the files in this pull request, we identified @GrayJay, @kosmikus and @edsko to be potential reviewers.

@@ -40,25 +40,25 @@ logToProgress mbj l = let
-- and ignores repeated backjumps. If proc reaches the backjump limit, it truncates

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not something you need to do for this patchset, but someday we should explain to mere mortals what a conflict set is :)

@ezyang

ezyang commented Oct 8, 2016

Copy link
Copy Markdown
Contributor

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

@fmthoma

fmthoma commented Oct 9, 2016

Copy link
Copy Markdown
Collaborator Author

@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: …«.

@fmthoma
fmthoma force-pushed the fmthoma/print-conflict-set branch from f34346a to 8b25ed4 Compare October 9, 2016 10:24
@ezyang

ezyang commented Oct 9, 2016

Copy link
Copy Markdown
Contributor

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.

@fmthoma
fmthoma force-pushed the fmthoma/print-conflict-set branch from 8b25ed4 to 56b1c5f Compare October 10, 2016 19:01
@fmthoma

fmthoma commented Oct 10, 2016

Copy link
Copy Markdown
Collaborator Author

@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 package1 (10000), package2 (9999) and package1 (10000), package2 (3) that is not neglectable). So here are some suggestions:

  • Print the numbers as they are
  • Defer them to verbose mode
  • Normalize them to something more useful (e.g. to percentage of all conflicts)
  • Use them to further reduce the output, e.g. cut off all packages that contribute less than 1..10% of all conflicts.

The warning should be gone now, I overlooked a Control.Applicative import.

@ezyang

ezyang commented Oct 10, 2016

Copy link
Copy Markdown
Contributor

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.

@fmthoma

fmthoma commented Oct 10, 2016

Copy link
Copy Markdown
Collaborator Author

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.

@phadej

phadej commented Oct 11, 2016 •

Copy link
Copy Markdown
Collaborator

@GrayJay, use

import Prelude ()         
import Distribution.Client.Compat.Prelude

(related to Control.Applicative)

@sebright sebright left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have a few comments, but everything else looks good. Thanks for adding this!

@@ -67,8 +67,6 @@ backjump (EnableBackjumping enableBj) var initial xs =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, changed it in the PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@fmthoma Actually, the code that I linked to above isn't enough to prevent space leaks. I had to fix it in 41cd786.

getFirstGoal doesn't evaluate the conflict map unless there is more than one goal, so it is possible for a thunk to develop even with --count-conflicts. Using seq is more reliable.

messages :: Progress step fail done -> [step]
messages = foldProgress (:) (const []) (const [])

data Exhaustive = Exhaustive | NotExhaustive

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this be "Backjump limit reached"?

@fmthoma fmthoma Oct 14, 2016 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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) ++

@sebright sebright Oct 12, 2016 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@fmthoma fmthoma Nov 20, 2016 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

  1. either by choosing to print the first rather than the final conflict set also in the exhaustive case (what would this imply?),
  2. 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),
  3. 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).)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like option (2).

  1. 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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That looks good. Should it be "the rest of the dependencies"?

@fmthoma fmthoma Nov 29, 2016 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

»rest of the dependency tree«, actually. Just pushed the change.

EDIT: And rebased onto master to resolve conflicts.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@fmthoma

fmthoma commented Oct 14, 2016

Copy link
Copy Markdown
Collaborator Author

@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.
@kosmikus: Do you agree with @GrayJay and @ezyang to show the counts only in verbose mode?

@23Skidoo

Copy link
Copy Markdown
Member

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.

@fmthoma
fmthoma force-pushed the fmthoma/print-conflict-set branch 2 times, most recently from 3ed9af4 to 64306bf Compare November 11, 2016 18:30
@fmthoma
fmthoma force-pushed the fmthoma/print-conflict-set branch from 9cb4b0c to 4839eaf Compare November 21, 2016 08:28
@fmthoma
fmthoma force-pushed the fmthoma/print-conflict-set branch from 4839eaf to ad04e74 Compare November 29, 2016 21:54
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)
```
@fmthoma
fmthoma force-pushed the fmthoma/print-conflict-set branch from ad04e74 to 2fe9c40 Compare November 29, 2016 22:15
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.

@sebright sebright left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@@ -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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

@23Skidoo

23Skidoo commented Dec 3, 2016

Copy link
Copy Markdown
Member

@GrayJay @fmthoma Feel free to merge once the CI is green if you think that this PR is ready to go in.

@sebright

sebright commented Dec 3, 2016

Copy link
Copy Markdown
Collaborator

It's green, so I'll merge it. Thanks, @fmthoma!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants