Skip to content

Commit 6e5d2fe

Browse files
Slim down README (#92)
1 parent c5e4386 commit 6e5d2fe

File tree

1 file changed

+5
-312
lines changed

1 file changed

+5
-312
lines changed

README.md

Lines changed: 5 additions & 312 deletions
Original file line numberDiff line numberDiff line change
@@ -14,318 +14,9 @@ Formulog sets out to fill this gap by augmenting Datalog with ways to construct
1414
3. Thanks to our [Formulog-to-Soufflé compiler](#compiling-formulog-programs), you can automatically generate a C++ version of the analysis that leverages highly optimized Datalog algorithms and data structures.
1515

1616
**Interested?**
17+
For more information, check out the [Formulog docs](https://harvardpl.github.io/formulog/) (also available in the [docs](./docs/) directory), including [tips on getting started](https://harvardpl.github.io/formulog/starting.html) and the [language reference](https://harvardpl.github.io/formulog/lang_ref/).
1718
To get a sense for what's involved in building a nontrivial SMT-based analysis in Formulog,
18-
check out our [tutorial](./docs/tutorial/tutorial.md) on implementing a refinement type checker in Formulog.
19-
For more tips on where to start, check out the section on [writing Formulog programs](#writing-formulog-programs) later in this document.
20-
21-
## Setup
22-
23-
### Prepackaged JAR
24-
25-
You can find a prepackaged JAR file in the Releases section of the GitHub
26-
repository.
27-
28-
Dependencies:
29-
30-
* JRE 11+
31-
* A supported SMT solver (see discussion below)
32-
33-
### Docker
34-
35-
Prebuilt images are available
36-
on [Docker Hub](https://hub.docker.com/r/aaronbembenek/formulog). If you have
37-
Docker installed, you can spin up an Ubuntu container with Formulog and some
38-
example programs by running this command:
39-
40-
```bash
41-
docker run -it aaronbembenek/formulog:0.7.0 # may require sudo
42-
```
43-
44-
This should place you in the directory `/root/formulog/`. From here, you should
45-
be able to run the following command and see some greetings:
46-
47-
```bash
48-
java -jar formulog.jar examples/greeting.flg --dump-idb
49-
```
50-
51-
### Building from source
52-
53-
Dependencies:
54-
55-
* JDK 11+
56-
* Maven
57-
* A supported SMT solver (see discussion below)
58-
59-
To build an executable JAR, run the command `mvn package` from the project
60-
directory. This will create an executable JAR with a name like
61-
`formulog-X.Y.Z-SNAPSHOT-jar-with-dependencies.jar` in the `target/`
62-
directory.
63-
64-
If `mvn package` fails during testing, it might mean that there is a problem
65-
connecting with your SMT solver. You can compile without testing by adding the
66-
`-DskipTests` flag.
67-
68-
### Supported SMT solvers
69-
70-
We have primarily used Formulog with Z3 as the backend solver. Z3's textual
71-
interface can change even between patch versions. Z3 4.12.2 is known to work
72-
with Formulog. To use Z3, the binary `z3` must be on your path.
73-
74-
We also have some experimental (not recently tested) support for other solvers;
75-
not all these solvers handle the full range of Formulog features. To use a
76-
solver besides Z3, you need to set the `smtSolver` system property (see below).
77-
For each solver, the relevant binary needs to be on your path: `z3` for
78-
Z3, `boolector` for Boolector, `cvc4` for CVC4, and `yices-smt2` for Yices.
79-
80-
### Zenodo artifact (OOPSLA'20 paper)
81-
82-
[![Zenodo DOI 10.5281/zenodo.4039085](https://zenodo.org/badge/DOI/10.5281/zenodo.4039085.svg)](https://doi.org/10.5281/zenodo.4039085)
83-
84-
You can replicate our evaluation from
85-
the [OOPSLA'20 paper](https://dl.acm.org/doi/10.1145/3428209) following
86-
the [instructions on Zenodo](https://zenodo.org/record/4039085). To start,
87-
[download the Docker image tarball](https://zenodo.org/record/4039085/files/formulog-artifact-image.tar.gz?download=1)
88-
for the artifact and load it using Docker:
89-
90-
```ShellSession
91-
$ curl "https://zenodo.org/record/4039085/files/formulog-artifact-image.tar.gz?download=1" -o formulog-artifact-image.tar.gz
92-
$ docker load < formulog-artifact-image.tar.gz # may require sudo
93-
$ docker run -it formulog-artifact # may require sudo
94-
```
95-
96-
## Running Formulog
97-
98-
The executable Formulog JAR that you have either downloaded or built expects a
99-
single Formulog file as an argument.
100-
101-
For example, if you save this Formulog program to `greeting.flg`
102-
103-
```
104-
@edb rel entity(string)
105-
entity("Alice").
106-
entity("Bob").
107-
entity("World").
108-
109-
rel greeting(string)
110-
greeting(Y) :-
111-
entity(X),
112-
some(M) = get_model([`#y[string] #= str_concat("Hello, ", X)`], none),
113-
some(Y) = query_model(#y[string], M).
114-
```
115-
116-
and run the command
117-
118-
```
119-
java -jar formulog.jar greeting.flg --dump-idb
120-
```
121-
122-
(assuming `formulog.jar` is the name of the Formulog executable JAR), you should see results like the following:
123-
124-
```
125-
Parsing...
126-
Finished parsing (0.202s)
127-
Type checking...
128-
Finished type checking (0.024s)
129-
Rewriting and validating...
130-
Finished rewriting and validating (0.253s)
131-
Evaluating...
132-
Finished evaluating (0.354s)
133-
134-
==================== SELECTED IDB RELATIONS ====================
135-
136-
---------- greeting (3) ----------
137-
greeting("Hello, Alice")
138-
greeting("Hello, Bob")
139-
greeting("Hello, World")
140-
```
141-
142-
### Options
143-
144-
The Formulog interpreter currently provides the following options:
145-
146-
```
147-
Usage: formulog [-chV] [--dump-all] [--dump-idb] [--dump-query] [--dump-sizes]
148-
[--eager-eval] [--smt-stats] [--codegen-dir=<codegenDir>]
149-
[-D=<outDir>] [-j=<parallelism>]
150-
[--smt-solver-mode=<smtStrategy>]
151-
[--dump=<relationsToPrint>]... [-F=<factDirs>]... <file>
152-
Runs Formulog.
153-
<file> Formulog program file.
154-
-c, --codegen Compile the Formulog program.
155-
--codegen-dir=<codegenDir>
156-
Directory for generated code (default: './codegen').
157-
-D, --output-dir=<outDir>
158-
Directory for .tsv output files (default: '.').
159-
--dump=<relationsToPrint>
160-
Print selected relations.
161-
--dump-all Print all relations.
162-
--dump-idb Print all IDB relations.
163-
--dump-query Print query result.
164-
--dump-sizes Print relation sizes.
165-
--eager-eval Use eager evaluation (instead of traditional semi-naive
166-
Datalog evaluation)
167-
-F, --fact-dir=<factDirs>
168-
Directory to look for fact .tsv files (default: '.').
169-
-h, --help Show this help message and exit.
170-
-j, --parallelism=<parallelism>
171-
Number of threads to use.
172-
--smt-solver-mode=<smtStrategy>
173-
Strategy to use when interacting with external SMT solvers
174-
('naive', 'push-pop', or 'check-sat-assuming').
175-
--smt-stats Report basic statistics related to SMT solver usage.
176-
-V, --version Print version information and exit.
177-
```
178-
179-
**Note:** The interpreter does not print any results by default; use one of the
180-
`--dump*` options to print results to the console, or annotate intensional
181-
database (IDB) relations with `@disk` to dump them to disk.
182-
183-
### System properties
184-
185-
In addition to options, there are many system properties that can be set using
186-
the `-D` flag (as in `-DdebugSmt` or `-DuseDemandTransformation=false`). Most of
187-
the properties are not yet documented; many are defined in the
188-
class `edu.harvard.seas.pl.formulog.Configuration`; some of the most useful ones
189-
are:
190-
191-
* `debugSmt` - log debugging information related to SMT calls to
192-
the `solver_logs/` directory (defaults to false)
193-
* `debugMst` - print debugging information related to the magic set
194-
transformation (defaults to false)
195-
* `debugRounds` - print statistics for each round of seminaive evaluation
196-
(defaults to false)
197-
* `useDemandTransformation` - apply the demand transformation as a
198-
post-processing step after the magic set transformation (defaults to true)
199-
* `softExceptions` - ignore exceptions during evaluation (i.e., treat them as
200-
unification failures, and not as something that should stop evaluation;
201-
defaults to false)
202-
* `sequential` - run interpreter without a thread pool (helpful for debugging
203-
runtime; defaults to false)
204-
* `printRelSizes` - print final relation sizes (defaults to false)
205-
* `printFinalRules` - print the final, transformed rules (defaults to false)
206-
* `trackedRelations=REL_1,...,REL_n` - print facts from listed relations as they
207-
are derived (defaults to the empty list)
208-
* `smtLogic=LOGIC` - set the logic used by the external SMT solver (defaults to
209-
`ALL`)
210-
* `smtSolver=SOLVER` - set the external SMT solver to use; current options are
211-
`z3` (default), `cvc4`, `yices`, and `boolector`
212-
* `smtDeclareAdts` - whether to declare Formulog algebraic data types to the SMT
213-
solver upon initialization; set this to false for logics that do not support
214-
ADTs (defaults to true)
215-
216-
For example, to run the test program above with SMT debug information and 3
217-
threads, use
218-
219-
```
220-
java -DdebugSmt -jar formulog.jar greeting.flg -j 3
221-
```
222-
223-
## Compiling Formulog programs
224-
225-
As an alternative to being directly interpreted, Formulog programs can be compiled into a mix of C++ and Souffle code, which can then in turn be compiled into an efficient executable.
226-
To enable compilation, set the `--codegen` (`-c`) flag; generated code will be placed in the directory `./codegen/` (you can change this using the `--codegen-dir` option).
227-
Within this directory you can use `cmake` to compile the generated code into a binary named `flg`.
228-
229-
For example, to compile and execute the `greeting.flg` program from above, you can use these steps:
230-
231-
```shellsession
232-
$ java -jar formulog.jar -c greeting.flg
233-
$ cd codegen
234-
$ cmake -B build -S .
235-
$ cmake --build build -j
236-
$ ./build/flg --dump-idb
237-
```
238-
239-
This should produce output like the following:
240-
241-
```
242-
Parsing...
243-
Finished parsing (0.000s)
244-
Evaluating...
245-
Finished evaluating (0.029s)
246-
247-
==================== SELECTED IDB RELATIONS ====================
248-
249-
---------- greeting (3) ----------
250-
greeting("Hello, Bob")
251-
greeting("Hello, World")
252-
greeting("Hello, Alice")
253-
```
254-
255-
Use the command `./build/flg -h` see options available when running the executable.
256-
257-
### Dependencies
258-
259-
To build the generated code, you must have:
260-
261-
- A C++ compiler that supports the C++17 standard (and OpenMP, if you want to produce a parallelized binary)
262-
- `cmake` (v3.21+)
263-
- [`boost`](https://www.boost.org/) (a version compatible with v1.81)
264-
- [`oneTBB`](https://oneapi-src.github.io/oneTBB/) (v2021.8.0 is known to work)
265-
- [`souffle`](https://souffle-lang.github.io/) (v2.3 is known to work)
266-
267-
The Formulog Docker image already has these dependencies installed.
268-
269-
## SMT solver modes and incremental SMT solving
270-
271-
The Formulog runtime associates one external SMT solver process per Formulog
272-
worker thread. Each SMT query is a list of conjuncts. If the SMT solver is
273-
invoked via the `is_sat_opt` or `get_model_opt` function, this list is
274-
explicitly given by the programmer; otherwise, if the solver is invoked via the
275-
`is_sat` or `is_valid` function, the Formulog runtime breaks the supplied
276-
proposition into conjuncts. Formulog supports three strategies for interacting
277-
with external SMT solvers; they can be set using the `--smt-solver-mode` option.
278-
Consider two SMT queries `x` and `y`, where `x` immediately precedes `y` and
279-
both are lists of conjuncts.
280-
281-
- `naive`: reset the solver between queries `x` and `y` (do not use incremental
282-
SMT solving).
283-
- `push-pop`: try to use incremental SMT solving via the `push` and `pop` SMT
284-
commands. This can work well when query `y` extends query `x`; e.g., `y = c ::
285-
x`, where `c` is an additional conjunct; this situation most commonly occurs
286-
when using [eager evaluation](#eager-evaluation).
287-
- `check-sat-assuming`: try to use incremental SMT solving via the
288-
`check-sat-assuming` SMT command. This caches conjuncts in the SMT solver in a
289-
way such that they can be enabled or disabled per SMT query, and works well if
290-
there are shared conjuncts between queries `x` and `y`, but query `x` is not
291-
simply an extension of query `y` (e.g., it omits a conjunct in query `y`).
292-
293-
For more information, see the ICLP'20 extended abstract [Datalog-Based Systems Can Use Incremental SMT Solving](https://aaronbembenek.github.io/papers/datalog-incr-smt-iclp2020.pdf)
294-
by Aaron Bembenek, Michael Ballantyne, Michael Greenberg, and Nada Amin.
295-
296-
## Eager evaluation
297-
298-
In addition to traditional semi-naive Datalog evaluation, Formulog supports _eager_ evaluation, a novel concurrent evaluation algorithm for Datalog that is faster than semi-naive evaluation on some Formulog workloads (often because it induces a more favorable distribution of the SMT workload across SMT solvers).
299-
Whereas semi-naive evaluation batches derived tuples to process them in explicit rounds, eager evaluation eagerly pursues the consequences of each tuple as it is derived.
300-
301-
Using eager evaluation with the Formulog interpreter is easy: just add the `--eager-eval` flag.
302-
Eager evaluation can also be used with the Formulog compiler, provided you install [our custom version of Souffle](https://github.com/aaronbembenek/souffle).
303-
When you configure `cmake` on the generated code, you need to add `-DFLG_EAGER_EVAL=On`.
304-
For example, to build a version of the greeting program that uses eager evaluation, use these commands:
305-
306-
```shellsession
307-
$ java -jar formulog.jar -c greeting.flg
308-
$ cd codegen
309-
$ cmake -B build -S . -DFLG_EAGER_EVAL=On
310-
$ cmake --build build -j
311-
$ ./build/flg --dump-idb
312-
```
313-
314-
## Writing Formulog programs
315-
316-
Check out our [tutorial](./docs/tutorial/tutorial.md) for a walk-through of how to encode a refinement type system in Formulog.
317-
Additional shortish example programs can be found in the [examples](./examples) directory.
318-
For examples of larger developments, see the case studies we have used in publications:
319-
320-
- [a refinement type checker](https://github.com/aaronbembenek/making-formulog-fast/blob/main/benchmarks/dminor/bench.flg)
321-
- [a bottom-up points-to analysis for Java](https://github.com/aaronbembenek/making-formulog-fast/blob/main/benchmarks/scuba/bench.flg)
322-
- [a symbolic executor an LLVM fragment](https://github.com/aaronbembenek/making-formulog-fast/blob/main/benchmarks/symex/bench.flg)
323-
324-
See the [language reference](./docs/00_language_ref.md) for details about Formulog constructs.
325-
326-
Syntax highlighting is available for Visual Studio Code (follow instructions [here](https://github.com/HarvardPL/formulog-syntax)) and Vim (install [misc/flg.vim](./misc/flg.vim)).
327-
328-
Finally, please raise a [GitHub issue](https://github.com/HarvardPL/formulog/issues/new) if you want to try out Formulog but need additional information/assistance---we're happy to help! :)
19+
check out our [tutorial](https://harvardpl.github.io/formulog/tutorial/) on implementing a refinement type checker in Formulog.
32920

33021
## Contributing
33122

@@ -334,7 +25,9 @@ Please open a [GitHub issue](https://github.com/HarvardPL/formulog/issues/new) a
33425
Pull requests must be in the [Google Java format](https://github.com/google/google-java-format) before being merged.
33526
To reformat your code, run `mvn spotless:apply`; you can also check if your code is conformant (without reformatting it) by running `mvn spotless:check`.
33627

337-
## Third-party libraries
28+
## Licensing and Third-Party Libraries
29+
30+
Formulog is released under an [Apache 2.0 license](./LICENSE.txt).
33831

33932
This project uses third-party libraries. You can generate a list of these
34033
libraries and download their associated licenses with this command:

0 commit comments

Comments
 (0)