Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explanations Table #719

Merged
merged 72 commits into from
May 29, 2024
Merged

Explanations Table #719

merged 72 commits into from
May 29, 2024

Conversation

wags-1314
Copy link
Collaborator

@wags-1314 wags-1314 commented Feb 2, 2024

This PR adds functionality and some more stats to the explanations algorithm:

  • Adds a table showing explanations for each erroneous subexpression along with count
  • Compares the algorithm to total error, and then calculates the confusion matrix, and precision recall for our predictions
  • Shows root cause of overflows and underflows for rescues

Copy link
Contributor

@pavpanchekha pavpanchekha left a comment

Choose a reason for hiding this comment

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

We should merge, even if there are more cleanups possible, just to keep this in sync with the rest of Herbie.

Comment on lines 535 to 538
[(and (or (bf> cond-x cond-thres)
(bf> cond-y cond-thres))
(not (constant? y-ex)))
(mark-erroneous! subexpr 'sensitivity)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue with pow(x, 1000). I think we need:

if G_x > 100 && ! exact(x)
if G_y > 100 && ! exact(y)

src/error-table.rkt Outdated Show resolved Hide resolved
(mark-maybe! subexpr 'sensitivity)]
[(and (bf> cond-no maybe-cond-thres)
(bf> cot-x maybe-cond-thres))
(mark-maybe! subexpr 'cancellation)]
[else #f])]

[(list (or 'cos.f64 'cos.f32) x-ex)
#:when (list? x-ex)
Copy link
Contributor

Choose a reason for hiding this comment

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

So I think list? is not quite right, because it can be a constant but not one exactly representable in float, like 1/3. There's gotta be some way to do this exactly right.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have been thinking about this. I think it should be a composition of (a) expression that's a product or quotient of constants and (b) representable in floating point. (a) is easy enough not sure how to do (b).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should write a little wrapper around eval-application and it can check something like:

(define (exact-constant? expr)
  (let ([val (eval-application-recursively expr)])
    (and val (= val (exact->inexact val)))))

Would be even better to use real->representation instead of just exact->inexact but that is more complex.

@@ -49,28 +64,87 @@
(make-immutable-hash (map cons
subexprs-list
(map context-repr ctx-list))))


(define subexprs-fn (eval-progs-real spec-list ctx-list))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want this to be (compile-progs exprs ctx) but there might be issues with different ctxs but maybe we're ok with some expressions erroring for now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will it crash on booleans and if? If yes, then I'd rather not use it because right now we don't get crashes on booleans and if.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not mess with this for now.

bench/numerics/test.py Outdated Show resolved Hide resolved
src/error-table.rkt Outdated Show resolved Hide resolved

(define subexprs
(all-subexpressions-rev expr (context-repr ctx)))
(define subexprs-list (map car subexprs))
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to make all-subexpressions-rev return the same kind of thing as all-subexpressions, in other words have it return what is called subexprs-list here. Then the code could be a little nicer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine to do in another PR

Comment on lines 77 to 80
(define repr-hash
(make-immutable-hash (map cons
subexprs-list
(map context-repr ctx-list))))
Copy link
Contributor

Choose a reason for hiding this comment

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

You also wouldn't need repr-hash if we changed all-sub...s-rev

src/error-table.rkt Outdated Show resolved Hide resolved
src/error-table.rkt Outdated Show resolved Hide resolved
@pavpanchekha
Copy link
Contributor

Proposal: let's not fix the exact-expr thing in this PR, let's do that in another PR, and merge this PR now.

@pavpanchekha
Copy link
Contributor

There are two extra crashes, otherwise let's merge

@wags-1314
Copy link
Collaborator Author

Closing this in favor of #824

@wags-1314 wags-1314 closed this May 29, 2024
@wags-1314 wags-1314 reopened this May 29, 2024
@wags-1314
Copy link
Collaborator Author

Forgot to push the fix, sorry

@wags-1314 wags-1314 merged commit d3c34d8 into main May 29, 2024
12 checks passed
@pavpanchekha pavpanchekha deleted the explanations-table branch May 30, 2024 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants