Skip to content

Commit

Permalink
Revert "Formatting."
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneenders authored Oct 13, 2024
1 parent 3a13d68 commit 9c563e1
Show file tree
Hide file tree
Showing 43 changed files with 224 additions and 561 deletions.
17 changes: 4 additions & 13 deletions infra/ci.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@

(define (run-tests . bench-dirs)
(define default-precision
(if (*precision*)
(representation-name (*precision*))
(*default-precision*)))
(if (*precision*) (representation-name (*precision*)) (*default-precision*)))
(define tests
(parameterize ([*default-precision* default-precision])
(append-map load-tests bench-dirs)))
Expand All @@ -39,10 +37,7 @@
(for/and ([the-test tests]
[i (in-naturals)])
(printf "~a/~a\t" (~a (+ 1 i) #:width 3 #:align 'right) (length tests))
(define the-test*
(if (*precision*)
(override-test-precision the-test (*precision*))
the-test))
(define the-test* (if (*precision*) (override-test-precision the-test (*precision*)) the-test))
(define result (run-herbie 'improve the-test* #:seed seed))
(match-define (job-result _ test status time timeline warnings backend) result)
(match status
Expand All @@ -54,9 +49,7 @@
;; Pick lowest target from all target
(define target-error
; If the list is empty, return false
(if (empty? targets)
#f
(argmin errors-score (map alt-analysis-test-errors targets))))
(if (empty? targets) #f (argmin errors-score (map alt-analysis-test-errors targets))))

(printf "[ ~as] ~a→~a\t~a\n"
(~r (/ time 1000) #:min-width 7 #:precision '(= 3))
Expand All @@ -67,9 +60,7 @@
(define success?
(test-successful? test
(errors-score start-error)
(if target-error
(errors-score target-error)
#f)
(if target-error (errors-score target-error) #f)
(errors-score end-error)))

(when (not success?)
Expand Down
9 changes: 2 additions & 7 deletions infra/convert-demo.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
(match expr
[(? string?)
(let ([parsed (string->number expr)])
(if parsed
parsed
(raise (error "string that is not a num"))))]
(if parsed parsed (raise (error "string that is not a num"))))]
[(list op args ...) (format-op (cons op (map (curry format-expr is-version-10) args)))]
[(? symbol?)
(if is-version-10
(hash-ref version-10-constants expr expr)
expr)]
[(? symbol?) (if is-version-10 (hash-ref version-10-constants expr expr) expr)]
[else expr]))

(define (read-expr expr-string is-version-10)
Expand Down
21 changes: 7 additions & 14 deletions infra/convert-json.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,13 @@
(define vars (map string->symbol (hash-ref test 'vars (λ () (map ~a (free-variables expr))))))
(define spec (fix-expr (call-with-input-string (hash-ref test 'spec (~s expr)) read) pre-fpcore?))
(define pre (fix-expr (call-with-input-string (hash-ref test 'pre "TRUE") read) pre-fpcore?))
`(FPCore ,vars
,@(if (hash-has-key? test 'name)
(list ':name (hash-ref test 'name))
'())
,@(if (not (equal? pre "TRUE"))
(list ':pre pre)
'())
,@(if (not (equal? spec expr))
(list ':spec spec)
'())
,@(if (hash-has-key? test 'prec)
(list ':precision (string->symbol (hash-ref test 'prec)))
'())
,expr))
`(FPCore
,vars
,@(if (hash-has-key? test 'name) (list ':name (hash-ref test 'name)) '())
,@(if (not (equal? pre "TRUE")) (list ':pre pre) '())
,@(if (not (equal? spec expr)) (list ':spec spec) '())
,@(if (hash-has-key? test 'prec) (list ':precision (string->symbol (hash-ref test 'prec))) '())
,expr))

(define (convert-files json-files pre-fpcore?)
(define seen (mutable-set))
Expand Down
14 changes: 3 additions & 11 deletions infra/make-index.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
(for*/list ([(cat flags) (in-dict (or (report-info-flags ri) '()))]
[fl flags])
(string->symbol (format "~a:~a" cat fl))))
(if (equal? (report-info-iterations ri) 2)
(cons 'fuel:2 flags)
flags))
(if (equal? (report-info-iterations ri) 2) (cons 'fuel:2 flags) flags))

(define *cache* (make-parameter (make-hasheq)))

Expand Down Expand Up @@ -204,10 +202,7 @@
#:key (curryr dict-ref 'date-unix))))))))

(define crashes (filter (λ (x) (> (dict-ref x 'tests-crashed) 0)) (apply append mainline-infos)))
(define last-crash
(if (null? crashes)
#f
(argmax (curryr dict-ref 'date-unix) crashes)))
(define last-crash (if (null? crashes) #f (argmax (curryr dict-ref 'date-unix) crashes)))
(define since-last-crash
(and last-crash
(/ (- (date->seconds (current-date)) (dict-ref last-crash 'date-unix)) (* 60 60 24))))
Expand Down Expand Up @@ -253,10 +248,7 @@
[(directory-exists? file)
(for/list ([folder (in-list (directory-jsons file))])
(define relative-path (find-relative-path file folder #:more-than-same? false))
(define path*
(if base
(build-path base relative-path)
relative-path))
(define path* (if base (build-path base relative-path) relative-path))
(hash-set (compute-row folder) 'folder (path->string (simplify-path path* false))))]
[(file-exists? file)
(define cached-info (call-with-input-file file read-json))
Expand Down
4 changes: 1 addition & 3 deletions infra/merge.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
(for/list ([dir (in-list dirs)])
(with-handlers ([exn? (const #f)])
(let ([df (read-datafile (build-path outdir dir "results.json"))])
(if (eof-object? df)
eof
(cons df dir)))))))
(if (eof-object? df) eof (cons df dir)))))))
(define dfs (map car rss))
(define joint-rs (merge-datafiles dfs #:dirs dirs #:name name))
(write-datafile (build-path outdir "results.json") joint-rs)
Expand Down
4 changes: 1 addition & 3 deletions infra/sort-fpcore.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

(define (read-lines port)
(define line (read port))
(if (equal? line eof)
empty
(cons line (read-lines port))))
(if (equal? line eof) empty (cons line (read-lines port))))

(define (fpcore-less-than fpcore fpcore2)
(string>? (~a (rest (rest fpcore))) (~a (rest (rest fpcore2)))))
Expand Down
4 changes: 1 addition & 3 deletions infra/survey.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ section > div { width: 500; float: left; margin-right: 20px; }
'buckets
32.0
'max
(if (equal? name 'time)
(json-null)
64.0)))
(if (equal? name 'time) (json-null) 64.0)))
")")))))))
out))

Expand Down
117 changes: 54 additions & 63 deletions src/api/datafile.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@
(target . ,target-bits)
(start-est . ,start-est)
(end-est . ,end-est)
(vars . ,(if vars
(map symbol->string vars)
#f))
(vars . ,(if vars (map symbol->string vars) #f))
(warnings . ,(map ~s warnings))
(input . ,(~s input))
(output . ,(~s output))
Expand Down Expand Up @@ -196,63 +194,60 @@

(define (read-datafile file)
(define (parse-string s)
(if s
(call-with-input-string s read)
#f))
(if s (call-with-input-string s read) #f))

(let* ([json (call-with-input-file file read-json)]
[get (λ (field) (hash-ref json field))])
(report-info (seconds->date (get 'date))
(get 'commit)
(get 'branch)
(hash-ref json 'hostname "")
(parse-string (get 'seed))
(list->flags (get 'flags))
(get 'points)
(get 'iterations)
(hash-ref json 'note #f)
(for/list ([test (get 'tests)]
#:when (hash-has-key? test 'vars))
(let ([get (λ (field) (hash-ref test field))])
(define vars
(match (hash-ref test 'vars)
[(list names ...) (map string->symbol names)]
[string-lst (parse-string string-lst)]))
(define cost-accuracy
(match (hash-ref test 'cost-accuracy '())
[(list) (list)]
[(list start best others)
(list start
best
(for/list ([other (in-list others)])
(match-define (list cost err expr) other)
(list cost err (parse-string expr))))]
[(? string? s) (parse-string s)]))
(table-row (get 'name)
(parse-string (hash-ref test 'identifier "#f"))
(get 'status)
(parse-string (hash-ref test 'pre "TRUE"))
(parse-string (hash-ref test 'preprocess "()"))
(parse-string (hash-ref test 'prec "binary64"))
(let ([cs (hash-ref test 'conversions "()")])
(if (string? cs)
(parse-string cs)
(map (curry map parse-string) cs)))
vars
(map string->symbol (hash-ref test 'warnings '()))
(parse-string (get 'input))
(parse-string (get 'output))
(parse-string (hash-ref test 'spec "#f"))
(parse-string (hash-ref test 'target-prog "#f"))
(get 'start)
(get 'end)
(get 'target)
(hash-ref test 'start-est 0)
(hash-ref test 'end-est 0)
(get 'time)
(get 'link)
cost-accuracy)))
(hash-ref json 'merged-cost-accuracy null))))
(report-info
(seconds->date (get 'date))
(get 'commit)
(get 'branch)
(hash-ref json 'hostname "")
(parse-string (get 'seed))
(list->flags (get 'flags))
(get 'points)
(get 'iterations)
(hash-ref json 'note #f)
(for/list ([test (get 'tests)]
#:when (hash-has-key? test 'vars))
(let ([get (λ (field) (hash-ref test field))])
(define vars
(match (hash-ref test 'vars)
[(list names ...) (map string->symbol names)]
[string-lst (parse-string string-lst)]))
(define cost-accuracy
(match (hash-ref test 'cost-accuracy '())
[(list) (list)]
[(list start best others)
(list start
best
(for/list ([other (in-list others)])
(match-define (list cost err expr) other)
(list cost err (parse-string expr))))]
[(? string? s) (parse-string s)]))
(table-row (get 'name)
(parse-string (hash-ref test 'identifier "#f"))
(get 'status)
(parse-string (hash-ref test 'pre "TRUE"))
(parse-string (hash-ref test 'preprocess "()"))
(parse-string (hash-ref test 'prec "binary64"))
(let ([cs (hash-ref test 'conversions "()")])
(if (string? cs) (parse-string cs) (map (curry map parse-string) cs)))
vars
(map string->symbol (hash-ref test 'warnings '()))
(parse-string (get 'input))
(parse-string (get 'output))
(parse-string (hash-ref test 'spec "#f"))
(parse-string (hash-ref test 'target-prog "#f"))
(get 'start)
(get 'end)
(get 'target)
(hash-ref test 'start-est 0)
(hash-ref test 'end-est 0)
(get 'time)
(get 'link)
cost-accuracy)))
(hash-ref json 'merged-cost-accuracy null))))

(define (unique? a)
(or (null? a) (andmap (curry equal? (car a)) (cdr a))))
Expand All @@ -277,9 +272,7 @@
[test (in-list (report-info-tests df))])
(struct-copy table-row
test
(link (if dir
(format "~a/~a" dir (table-row-link test))
(table-row-link test))))))
(link (if dir (format "~a/~a" dir (table-row-link test)) (table-row-link test))))))

(report-info (last (sort (map report-info-date dfs) < #:key date->seconds))
(report-info-commit (first dfs))
Expand All @@ -289,9 +282,7 @@
(report-info-flags (first dfs))
(report-info-points (first dfs))
(report-info-iterations (first dfs))
(if name
(~a name)
(~a (cons 'merged (map report-info-note dfs))))
(if name (~a name) (~a (cons 'merged (map report-info-note dfs))))
tests
;; Easiest to just recompute everything based off the combined tests
(merged-cost-accuracy tests)))
Expand Down
10 changes: 2 additions & 8 deletions src/api/demo.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
(let ([m (regexp-match #rx"^([0-9a-f]+)\\.[0-9a-f.]+" x)])
(and m (server-check-on (second m))))))
(λ (x)
(let ([m (regexp-match #rx"^([0-9a-f]+)\\.[0-9a-f.]+" x)])
(server-check-on (if m
(second m)
x)))))
(let ([m (regexp-match #rx"^([0-9a-f]+)\\.[0-9a-f.]+" x)]) (server-check-on (if m (second m) x)))))

(define-bidi-match-expander hash-arg hash-arg/m hash-arg/m)

Expand Down Expand Up @@ -143,10 +140,7 @@
(link ([rel "stylesheet"] [type "text/css"] [href "main.css"]))
,@(for/list ([style styles])
`(link ([rel "stylesheet"] [type "text/css"] [href ,style]))))
(body (header (img ((class "logo") [src "/logo.png"]))
,@(if title?
`((h1 ,title))
'()))
(body (header (img ((class "logo") [src "/logo.png"])) ,@(if title? `((h1 ,title)) '()))
,@body)))

(define (main req)
Expand Down
29 changes: 7 additions & 22 deletions src/api/sandbox.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@

;; Branch on whether or not we should run inside an engine
(define eng (engine in-engine))
(if (engine-run (*timeout*) eng)
(engine-result eng)
(on-timeout)))
(if (engine-run (*timeout*) eng) (engine-result eng) (on-timeout)))

(define (dummy-table-row result status link)
(define test (job-result-test result))
Expand Down Expand Up @@ -398,9 +396,7 @@

; Important to calculate value of status
(define best-score
(if (null? target-cost-score)
target-cost-score
(apply min (map second target-cost-score))))
(if (null? target-cost-score) target-cost-score (apply min (map second target-cost-score))))

(define end-exprs (hash-ref end 'end-exprs))
(define end-train-scores (map errors-score (hash-ref end 'end-train-scores)))
Expand Down Expand Up @@ -473,9 +469,7 @@

; Important to calculate value of status
(define best-score
(if (null? target-cost-score)
target-cost-score
(apply min (map second target-cost-score))))
(if (null? target-cost-score) target-cost-score (apply min (map second target-cost-score))))

; analysis of output expressions
(define-values (end-exprs end-train-scores end-test-scores end-costs)
Expand Down Expand Up @@ -533,10 +527,7 @@
(define repr (get-representation (table-row-precision row)))
(define ctx (context vars repr (map (const repr) vars))) ; TODO: this seems wrong
(define expr* (or expr (table-row-output row) (table-row-input row)))
(define top
(if (table-row-identifier row)
(list (table-row-identifier row) vars)
(list vars)))
(define top (if (table-row-identifier row) (list (table-row-identifier row) vars) (list vars)))
`(FPCore ,@top
:herbie-status
,(string->symbol (table-row-status row))
Expand All @@ -549,19 +540,13 @@
,@(append (for/list ([rec (in-list (table-row-target row))])
(match-define (list cost score) rec)
`(:herbie-error-target ([,(*reeval-pts*) ,(table-row-target row)]))))
,@(if (empty? (table-row-warnings row))
'()
`(:herbie-warnings ,(table-row-warnings row)))
,@(if (empty? (table-row-warnings row)) '() `(:herbie-warnings ,(table-row-warnings row)))
:name
,(table-row-name row)
,@(if descr
`(:description ,(~a descr))
'())
,@(if descr `(:description ,(~a descr)) '())
:precision
,(table-row-precision row)
,@(if (eq? (table-row-pre row) 'TRUE)
'()
`(:pre ,(table-row-pre row)))
,@(if (eq? (table-row-pre row) 'TRUE) '() `(:pre ,(table-row-pre row)))
,@(if (equal? (table-row-preprocess row) empty)
'()
`(:herbie-preprocess ,(table-row-preprocess row)))
Expand Down
Loading

0 comments on commit 9c563e1

Please sign in to comment.