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

Revert "Preprocess Initial Simplifiy Attempt #2" #657

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.10
version: 8.5
- 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.10
version: 8.7
- 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.10
version: 8.7
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand Down
32 changes: 31 additions & 1 deletion .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ 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 @@ -15,7 +45,7 @@ jobs:
- name: "Install Racket"
uses: Bogdanp/[email protected]
with:
version: 8.10
version: 8.5
- 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.10
version: 8.7

- 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.2', '8.10' ]
racket-version: [ '8.0', '8.7' ]
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.10
version: 8.7
- 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.10
version: 8.7
- 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.10
version: 8.7
- 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.10
version: 8.7
- 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.10
version: 8.7
- name: Install Rust compiler
uses: actions-rs/[email protected]
with:
Expand Down
2 changes: 0 additions & 2 deletions bench/hamming/rearrangement.fpcore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

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

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

(FPCore (x eps)
Expand All @@ -52,7 +51,6 @@
: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: 3 additions & 4 deletions bench/haskell.fpcore
Original file line number Diff line number Diff line change
Expand Up @@ -1403,10 +1403,9 @@
:name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, A"
(* x (- 1.0 (* x y))))

;; 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)
: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: 5 additions & 7 deletions src/core/localize.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
(if (null? exprs) empty (compute-local-errors exprs ctx)))
(for/list ([expr (in-list exprs)] [errs (in-list errss)])
(sort
(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)))
(reap [sow]
(for ([(expr err) (in-hash errs)])
(unless (andmap (curry = 1) err)
(sow (cons err expr)))))
> #:key (compose errors-score car))))

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

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

(define (aterm->expr term)
(match term
Expand Down
43 changes: 26 additions & 17 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)) (~a (representation-name repr)))
(not (patch-table-has-expr? expr)) (format "~a" (representation-name repr)))
expr))

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

(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)))
(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)))

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

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

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

Expand Down
8 changes: 8 additions & 0 deletions src/patch.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(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 @@ -287,3 +288,10 @@
(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
Loading