Skip to content

Commit a4c756d

Browse files
committed
Merge branch 'main' into kalman-filter-benchmarks
2 parents bc0d923 + c7785e8 commit a4c756d

File tree

16 files changed

+450
-421
lines changed

16 files changed

+450
-421
lines changed

AGENT.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

AGENTS.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
# Testing
3+
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.
11+
12+
# Profiling
13+
14+
- Herbie generates a profile by default; run the `report` command
15+
above and look at `tmp/<benchmark>/profile.json`.
16+
- You can also run with `--enable dump:trace` to output
17+
`dump-trace.json` in chrome://tracing format
18+
- Additionally `--enable dump:rival` outputs all Rival commands it
19+
executes, which can be useful for debugging Rival &
20+
arbitrary-precision code.
21+
22+
# Timeline
23+
24+
- The timeline is Herbie's observability tooling. Timeline information
25+
goes into `timeline.json` and `timeline.html`.
26+
- A timeline is a list of phases, each of which is a hash table from
27+
key to "table", where a table is a list of rows each of which is a
28+
fixed-length array. Define new timeline types in
29+
`src/utils/timeline.rkt` and add/change HTML generation in
30+
`src/reports/timeline.rkt`.
31+
- Add to the timeline with `(timeline-push! 'type val1 val2 ...)`. The
32+
`val`s must be JSON-compatible; this mostly means you have to
33+
convert symbols to strings.
34+
35+
# Documentation
36+
37+
- Documentation lives in `www/doc/2.3/` and is HTML-formatted. Update
38+
it if you change any user-visible options.
39+
40+
# PRs
41+
42+
- PR descriptions should be 1-3 paragraphs in length. Describe the
43+
current behavior and why you changed it. Avoid bullet points.
44+
- Be explicit about the expected impact: "should be faster", "should
45+
be more accurate", "pure refactor, no changes", and so on.

src/api/server.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
job-id]
237237
[(list 'count) (hash-count queued-jobs)]
238238
[(list 'improve)
239-
(for/list ([(job-id result) (in-hash completed-jobs)]
239+
(for/list ([result (in-hash-values completed-jobs)]
240240
#:when (equal? (hash-ref result 'command) "improve"))
241241
result)]
242242
[(list 'forget job-id)
@@ -368,7 +368,7 @@
368368
; Retrieve the improve results for results.json
369369
[(list 'improve handler)
370370
(define improved-list
371-
(for/list ([(job-id result) (in-hash completed-jobs)]
371+
(for/list ([result (in-hash-values completed-jobs)]
372372
#:when (equal? (hash-ref result 'command) "improve"))
373373
result))
374374
(place-channel-put handler improved-list)]

src/core/batch.rkt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,10 @@
180180
(λ (brf recurse)
181181
(define node (deref brf))
182182
(define node* (f node))
183-
(define brf*
184-
(let loop ([node* node*])
185-
(match node*
186-
[(? batchref? brf) (recurse brf)]
187-
[_ (batch-push! out (expr-recurse node* (compose batchref-idx loop)))])))
188-
brf*)))
183+
(let loop ([node* node*])
184+
(match node*
185+
[(? batchref? brf) (recurse brf)]
186+
[_ (batch-push! out (expr-recurse node* (compose batchref-idx loop)))])))))
189187

190188
;; Allocates new batch
191189
(define (batch-apply b brfs f)

src/core/egg-herbie.rkt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,11 @@
666666
(vector-set! id->eclass id (cons enode* (vector-ref id->eclass id)))
667667
(match enode*
668668
[(list _ ids ...)
669-
(if (null? ids)
670-
(vector-set! id->leaf? id #t)
671-
(for ([child-id (in-list ids)])
672-
(vector-set! id->parents child-id (cons id (vector-ref id->parents child-id)))))]
669+
#:when (null? ids)
670+
(vector-set! id->leaf? id #t)]
671+
[(list _ ids ...)
672+
(for ([child-id (in-list ids)])
673+
(vector-set! id->parents child-id (cons id (vector-ref id->parents child-id))))]
673674
[(? symbol?) (vector-set! id->leaf? id #t)]
674675
[(? number?) (vector-set! id->leaf? id #t)]))))
675676

@@ -1108,7 +1109,11 @@
11081109

11091110
;; Is fractional with odd denominator.
11101111
(define (fraction-with-odd-denominator? frac)
1111-
(and (rational? frac) (let ([denom (denominator frac)]) (and (> denom 1) (odd? denom)))))
1112+
(cond
1113+
[(rational? frac)
1114+
(define denom (denominator frac))
1115+
(and (> denom 1) (odd? denom))]
1116+
[else #f]))
11121117

11131118
;; Decompose an e-node representing an impl of `(pow b e)`.
11141119
;; Returns either `#f` or the `(cons b e)`

src/core/rival.rkt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@
9494
machine
9595
dump-file))
9696

97+
(define (bigfloat->readable-string x)
98+
(define real (bigfloat->real x)) ; Exact rational unless inf/nan
99+
(define float (real->double-flonum real))
100+
(if (= real float)
101+
(format "#i~a" float) ; The #i explicitly means nearest float
102+
(number->string real))) ; Backup is print as rational
103+
97104
;; Runs a Rival machine on an input point.
98105
(define (real-apply compiler pt [hint #f])
99106
(match-define (real-compiler _ vars var-reprs _ _ machine dump-file) compiler)
@@ -104,9 +111,8 @@
104111
[repr (in-vector var-reprs)])
105112
((representation-repr->bf repr) val)))
106113
(when dump-file
107-
(define args (map bigfloat->rational (vector->list pt*)))
108-
;; convert to rational, because Rival reads as exact
109-
(pretty-print `(eval f ,@args) dump-file 1))
114+
(define args (map bigfloat->readable-string (vector->list pt*)))
115+
(fprintf dump-file "(eval f ~a)\n" (string-join args " ")))
110116
(define-values (status value)
111117
(with-handlers ([exn:rival:invalid? (lambda (e) (values 'invalid #f))]
112118
[exn:rival:unsamplable? (lambda (e) (values 'exit #f))])
@@ -128,11 +134,15 @@
128134
(define name (symbol->string (execution-name execution)))
129135
(define precision
130136
(- (execution-precision execution) (remainder (execution-precision execution) prec-threshold)))
131-
(timeline-push!/unsafe 'mixsample (execution-time execution) name precision))
137+
(timeline-push!/unsafe 'mixsample
138+
(execution-time execution)
139+
name
140+
precision
141+
(execution-memory execution)))
132142
(timeline-push!/unsafe 'outcomes
133143
(- (current-inexact-milliseconds) start)
134144
(rival-profile machine 'iterations)
135-
(~a status)
145+
(symbol->string status)
136146
1)
137147
(values status value))
138148

0 commit comments

Comments
 (0)