Skip to content

Commit 9f744b3

Browse files
committed
intervals around points
1 parent 295a039 commit 9f744b3

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

src/egglog/egg-smol

src/egglog/run-egglog.rkt

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#lang racket
22

3-
(require racket/runtime-path)
3+
(require racket/runtime-path math/base)
44
(require "egraph-conversion.rkt" "../timeline.rkt"
55
"../syntax/types.rkt" "../points.rkt" "../common.rkt")
66
(require (for-syntax syntax/parse))
@@ -19,13 +19,15 @@
1919
(define egg-if-match-limit 10000)
2020
(define HIGH-COST 100000000)
2121
;; Number of egraphs to run (independent samples)
22-
(define egg-num-egraphs 3)
22+
(define egg-num-egraphs 1)
2323
;; local error threshold for search
2424
(define ERROR-THRESHOLD 0.0)
2525

2626

27+
;; var-intervals is a hash from variable names to
28+
;; an interval: (list start end)
2729
(struct econfig
28-
(ctx pctx exprs egg-data local-error? num-sample num-variants))
30+
(ctx pctx exprs egg-data local-error? num-sample num-variants var-intervals))
2931

3032
(define (add-to-ruleset ruleset commands)
3133
(for/list ([command commands])
@@ -1496,8 +1498,17 @@
14961498
))))
14971499

14981500

1501+
(define (in-interval? point config)
1502+
(for/and ([var (context-vars (econfig-ctx config))]
1503+
[num point])
1504+
(define interval (hash-ref (econfig-var-intervals config) var))
1505+
(and (<= (first interval) num)
1506+
(<= num (second interval)))))
1507+
14991508
(define (setup-ground-truth config)
1500-
(define points (for/list ([(point exact) (in-pcontext (econfig-pctx config))])
1509+
(define points
1510+
(for/list ([(point exact) (in-pcontext (econfig-pctx config))]
1511+
#:when (in-interval? point config))
15011512
point))
15021513
(define shuffled (shuffle points))
15031514
(append
@@ -1511,7 +1522,7 @@
15111522
[num point])
15121523
`(set (ival ,(expr->egglog (econfig-ctx config) var (econfig-egg-data config))
15131524
,i)
1514-
(interval ,num ,num)))))))
1525+
(interval ,(egglog-float num) ,(egglog-float num))))))))
15151526

15161527

15171528
(define run-ground-truth-compute
@@ -1526,7 +1537,11 @@
15261537
,(expr->egglog
15271538
(econfig-ctx config) var (econfig-egg-data config))
15281539
-1)
1529-
(ival-Empty)))))
1540+
(interval
1541+
,(egglog-float
1542+
(first (hash-ref (econfig-var-intervals config) var)))
1543+
,(egglog-float
1544+
(second (hash-ref (econfig-var-intervals config) var))))))))
15301545

15311546
(define (build-egglog config)
15321547
(append
@@ -1739,6 +1754,37 @@
17391754
[`(mostaccurate ,args ...) #f]
17401755
[else #t]))
17411756

1757+
(define (egglog-float num)
1758+
(define inexact (exact->inexact num))
1759+
(cond
1760+
[(equal? inexact +inf.0)
1761+
'inf]
1762+
[(equal? inexact -inf.0)
1763+
'-inf]
1764+
[else
1765+
inexact]))
1766+
1767+
1768+
(define (random-area ctx pctx)
1769+
(define points
1770+
(for/list ([(point exact) (in-pcontext pctx)])
1771+
point))
1772+
1773+
(cond
1774+
[(empty? points)
1775+
(make-hash
1776+
(for/list ([var (context-vars ctx)])
1777+
(cons var (list -inf.0 +inf.0))))]
1778+
[else
1779+
(define shuffled (shuffle points))
1780+
(define rand-point (first shuffled))
1781+
(define area-size 0.5)
1782+
(make-hash
1783+
(for/list ([var (context-vars ctx)]
1784+
[num rand-point])
1785+
(cons var (list (- num area-size) (+ num area-size)))))]))
1786+
1787+
17421788
(define (run-egglog ctx pctx exprs num-variants)
17431789
(define num-egraphs
17441790
(if (equal? num-variants 0)
@@ -1758,11 +1804,12 @@
17581804
(if (> i 0)
17591805
0
17601806
num-variants)
1807+
(random-area ctx pctx)
17611808
))))))
17621809

17631810
(define (run-egglog-random-point config)
17641811
(define-values (egglog-process egglog-output egglog-in err)
1765-
(subprocess #f #f (current-error-port) egglog-binary))
1812+
(subprocess #f #f #f egglog-binary))
17661813

17671814
(define egglog-program
17681815
(apply ~s #:separator "\n"
@@ -1774,7 +1821,7 @@
17741821

17751822
(displayln egglog-program egglog-in)
17761823
(close-output-port egglog-in)
1777-
1824+
17781825
(define all-variants
17791826
(for/list ([expr (econfig-exprs config)])
17801827
(read egglog-output)))
@@ -1792,11 +1839,17 @@
17921839

17931840
(close-input-port egglog-output)
17941841

1842+
;; todo how to read all the error with a timeout?
1843+
(define err-results (read-string 1000 err))
1844+
(close-input-port err)
1845+
(when (not (equal? err-results eof))
1846+
(error (format "Egglog error: ~a" err-results)))
1847+
17951848

17961849
(for ([result results])
17971850
(when (equal? result eof)
17981851
(displayln egglog-program)
1799-
(error "Egglog failed to produce a result")))
1852+
(error "Egglog failed to produce a result")))
18001853

18011854

18021855
(define converted

0 commit comments

Comments
 (0)