Skip to content

Commit dd66cc0

Browse files
authored
Merge pull request #1280 from herbie-fp/remove-obsolete-timeline
General-purpose cleanup across Herbie
2 parents 33912b6 + bda64e4 commit dd66cc0

File tree

18 files changed

+95
-314
lines changed

18 files changed

+95
-314
lines changed

AGENT.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11

22
# Testing
33

4-
- Before presenting any code run `make fmt` to format the code. This
5-
is mandatory and PRs that don't follow the coding style are
6-
rejected.
7-
- As a quick test to make sure everything is working, you can run
8-
`racket src/main.rkt report bench/tutorial.fpcore tmp`; this should
9-
take about 5-10 seconds and all of the tests should pass, getting
10-
basically perfect accuracy.
11-
- You can also run the unit tests with `raco test src/`, but these
12-
aren't very complete; focus more on the full run from the previous
13-
bullet point.
4+
- Run `make fmt` to format the code before presentingcode. This is
5+
mandatory and PRs that don't follow the coding style are rejected.
6+
- Run `racket src/main.rkt report bench/tutorial.fpcore tmp` to test
7+
that your changes work; this should take about 5-10 seconds and all
8+
of the tests should pass, getting basically perfect accuracy.
9+
- You can also run the unit tests with `raco test <file>`, when unit
10+
tests exist. Often they don't.
1411

1512
# PRs
1613

17-
- PR descriptions should be in full sentences one to a few paragraphs
18-
paragraphs in length. For all but the most trivial fixes, describe
19-
the current behavior and why you changed it.
14+
- PR descriptions should be 1-3 paragraphs in length. Describe the
15+
current behavior and why you changed it. Avoid bullet points.
2016
- Be explicit about the expected impact: "should be faster", "should
21-
be more accurate", "pure refactor, not changes", and so on.
17+
be more accurate", "pure refactor, no changes", and so on.

infra/merge.rkt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
(filter (conjoin (negate eof-object?) identity)
1414
(for/list ([dir (in-list dirs)])
1515
(with-handlers ([exn? (const #f)])
16-
(define tl (call-with-input-file (build-path outdir dir "timeline.json") read-json))
17-
(timeline-relink dir tl)))))
16+
(call-with-input-file (build-path outdir dir "timeline.json") read-json)))))
1817
(define info (call-with-input-file (build-path outdir (first dirs) "results.json") read-datafile))
1918
(define joint-tl (apply timeline-merge tls))
2019
(call-with-output-file (build-path outdir "timeline.json")

src/api/datafile.rkt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
#:prefab)
3636

3737
(struct report-info (date commit branch seed flags points iterations tests merged-cost-accuracy)
38-
#:prefab
39-
#:mutable)
38+
#:prefab)
4039

4140
(define (make-report-info tests #:seed [seed #f])
4241
(report-info (current-date)
@@ -228,9 +227,6 @@
228227
cost-accuracy)))
229228
(hash-ref json 'merged-cost-accuracy null)))
230229

231-
(define (unique? a)
232-
(or (null? a) (andmap (curry equal? (car a)) (cdr a))))
233-
234230
(define (merge-datafiles dfs #:dirs [dirs #f])
235231
(when (null? dfs)
236232
(error 'merge-datafiles "Cannot merge no datafiles"))
@@ -239,7 +235,7 @@
239235
report-info-flags
240236
report-info-points
241237
report-info-iterations))]
242-
#:unless (unique? (map f dfs)))
238+
#:unless (<= (set-count (list->set (map f dfs))) 1))
243239
(error 'merge-datafiles "Cannot merge datafiles at different ~a" f))
244240
(unless dirs
245241
(set! dirs (map (const #f) dfs)))

src/api/run.rkt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@
5656
(define out
5757
(with-handlers ([exn? (const #f)])
5858
(call-with-input-file (build-path dir (table-row-link res) name) read-json)))
59-
(and out (not (eof-object? out)) (cons (table-row-link res) out)))))
60-
61-
(define (merge-timeline-jsons tl)
62-
(apply timeline-merge (map timeline-relink (dict-keys tl) (dict-values tl))))
59+
(and out (not (eof-object? out)) out))))
6360

6461
(define (merge-profile-jsons ps)
65-
(profile->json (apply profile-merge (map json->profile (dict-values ps)))))
62+
(profile->json (apply profile-merge (map json->profile ps))))
6663

6764
(define (generate-bench-report result bench-name test-number dir total-tests)
6865
(define report-path (bench-folder-path bench-name test-number))
@@ -105,7 +102,7 @@
105102
(copy-file (web-resource "report.css") (build-path dir "report.css") #t)
106103
(copy-file (web-resource "logo-car.png") (build-path dir "logo-car.png") #t)
107104
(copy-file (web-resource "report.html") (build-path dir "index.html") #t)
108-
(define timeline (merge-timeline-jsons (read-json-files info dir "timeline.json")))
105+
(define timeline (apply timeline-merge (read-json-files info dir "timeline.json")))
109106
(call-with-output-file (build-path dir "timeline.json")
110107
(curry write-json timeline)
111108
#:exists 'replace)

src/api/sandbox.rkt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
(provide run-herbie
2929
get-table-data-from-hash
3030
*reeval-pts*
31-
*timeout*
3231
(struct-out job-result)
3332
(struct-out improve-result)
3433
(struct-out alt-analysis))
@@ -92,10 +91,6 @@
9291
(define end-errs (map cdr sorted-end-exprs))
9392
(define end-data (map alt-analysis alternatives end-errs))
9493

95-
;; bundle up the result
96-
(timeline-adjust! 'regimes 'name (test-name test))
97-
(timeline-adjust! 'regimes 'link ".")
98-
9994
(improve-result preprocessing test-pcontext* start-alt-data target-alt-data end-data))
10095

10196
(define (get-cost test)

src/config.rkt

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,40 @@
4040
branches)]
4141
[dump . ()]))
4242

43-
(define (check-flag-deprecated! category flag)
43+
(define (flag-deprecated? category flag)
44+
(match* (category flag)
45+
[('precision 'double) #t]
46+
[('precision 'fallback) #t]
47+
[('setup 'simplify) #t]
48+
[('generate 'better-rr) #t]
49+
[('generate 'simplify) #t]
50+
[('reduce 'simplify) #t]
51+
[('reduce 'avg-error) #t]
52+
[('localize 'costs) #t]
53+
[('localize 'errors) #t]
54+
[(_ _) #f]))
55+
56+
; `hash-copy` returns a mutable hash, which makes `dict-update` invalid
57+
(define *flags* (make-parameter (make-immutable-hash (hash->list default-flags))))
58+
59+
(define (flag-set? class flag)
60+
(set-member? (dict-ref (*flags*) class) flag))
61+
62+
(define (enable-flag! category flag)
63+
(when (flag-deprecated? category flag)
64+
(warn-flag-deprecated! category flag))
65+
(define (update cat-flags)
66+
(set-add cat-flags flag))
67+
(*flags* (dict-update (*flags*) category update)))
68+
69+
(define (disable-flag! category flag)
70+
(when (flag-deprecated? category flag)
71+
(warn-flag-deprecated! category flag))
72+
(define (update cat-flags)
73+
(set-remove cat-flags flag))
74+
(*flags* (dict-update (*flags*) category update)))
75+
76+
(define (warn-flag-deprecated! category flag)
4477
(match* (category flag)
4578
[('precision 'double)
4679
(eprintf "The precision:double option has been removed.\n")
@@ -80,31 +113,6 @@
80113
(eprintf "See <herbie://herbie.uwplse.org/doc/~a/options.html> for more.\n" *herbie-version*)]
81114
[(_ _) (void)]))
82115

83-
(define (enable-flag! category flag)
84-
(check-flag-deprecated! category flag)
85-
(define (update cat-flags)
86-
(set-add cat-flags flag))
87-
(*flags* (dict-update (*flags*) category update)))
88-
89-
(define (disable-flag! category flag)
90-
(check-flag-deprecated! category flag)
91-
(define (update cat-flags)
92-
(set-remove cat-flags flag))
93-
(*flags* (dict-update (*flags*) category update)))
94-
95-
(define (flag-set? class flag)
96-
(set-member? (dict-ref (*flags*) class) flag))
97-
98-
(define (flag-deprecated? category flag)
99-
(match* (category flag)
100-
[('precision 'double) #t]
101-
[('precision 'fallback) #t]
102-
[('generate 'better-rr) #t]
103-
[(_ _) #f]))
104-
105-
; `hash-copy` returns a mutable hash, which makes `dict-update` invalid
106-
(define *flags* (make-parameter (make-immutable-hash (hash->list default-flags))))
107-
108116
(define (changed-flags)
109117
(filter identity
110118
(for*/list ([(class flags) all-flags]
@@ -130,8 +138,6 @@
130138
;; The maximum number of consecutive skipped points for sampling valid points
131139
(define *max-skipped-points* (make-parameter 100))
132140

133-
(define *max-bsearch-bits* (make-parameter 48))
134-
135141
;; Maximum MPFR precision allowed during exact evaluation
136142
(define *max-mpfr-prec* (make-parameter 10000))
137143

@@ -140,9 +146,6 @@
140146
(define *proof-max-length* (make-parameter 200))
141147
(define *proof-max-string-length* (make-parameter 10000))
142148

143-
;; In localization, the maximum number of locations returned
144-
(define *localize-expressions-limit* (make-parameter 4))
145-
146149
;; How long of a Taylor series to generate; too long and we time out
147150
(define *taylor-order-limit* (make-parameter 4))
148151

@@ -175,6 +178,20 @@
175178
;; The number of iterations for the egglog search
176179
(define *default-egglog-iter-limit* (make-parameter 50))
177180

181+
;;; The random seed
182+
183+
(define the-seed #f)
184+
185+
(define (get-seed)
186+
(or the-seed (error "Seed is not set yet!")))
187+
188+
(define (set-seed! seed)
189+
"Reset the random number generator to a new seed"
190+
(set! the-seed seed)
191+
(if (vector? seed)
192+
(current-pseudo-random-generator (vector->pseudo-random-generator seed))
193+
(random-seed seed)))
194+
178195
;;; About Herbie:
179196

180197
(define (run-command cmd)

src/core/bsearch.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
;; Invariant: (pred p1) and (not (pred p2))
7070
(define (binary-search-floats pred p1 p2 repr)
7171
(cond
72-
[(<= (ulps->bits (ulp-difference p1 p2 repr)) (*max-bsearch-bits*))
72+
[(<= (ulps->bits (ulp-difference p1 p2 repr)) (*binary-search-accuracy*))
7373
(timeline-push! 'stop "narrow-enough" 1)
7474
(values p1 p2)]
7575
[else
@@ -151,7 +151,7 @@
151151
(define (left-point p1 p2)
152152
(define left ((representation-repr->bf repr) p1))
153153
(define right ((representation-repr->bf repr) p2))
154-
(define out
154+
(define out ; TODO: Try using bigfloat-pick-point here?
155155
(if (bfnegative? left)
156156
(bigfloat-interval-shortest left (bfmin (bf/ left 2.bf) right))
157157
(bigfloat-interval-shortest left (bfmin (bf* left 2.bf) right))))

src/core/preprocess.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
[(< (length result) (length preprocessing))
165165
(remove-unnecessary-preprocessing expression context pcontext result #:removed newly-removed)]
166166
[else
167-
(timeline-push! 'remove-preprocessing (map ~a newly-removed))
167+
(timeline-push! 'symmetry (map ~a result))
168168
result]))
169169

170170
(define (preprocessing-<=? expression context pcontext preprocessing1 preprocessing2)

src/core/taylor.rkt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@
113113

114114
(define/reset log-cache (make-hash '((1 . ((1 -1 1))))))
115115

116-
(define/reset series-cache (make-hash))
117-
118116
(define (n-sum-to n k)
119117
(hash-ref! (n-sum-to-cache)
120118
(cons n k)

src/main.rkt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#lang racket
22

33
(require racket/lazy-require)
4-
(require "utils/common.rkt"
4+
(require "config.rkt"
55
"utils/multi-command-line.rkt"
66
"utils/errors.rkt"
77
"syntax/load-plugin.rkt"
8-
"syntax/platform.rkt"
9-
"api/sandbox.rkt")
8+
"syntax/platform.rkt")
109

1110
;; Load all the plugins
1211
(load-herbie-plugins)

0 commit comments

Comments
 (0)