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

Prototype SMT backend #273

Merged
merged 167 commits into from
Nov 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
f5958cf
add: working on contract for collector
tnelson Jun 18, 2024
88127d4
add: template w/ Karim
tnelson Jun 18, 2024
9d1fcc2
add: Easy way to find Java Temp folder
tnelson Jun 19, 2024
ec18c92
change: send-to-kodkod -> send-to-solver
tnelson Jun 20, 2024
1f8de89
change: factor out pardinus backend
tnelson Jun 20, 2024
e38ad72
Merge branch 'dev' into feat_smt
tnelson Jun 20, 2024
5e6ed36
remove: experiment skeleton
tnelson Jun 20, 2024
d2ecaa0
Converted to format strings
k-mouline Jun 20, 2024
7fe890e
fix: ->
tnelson Jun 20, 2024
b82a887
first changes to parsing
k-mouline Jun 21, 2024
19da701
add: join builder, no preservation of loc
tnelson Jun 21, 2024
dfc9dbc
preserve syntax loc
tnelson Jun 21, 2024
03569ec
updated interpret calls
k-mouline Jun 24, 2024
8ec583b
examples added
k-mouline Jun 24, 2024
55e3c5a
pair with Karim, demo of match
tnelson Jun 24, 2024
c3aed57
identity parsing
k-mouline Jun 24, 2024
47ae4cf
NNF parser
k-mouline Jun 24, 2024
87ea87f
Draft of testing; needs to be validated
bisheshank Jun 25, 2024
68e42ad
Substitutor push
k-mouline Jun 25, 2024
f61ba63
updated testing; needs review
bisheshank Jun 25, 2024
17dd94c
updating substitutor
k-mouline Jun 26, 2024
7d83d9c
add: programming together in NNF/NNF testing, macros
tnelson Jun 26, 2024
5062063
quantifiers and decls fixed
k-mouline Jun 26, 2024
bf430e4
nnf testing updated; need to fix sig-rel contract vio
bisheshank Jun 26, 2024
d4e8a69
small sub tests and nnf conversion modified
k-mouline Jun 26, 2024
2c9de2e
verbosity added and sub tests
k-mouline Jun 26, 2024
23f820e
nnf-testing suite rewritten
bisheshank Jun 26, 2024
8d69be9
nff-test updated with comparision tests
bisheshank Jun 26, 2024
44d0280
refactor: one-sided integration prototype for cvc5
tnelson Jun 27, 2024
f1e5100
skolemization first implementation
k-mouline Jun 27, 2024
ff7e392
bounds propagate up
k-mouline Jun 27, 2024
7162ae1
add: additional refactoring around SMTlib backend
tnelson Jun 28, 2024
01dd402
minor: print out raw cvc5 response in sat case
tnelson Jun 28, 2024
2c8f5c6
working: basic parsing of SMTlib SAT response
tnelson Jun 28, 2024
eb4c77f
add: own-grandpa, sterling proof of concept
tnelson Jun 28, 2024
33f32d1
integer reconciliation
k-mouline Jun 28, 2024
a912f9a
first attempt at converting to smtlib
k-mouline Jun 28, 2024
649d3d6
add: working on integration. NNF and int-conversion in pipeline
tnelson Jun 29, 2024
abfa8ed
partial conversion, need to stop soon
tnelson Jun 29, 2024
e85656b
more adjustments to skolem
tnelson Jun 29, 2024
0c30972
add: more fixes, see initialed comments in skolem
tnelson Jun 29, 2024
c4c8fd1
add: final pipeline step
tnelson Jun 29, 2024
658ce7a
working through skolem, starting SMT conversion add
tnelson Jun 29, 2024
45b3297
rough mapping into cvc5, not done yet'
tnelson Jun 29, 2024
e26fd69
working on SMT conversion
tnelson Jun 29, 2024
59ebf96
fix: skolemize _inner_ formula as well. also fix var call order
tnelson Jun 29, 2024
c709c44
fix: quantifier IDs, more robust cmd line args
tnelson Jun 29, 2024
7ff052a
fix: use XSort in quantifier domains
tnelson Jun 29, 2024
1805e3c
intermediate checkpoint: multi-run is combining results
tnelson Jun 29, 2024
a4c7d5e
fix: singleton tuple processing. note failing test, skolem issue
tnelson Jun 29, 2024
83697e4
fix: skolem depth 0 only; cleanup
tnelson Jun 30, 2024
33c32fa
misc fixes, 3-ary relations
tnelson Jun 30, 2024
171e249
add test
tnelson Jul 1, 2024
9a1d174
add: print stderr from cvc5 in another location
tnelson Jul 1, 2024
52514ab
add: basic collector draft, working on smoke tests
tnelson Jul 2, 2024
3464314
update: collector
tnelson Jul 2, 2024
810c352
fix: ordering in collector, add tesT
tnelson Jul 2, 2024
ef54bb2
Small edits to skolemization
k-mouline Jul 2, 2024
d412ba1
atom test added
k-mouline Jul 3, 2024
ea59bec
several changes, mostly multiplicity
k-mouline Jul 3, 2024
6218d18
saving intermediate work
tnelson Jul 3, 2024
504ea94
adding tests
tnelson Jul 3, 2024
c46abe5
paren fix and beginning some work on ints
k-mouline Jul 3, 2024
0396f60
disable int literal checking for smtlibtor
tnelson Jul 3, 2024
0ab2f30
decl domains are expressions
tnelson Jul 3, 2024
5b8a834
add: fix errors with skolem, contract
tnelson Jul 3, 2024
9a2c532
working; will convert join to application on merge
tnelson Jul 3, 2024
e8a7c9f
convert join to application
tnelson Jul 3, 2024
5ae8d8c
add: allow Unknown message to Sterling; blank right now
tnelson Jul 3, 2024
b973852
defensive check
tnelson Jul 3, 2024
0fb298a
more int work
k-mouline Jul 3, 2024
a8dec28
merge
tnelson Jul 3, 2024
ba285b2
add: handle unknown in tests, etc. (cannot test much yet)
tnelson Jul 4, 2024
69c7123
to-skolem func args fixed
k-mouline Jul 5, 2024
0cda303
fun spacer maintained in substitutor
k-mouline Jul 5, 2024
df80e05
fix: error message string
tnelson Jul 5, 2024
9358764
add: pair programming
tnelson Jul 5, 2024
a7534bb
add: comment only, thinking re: int
tnelson Jul 5, 2024
06d4100
add: Goldbach for unsat
tnelson Jul 5, 2024
b614800
Vars and decls sorted out
k-mouline Jul 5, 2024
64d1b15
resolve conflict
tnelson Jul 8, 2024
a6574ce
fix: missing annotation #f
tnelson Jul 8, 2024
972ba22
add: annotation to qvar for smtlib integer conversion'
tnelson Jul 8, 2024
ae0d390
add: draft annotation use
tnelson Jul 8, 2024
0fb841e
add: define sign SMT function, question re ints
tnelson Jul 8, 2024
4e114a8
add: comment, question about ints
tnelson Jul 8, 2024
26a74a2
add: untangle expr/const case
tnelson Jul 8, 2024
6ae6ae9
add: relational update unsupported
tnelson Jul 8, 2024
a4bfc03
add: draft for translating none
tnelson Jul 8, 2024
b874a48
add: notes on int
tnelson Jul 8, 2024
dfd6128
oops
tnelson Jul 8, 2024
7c48a42
add: proof of concept, pair programming with Karim
tnelson Jul 8, 2024
b54323c
add: stop policy to collector
tnelson Jul 8, 2024
87342b7
fix: hacky fix for substitutor fun-spacer; needs expanding
tnelson Jul 9, 2024
32a92e0
quantifier grounding added
k-mouline Jul 9, 2024
efc57cf
fake run added
k-mouline Jul 9, 2024
a07b349
fix: minor to collector, add grandpa
tnelson Jul 9, 2024
80a1c1e
Comparison pull request (#265)
k-mouline Aug 1, 2024
e0686e8
patch
tnelson Aug 1, 2024
37d99b6
manual merge from dev
tnelson Aug 1, 2024
cc08cd9
minor: comment change to avoid confusion
tnelson Aug 1, 2024
35e7e4b
minor: comment fix
tnelson Aug 1, 2024
0c3e9e5
fix: get-annotation for nodes
tnelson Aug 1, 2024
2e22980
Fixing issue with to-smt visitor; refactor lang-specific error code (…
tnelson Aug 5, 2024
4cfef1a
fix: quantifier case in tor conversion
tnelson Aug 5, 2024
7717a47
fix: blocking in error case from cvc5
tnelson Aug 5, 2024
d4509d5
Comprehension and integer handling improved
k-mouline Aug 5, 2024
f9e4855
fix: parsing smt response, allow 'some Node'
tnelson Aug 5, 2024
cbc2b61
rename univInt, no longer pass IntAtom-to-Int
tnelson Aug 5, 2024
9e669dc
Cardinality supported, a few fixes needed
k-mouline Aug 6, 2024
9d4ed97
match against nested ites
tnelson Aug 7, 2024
5a1adf3
fix: issue with chained ite
tnelson Aug 7, 2024
dfc5daa
fix: negative numbers in IntAtom-to-Int
tnelson Aug 7, 2024
ea152f2
fix more
tnelson Aug 7, 2024
83e7bbc
fix: update sterling for larger numbers
tnelson Aug 7, 2024
af90532
Added more comp/card tests, added to expression-type struct
k-mouline Aug 7, 2024
462edb1
fix: remove leftover prints
tnelson Aug 8, 2024
7923a0d
fix: arity of function call
tnelson Aug 8, 2024
b05b7d5
Tests for Tim
k-mouline Aug 8, 2024
4aae72f
fix to use of 'second' in last-checker, clarifying comments
tnelson Aug 8, 2024
f3c86d4
Multiplicities fixed and tests added
k-mouline Aug 8, 2024
fa5b2e3
More tests
k-mouline Aug 12, 2024
48769bc
Relational override, reflexive tc typing, lone sig, and tests
k-mouline Aug 14, 2024
212463a
add: don't pass translation-helpers to sterling
tnelson Aug 14, 2024
17cde9e
Fixed cardinality of size 0 set typing
k-mouline Aug 14, 2024
dce6b19
Cardinality error fixed
k-mouline Aug 14, 2024
24a8905
add: finite int set, commented test example
tnelson Aug 15, 2024
1a23e3e
add: additional comment
tnelson Aug 15, 2024
b11ffa8
Plenty more tests added
k-mouline Aug 16, 2024
e9cbfeb
Tests fixed
k-mouline Aug 19, 2024
3312ac6
update pardinus: return parse error text
tnelson Aug 20, 2024
2768b8b
fix for non-smt, which gives no Int sig in instances
tnelson Aug 20, 2024
d91d825
Feat smt s exp (#271)
tnelson Aug 20, 2024
4bcfe5b
Fix prime check (#272)
tnelson Aug 20, 2024
f167639
Extra files removed
k-mouline Aug 20, 2024
8b62e4a
fix: skolemization tests robust to suffix
tnelson Aug 20, 2024
ff2ca40
S-exp descent and substitution added
k-mouline Aug 21, 2024
876db0e
Small errors fixed
k-mouline Aug 21, 2024
13c725b
refactor: SMT ToR tests into CI folder
tnelson Aug 21, 2024
3d8df26
Two out of three tests fixed
k-mouline Aug 21, 2024
2fefb34
remove outdated test
tnelson Aug 21, 2024
cc34513
Temp file added for verbose SMT runs
k-mouline Aug 21, 2024
f29b42c
cleanup verbosity, test cvc5 in CI
tnelson Aug 22, 2024
8efdc1e
experiment: actions
tnelson Aug 22, 2024
c67df5e
refine CI, update racket version and print cvc5 version
tnelson Aug 22, 2024
6b961d2
Wrap negative numbers for earlier cvc5 versions
tnelson Aug 22, 2024
7b068ed
fix: wrap -1 in sign built-in
tnelson Aug 22, 2024
e101a6d
minor: cleanup
tnelson Aug 22, 2024
a9f2c6d
add: more comprehension tests
tnelson Aug 22, 2024
54fe251
fix: uniqueness of ints, regression tests
tnelson Aug 22, 2024
da9777c
add: understanding ic3 example
tnelson Aug 23, 2024
66f377d
fix: remainder lambda
tnelson Aug 23, 2024
d01c5a9
minor fixes, mod
tnelson Sep 2, 2024
fe8d3e0
add: avoid asserting true
tnelson Sep 29, 2024
0c23720
add: include options in SMT-lib, not command line, where applicable
tnelson Sep 29, 2024
60a292f
add: simplify 'one' constraint
tnelson Oct 1, 2024
61d7392
adjust CI
tnelson Oct 15, 2024
050b654
update: CI
tnelson Oct 15, 2024
740b65b
smt tests verbosity set to 0
k-mouline Oct 17, 2024
85ca793
add: improve debugging line in reader
tnelson Oct 23, 2024
8fd9b3d
add: exclude examples from domains from compile
tnelson Nov 12, 2024
9ef1c70
Docker container for CI (#280)
k-mouline Nov 19, 2024
ccc9da5
add: null for PR in CI script
tnelson Nov 19, 2024
d654466
Merge branch 'dev' into feat_smt
tnelson Nov 19, 2024
d1dbee2
update: continue reconciling dev with feature branch
tnelson Nov 19, 2024
6d650ef
fix: is_theorem_disabled test, ++ case in smtlibtor conversion
tnelson Nov 19, 2024
82ca78a
cleanup: SMT / solver specifics
tnelson Nov 20, 2024
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
Prev Previous commit
Next Next commit
working: basic parsing of SMTlib SAT response
  • Loading branch information
tnelson committed Jun 28, 2024
commit 2c8f5c6d3997fc1b663035dc95d3665c83f77d56
98 changes: 91 additions & 7 deletions forge/solver-specific/cvc5-tor.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
(require (prefix-in @ (only-in racket/base >= not - = and or max > < +))
(only-in racket match first rest empty empty? set->list list->set set-intersect set-union
curry range index-of pretty-print filter-map string-prefix? string-split thunk*
remove-duplicates subset? cartesian-product match-define cons? set-subtract)
remove-duplicates subset? cartesian-product match-define cons? set-subtract
string-replace)
racket/hash
racket/port)

Expand Down Expand Up @@ -72,28 +73,36 @@
;(define result (translate-from-cvc5 'run soln all-rels all-atoms))

; Mock an SMT-LIB input using theory of relations. Keep the port open!
(define mock-problem (port->string (open-input-file "cvc5.smt") #:close? #f))
(define mock-problem (port->string (open-input-file "own-grandpa.smt2" #;"cvc5.smt") #:close? #f))
(smtlib-display stdin mock-problem)
; ASSUME: reply format is a single line for the result type, then
; a paren-delimited s-expression with any output of that
(smtlib-display stdin "(check-sat)")
(define sat-answer (read stdout))

;; TODO: stderr handling
;; TODO: statistics: https://cvc5.github.io/docs/cvc5-1.0.2/statistics.html
;; TODO: extract instance
;; TODO: close-run not via pardinus!!
;; TODO: multiple runs? (start with just (clear)?)
;; TODO: extract core

;; Note: CVC5 interactive mode won't process newlines properly;
;; https://github.com/cvc5/cvc5/issues/10414
;; As of Jun 28 2024, need one command per line

(define result
(match sat-answer
['sat
; No statistics or metadata yet
; No statistics or metadata yet
(begin
(smtlib-display stdin "(get-model)")
(define model-s-expression (read stdout))
(for ([s-expr model-s-expression])
(printf "~a~n" s-expr))
(Sat '() #f #f))]
; Forge still uses the Alloy 6 modality overall: Sat structs contain a _list_ of instances,
; each corresponding to the state of the instance at a given time index. Here, just 1.
(define response (Sat (list (smtlib-tor-to-instance model-s-expression)) #f #f))
(printf "~nSAT: ~a~n" response)
response)]
['unsat
; No cores or statistics yet
(Unsat #f #f 'unsat)]
Expand All @@ -102,4 +111,79 @@
(Unknown #f #f)]
[else (raise-forge-error #:msg (format "Received unexpected response from CVC5: ~a" sat-answer)
#:context #f)]))
result)
result)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Converting SMT-LIB response expression into a Forge instance
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Building this up from running examples, so the cases may be a bit over-specific
(define (smtlib-tor-to-instance model-s-expression)
(for/fold ([inst (hash)])
([part model-s-expression])
(define-values (key value)
(match part

; Constant bindings to atoms: return unary relation of one tuple
[(list (quote define-fun) ID (list) TYPE (list (quote as) ATOMID ATOMTYPE))
(values ID (list (list (process-atom-id ATOMID))))]

; Uninterpreted function w/ constant value
[(list (quote define-fun) ID (list ARGS-WITH-TYPES) TYPE (list (quote as) ATOMID ATOMTYPE))
;; TODO: look at bounds given and assemble the domain of this function, cross-product with value
(values ID (list (list (process-atom-id ATOMID))))]

; Relational value: empty set
[(list (quote define-fun) ID (list) TYPE (list (quote as) (quote set.empty) ATOMTYPE))
(values ID '(()))]

; Relational value: union (may contain any number of singletons)
[(list (quote define-fun) ID (list) TYPE (list (quote set.union) ARGS ...))
; A union may contain an inductive list built from singletons and unions,
; or multiple singletons within a single list. So pre-process unions
; and flatten to get a list of singletons.
(define singletons (apply append (map process-union-arg ARGS)))
(values ID (process-singleton-list singletons))]

; Relational value: singleton (should contain a single tuple)
[(list (quote define-fun) ID (list) TYPE (list (quote set.singleton) ARG))
(values ID (process-tuple ARG))]

; Catch-all; unknown format
[else
(raise-forge-error #:msg (format "Unsupported response s-expression from SMT-LIB: ~a" part)
#:context #f)]))
(hash-set inst key value)))

; Return a list containing singletons
(define (process-union-arg arg)
(match arg
[(list (quote set.singleton) TUPLE)
(list arg)]
[(list (quote set.union) ARGS ...)
(apply append (map process-union-arg ARGS))]
[else
(raise-forge-error #:msg (format "Unsupported response s-expression from SMT-LIB (process-union-arg): ~a" arg)
#:context #f)]))
(define (process-singleton-list args)
(match args
; a list of singletons (unions should be removed prior)
[(list (list (quote set.singleton) TUPLES) ...)
(map process-tuple TUPLES)]
[else
(raise-forge-error #:msg (format "Unsupported response s-expression from SMT-LIB (process-singleton-list): ~a" args)
#:context #f)]))

(define (process-tuple tup)
(match tup
[(list (quote tuple) (list (quote as) ATOMIDS ATOMTYPES) ...)
(map process-atom-id ATOMIDS)]))

(define (process-atom-id atom-id)
(define string-atom-id (symbol->string atom-id))
(string->symbol
(string-replace (string-replace string-atom-id "@" "") "_" "$")))

;(smtlib-tor-to-instance
;'((define-fun spouse () (Set (Tuple Person Person)) (set.union (set.singleton (tuple (as @Person_0 Person) (as @Person_3 Person))) (set.union (set.singleton (tuple (as @Person_2 Person) (as @Person_1 Person))) (set.union (set.singleton (tuple (as @Person_3 Person) (as @Person_0 Person))) (set.singleton (tuple (as @Person_1 Person) (as @Person_2 Person)))))))
;))