Skip to content

Commit

Permalink
Revert "Revert "Preprocess Initial Simplifiy Attempt #2""
Browse files Browse the repository at this point in the history
  • Loading branch information
pavpanchekha authored Sep 20, 2023
1 parent ade4b4d commit b634bed
Show file tree
Hide file tree
Showing 61 changed files with 2,912 additions and 125 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/api-endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.5
version: 8.10
- name: Install Rust compiler
uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -51,4 +51,4 @@ jobs:
# run: node -e "fetch('https://google.com')"

- name: "Test the endpoint"
run: node infra/testApi.mjs
run: node infra/testApi.mjs
2 changes: 1 addition & 1 deletion .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.7
version: 8.10
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/egg-herbie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.7
version: 8.10
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand Down
32 changes: 1 addition & 31 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,6 @@ env:
RUST_BACKTRACE: full

jobs:
softposit:
name: "Plugin tests (Posits)"
runs-on: ubuntu-latest
steps:
- name: "Install Packages"
run: sudo apt-get install -y libmpfr6 libmpfr-dev
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.7
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
toolchain: stable
default: true
override: true
components: rustfmt, clippy
- uses: actions/checkout@master
- name: "Install dependencies"
run: make install
- name: "Check out softposit-herbie master"
uses: actions/checkout@master
with:
repository: herbie-fp/softposit-herbie
path: plugin
- name: "Install SoftPosit support"
run: raco pkg install --no-cache --auto --name softposit-herbie plugin/
- name: "Run posit benchmarks"
run: racket infra/travis.rkt --precision posit16 --seed 0 plugin/bench/posits.fpcore

softposit-pherbie:
name: "Plugin tests (Posits, Pherbie)"
runs-on: ubuntu-latest
Expand All @@ -45,7 +15,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.5
version: 8.10
- name: Install Rust compiler
uses: actions-rs/toolchain@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Install Racket
uses: Bogdanp/[email protected]
with:
version: 8.7
version: 8.10

- name: Install Rust compiler
uses: actions-rs/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
racket-version: [ '8.0', '8.7' ]
racket-version: [ '8.2', '8.10' ]
precision: [ 'binary32', 'binary64' ]
steps:
- name: "Install Packages"
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.7
version: 8.10
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.7
version: 8.10
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand All @@ -38,7 +38,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.7
version: 8.10
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand All @@ -61,7 +61,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.7
version: 8.10
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.7
version: 8.10
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand Down
2 changes: 2 additions & 0 deletions bench/hamming/rearrangement.fpcore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

(FPCore (x)
:name "2frac (problem 3.3.1)"

(- (/ 1 (+ x 1)) (/ 1 x)))

(FPCore (x eps)
Expand All @@ -51,6 +52,7 @@
:name "3frac (problem 3.3.3)"
:herbie-target
(/ 2 (* x (- (* x x) 1)))
:herbie-expected 2

(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))))

Expand Down
7 changes: 4 additions & 3 deletions bench/haskell.fpcore
Original file line number Diff line number Diff line change
Expand Up @@ -1403,9 +1403,10 @@
:name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, A"
(* x (- 1.0 (* x y))))

(FPCore (x)
:name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, B"
(* x (- 1.0 (* x 0.5))))
;; TODO: Trello Benchmark Sources - Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, B
;; (FPCore (x)
;; :name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, B"
;; (* x (- 1.0 (* x 0.5))))

(FPCore (x y z t a b)
:name "Numeric.SpecFunctions:logBeta from math-functions-0.1.5.2, A"
Expand Down
12 changes: 7 additions & 5 deletions src/core/localize.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
(if (null? exprs) empty (compute-local-errors exprs ctx)))
(for/list ([expr (in-list exprs)] [errs (in-list errss)])
(sort
(reap [sow]
(for ([(expr err) (in-hash errs)])
(unless (andmap (curry = 1) err)
(sow (cons err expr)))))
> #:key (compose errors-score car))))
(sort
(reap [sow]
(for ([(expr err) (in-hash errs)])
(unless (andmap (curry = 1) err)
(sow (cons err expr)))))
> #:key (compose errors-score car))
expr<? #:key cdr)))

; Compute local error or each sampled point at each node in `prog`.
(define (compute-local-errors exprs ctx)
Expand Down
12 changes: 8 additions & 4 deletions src/core/reduce.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@
(for ([term terms])
(let ([sum (hash-ref! h (cadr term) (λ () 0))])
(hash-set! h (cadr term) (+ (car term) sum))))
(reap [sow]
(hash-for-each h (λ (k v) (when (not (= v 0)) (sow (cons v k))))))))
(sort
(reap [sow]
(hash-for-each h (λ (k v) (when (not (= v 0)) (sow (cons v k))))))
expr<? #:key cdr)))

(define (combine-mterms terms)
(cons
Expand All @@ -196,8 +198,10 @@
(for ([term (cdr terms)])
(let ([sum (hash-ref! h (cdr term) (λ () 0))])
(hash-set! h (cdr term) (+ (car term) sum))))
(reap [sow]
(hash-for-each h (λ (k v) (when (not (= v 0)) (sow (cons v k)))))))))
(sort
(reap [sow]
(hash-for-each h (λ (k v) (when (not (= v 0)) (sow (cons v k))))))
expr<? #:key cdr))))

(define (aterm->expr term)
(match term
Expand Down
43 changes: 17 additions & 26 deletions src/mainloop.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
[(err expr) (in-dict loc-errs)]
[i (in-range (*localize-expressions-limit*))])
(timeline-push! 'locations (~a expr) (errors-score err)
(not (patch-table-has-expr? expr)) (format "~a" (representation-name repr)))
(not (patch-table-has-expr? expr)) (~a (representation-name repr)))
expr))

; low-error locations (Pherbie-only with multi-precision)
Expand Down Expand Up @@ -300,23 +300,13 @@
(list (*context*))))
(cons domain (apply mk-pcontext pts+exs)))

(define (initialize-alt-table! prog pcontext ctx)
(define alt (make-alt prog))
(*start-prog* prog)
(define table (make-alt-table (*pcontext*) alt ctx))

; Add starting alt in every precision
(^table^
(if (*pareto-mode*)
(let ([new-alts (starting-alts alt ctx)])
(define-values (errss costs) (atab-eval-altns table new-alts ctx))
(atab-add-altns table new-alts errss costs))
table))

(when (flag-set? 'setup 'simplify)
(reconstruct! (patch-table-run-simplify (atab-active-alts (^table^))))
(finalize-iter!)
(^next-alts^ #f)))
(define (initialize-alt-table! alternatives context pcontext)
(match-define (cons initial simplified) alternatives)
(*start-prog* (alt-expr initial))
(define table (make-alt-table pcontext initial context))
(define simplified* (append-map (curryr starting-alts context) simplified))
(define-values (errss costs) (atab-eval-altns table simplified* context))
(^table^ (atab-add-altns table simplified* errss costs)))

;; This is only here for interactive use; normal runs use run-improve!
(define (run-improve vars prog iters
Expand All @@ -330,22 +320,23 @@
(define original-points (setup-context! vars (or specification prog) precondition repr))
(run-improve! iters prog specification preprocess original-points repr))

(define (run-improve! expression context pcontext rules iterations #:specification [specification #f])
(define (run-improve! initial specification context pcontext)
(timeline-event! 'preprocess)
(define preprocessing (find-preprocessing (or specification expression) context rules))
(define-values (simplified preprocessing)
(find-preprocessing initial specification context))
(timeline-push! 'symmetry (map ~a preprocessing))
(define pcontext* (preprocess-pcontext context pcontext preprocessing))
(match-define (and alternatives (cons best _))
(mutate! expression iterations pcontext*))
(match-define (and alternatives (cons (alt best _ _) _))
(mutate! simplified context pcontext* (*num-iterations*)))
(timeline-event! 'preprocess)
(define preprocessing*
(remove-unnecessary-preprocessing (alt-expr best) context pcontext preprocessing))
(remove-unnecessary-preprocessing best context pcontext preprocessing))
(values alternatives preprocessing*))

(define (mutate! prog iters pcontext)
(define (mutate! simplified context pcontext iterations)
(*pcontext* pcontext)
(initialize-alt-table! prog (*pcontext*) (*context*))
(for ([iter (in-range iters)] #:break (atab-completed? (^table^)))
(initialize-alt-table! simplified context pcontext)
(for ([iteration (in-range iterations)] #:break (atab-completed? (^table^)))
(run-iter!))
(extract!))

Expand Down
8 changes: 0 additions & 8 deletions src/patch.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
(provide
(contract-out
[patch-table-has-expr? (-> expr? boolean?)]
[patch-table-run-simplify (-> (listof alt?) (listof alt?))]
[patch-table-run (-> (listof expr?) (listof expr?) (listof alt?))]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;; Patch table ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -288,10 +287,3 @@
(simplify!)
(begin0 (apply append (^final^) (map patch-table-get cached))
(patch-table-clear!))]))

(define (patch-table-run-simplify altns)
(^rewrites^ (append altns (if (^rewrites^) (^rewrites^) '())))
(simplify!)
(begin0 (^final^)
(patch-table-clear!)))

Loading

0 comments on commit b634bed

Please sign in to comment.