Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RipplB committed Dec 14, 2024
1 parent d381042 commit 02d08eb
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Overview

This package contains two new data structures, a Proof and a Cex.

### Abstract State Graph

`ASG` is a more simple state space representation than `ARG`. It works and is implemented in a very similar way,
except it does allow circles to appear in the graph.

### ASG trace

`ASGTrace` represents a lasso like trace, i.e. it is made with two parts: a tail and a loop. The loop is required
to start and end in the last state of the tail. This node in the graph is called honda.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## Overview

This package provides algorithms that allow to look for accepting lasso shaped traces in a state space.
A lasso is a special form of trace, consisting of two parts: a tail and a loop. Both are like classic traces, where the
tail has to start from an initial state, and the loop has to start and end in the last state of the tail.
Loopchecker has to be provided with a predicate that can mark either states or actions as accepting. The loop checking
algorithms look for lasso traces that have such acceptance in their loop.

## Data structures

The data structures in Theta had a limitation that made them not suitable for the initial implementation of loopchecker.
Both ARG and Trace do not allow circles to appear in the state space. For this reason, loopchecker uses the
`hu.bme.mit.theta.analysis.algorithm.asg` package.

## Algorithms
For abstraction and trace concretization there are 2-2 algorithms, completely interchangeable. This is implemented
using the strategy design pattern.

### Abstraction

During abstraction, the `ASG` is built and explored until a valid `ASGTrace` is found. There are currently two algorithms
implemented, both based on a dept first search.

#### Nested Depth-First Search

NDFS contains of two Depth-First searches right after eachother to find a lasso trace. The goal of the first DFS
is to find any acceptance, and than the second should find the very same acceptance from there.

![]()


#### Guided depth first search

The basis of the
algorithm is Depth-First Search (DFS), where we do only one search with a modified
condition instead of two nested ones compared to NDFS. Let us call encountering an accepting state/transition an acceptance. In the DFS, while keeping an acceptance counter,
look for a node that is already on the stack and has a smaller value on the counter
than the top of the stack.

![]()


### Concretization

Concretizing a lasso trace requires an extra step after simple concretization. First the lasso is straightened to a classic
trace, and a classic concretization is used to determine if it's even feasible. However, after that, one needs to make
sure that the loop of the lasso is also a possible loop in the concrete state space.

#### Milano

This is a more direct approach. It checks whether the honda can be in the same
state before and after the loop. This is done by adding the cycle validity constraint to the
loop. An expression is added to the solver that requires all variables to have the same value in the first and
last state of the loop.

![]()

#### Bounded unrolling

The idea of bounded unwinding comes from E. Clarke et al., who defined an algorithm
to detect and refine lasso-shaped traces in the abstract state-space. The idea was that
even though we do not know if an abstract loop directly corresponds to a concrete loop,
we can be sure that the abstract loop can be concretized at most m different ways, where
m is the size of the smallest abstract state in the loop (if we think about abstract states as
sets of concrete states). That is because, if the loop is run m times and is concretizable,
the state that had the smallest number of concrete states has to repeat itself at least once.
The only limitations of the original algorithm were that it was defined for deterministic
operations only.

To slightly mitigate this limitation and be able to use the algorithm, we need to eliminate as many nondeterministic operations as possible. To achieve this, nondeterministic
operations have to be unfolded: they are replaced with all their possible deterministic
counterparts. For the nondet operations of `xsts`, this can be seen in the `XstsNormalizerPass` pass object.

Another limitation of the original algorithm in our context is that Theta is working with
possibly infinite domains, for which m could also potentially evaluate to infinite. To have a
chance to avoid these infinite unwindings, it is worth noting that counting all the concrete
states allowed by the abstract states in the loop is an overapproximation of the number
of all possible different states the concrete loop can reach. If a variable is included in only
such assignments (or no assignments at all) where the expression contains only literals,
that variable has a fixed value throughout the loop. That means, for such variables, just
one unwinding is enough.

To find all the variables that contribute towards the needed number of unwindings, `VarCollectorStatementVisitor` is used.
![]()

Since infinite bounds can
still be encountered, there is a configurable maximum for the bound. If m would be greater
than that, the refiner falls back to the default concretizer algorithm, which is Milano in the current implementation.
4 changes: 4 additions & 0 deletions subprojects/common/ltl-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Overview
This package contains classes and objects related to CLIs that allow LTL model checking. For now it only contains a helper class
that is an implementation of the Clikt's package OptionGroup. This option group allows the user to select from the available
loopchecker and loop refinement strategies.
76 changes: 76 additions & 0 deletions subprojects/common/ltl/doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
## Overview
This project has two main purposes. The `hu.bme.mit.theta.common.cfa.buchi` package is used to convert properties specified
in the LTL language to Buchi automata as CFA. The `hu.bme.mit.theta.common.ltl` package contains a SafetyChecker that
is able to perform LTL based model checking on any formalism.

## Converting LTL to Buchi automaton

The main job is done by implementations of the `Ltl2BuchiTransformer` interface. This accepts an LTL formula and
produces a Buchi automaton in Theta representation. The current implementation `Ltl2BuchiThroughHoaf` does the following:

1. Preprocess the input LTL expression by substituting complex expressions with atomic propositions
2. Call a `Ltl2Hoaf` converter that produces the Buchi automaton in the [Hanoi Omega-Automata Format](https://adl.github.io/hoaf/)
3. Use the `BuchiBuilder` object to read the HOAF string and generate a CFA

![](ltl_conversion_pipeline.jpg)

### Preprocessing
Linear Temporal Logic works with atomic propositions, i.e. variables and expressions can only be of type boolean.
In align to this, most tools won't accept complex formulae, like `F(x == 9)`, i.e. _x is eventually going to become 9_.
To support such expressions, a preprocessing step is implemented. The entry point is in the `ToStringVisitor` class.
This class creates a new, now valid LTL expression with only atomic propositions, and provides a mapping from these
propositions to the original expressions. In our previoues example, the result could be `F p0`, and the mapping would contain
`p0 -> x == 9`.

### The purpose of [Hanoi Omega-Automata Format](https://adl.github.io/hoaf/) in the implementation
Since there were no tools or libraries that could have been linked due to licensing issues, it was required
to support calling external tools. HOAF is a standard that has many advantages for us:

* It's widely accepted and adopted by most of the tools related to LTL manipulation
* It's a rather stable but still maintained standard
* There is a library which is now included with theta that provides interfaces to work with HOAF

This allows the end-user to use any tool for the conversion they'd like. They only need to provided a command that runs on their system
and when the `ExternalLtl2Hoaf` runs it by appending the processed LTL formula after it, returns a Buchi automaton in the HOA format.

The recommended tools are [Spot](https://spot.lre.epita.fr/) and [Owl](https://owl.model.in.tum.de/).


### Why CFA?

Implementing Buchi automaton from scratch would have resulted in a lot of duplicate code with the already existing CFA class.
For this reason, CFA is now extended with optional accepting states or edges. Such CFA can perfectly model a Buchi automaton.

Of course, it would be more desirable, to have a common automaton superclass for CFA and a new Buchi automaton, but this was
not in scope for the project that developed these packages.

### Automated testing of LTL checking

Running external tools during automated testing such as in the CI/CD processes is not that feasible in the case of Theta.
For various reasons, our tests run on many different platforms. Running the above recommended programs during these tests
would result in a maintenance nightmare:

* The tools would need to be installed on all runner images
* Since most of them are only distributed for linux, calling them would require to be different on different operating systems
* For example, on windows you might use `WSL`, but the command `wsl` would of course fail on a linux system

For this reason, testing is done with another implementation of `Ltl2Hoaf`. `Ltl2HoafFromDir` is a class that expects
a directory as a parameter. Than when called with an LTL formula, encodes the formula to URL and looks up the resulting
filename.hoa in the directory.

### Architecture

The above interfaces and objects form the following architecture:

![](ltl2buchi.jpg)

## LTL checking

In the ltl package there is a single class the `LtlChecker`. This is a subclass of the safety checker, so it can fit
into most CLI algorithms easily. It uses the conversion mechanisms to create a Buchi automaton. Then uses the
`hu.bme.mit.theta.analysis.multi` package to create a product of this buchi automaton and the model that needs to
be checket. Finally it simply constructs a loopchecker abstractor and refiner, than builds
a `CegarChecker` with them.

For the details of the model checking algorithms, look at the `hu.bme.mit.theta.analysis.algorithm.loopchecker` package
in the common analysis subproject.
70 changes: 70 additions & 0 deletions subprojects/common/ltl/doc/ltl2buchi.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0" version="25.0.3">
<diagram name="Page-1" id="c4acf3e9-155e-7222-9cf6-157b1a14988f">
<mxGraphModel dx="2314" dy="1187" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" background="none" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="uSu6PvIy16e7wkabvxPg-1" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;i&gt;&amp;lt;&amp;lt;Interface&amp;gt;&amp;gt;&lt;/i&gt;&lt;br&gt;&lt;b&gt;Ltl2BuchiTransformer&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot; style=&quot;border-style:solid;&quot;&gt;&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ transform(String): CFA&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="840" y="330" width="170" height="70" as="geometry" />
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-6" value="Ltl2BuchiThroughHoaf" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=none;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="840" y="510" width="170" height="52" as="geometry" />
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-7" value="+ transform(String): CFA" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="uSu6PvIy16e7wkabvxPg-6" vertex="1">
<mxGeometry y="26" width="170" height="26" as="geometry" />
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-10" value="" style="endArrow=block;dashed=1;endFill=0;endSize=12;html=1;rounded=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="uSu6PvIy16e7wkabvxPg-6" target="uSu6PvIy16e7wkabvxPg-1" edge="1">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="860" y="400" as="sourcePoint" />
<mxPoint x="1020" y="400" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-11" value="BuchiBuilder" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="1150" y="510" width="110" height="50" as="geometry" />
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-12" value="«interface»&lt;br&gt;&lt;b&gt;HOAConsumer&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="1150" y="350" width="110" height="50" as="geometry" />
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-13" value="Use" style="endArrow=open;endSize=12;dashed=1;html=1;rounded=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="uSu6PvIy16e7wkabvxPg-6" target="uSu6PvIy16e7wkabvxPg-11" edge="1">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="860" y="400" as="sourcePoint" />
<mxPoint x="1020" y="400" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-14" value="" style="endArrow=block;dashed=1;endFill=0;endSize=12;html=1;rounded=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="uSu6PvIy16e7wkabvxPg-11" target="uSu6PvIy16e7wkabvxPg-12" edge="1">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="935" y="520" as="sourcePoint" />
<mxPoint x="935" y="410" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-15" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;i&gt;&amp;lt;&amp;lt;Interface&amp;gt;&amp;gt;&lt;/i&gt;&lt;br&gt;&lt;b&gt;Ltl2Hoaf&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot; style=&quot;border-style:solid;&quot;&gt;&lt;p style=&quot;margin:0px;margin-left:4px;&quot;&gt;+ transform(String): String&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="540" y="500" width="170" height="70" as="geometry" />
</mxCell>
<mxCell id="uSu6PvIy16e7wkabvxPg-16" value="Use" style="endArrow=open;endSize=12;dashed=1;html=1;rounded=0;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="uSu6PvIy16e7wkabvxPg-6" target="uSu6PvIy16e7wkabvxPg-15" edge="1">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="1020" y="546" as="sourcePoint" />
<mxPoint x="1160" y="545" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="cwrDArwZGd7g-K7oJVQ2-1" value="ExternalLtl2Hoaf" style="html=1;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="465" y="640" width="110" height="50" as="geometry" />
</mxCell>
<mxCell id="cwrDArwZGd7g-K7oJVQ2-2" value="Ltl2HoafFromDir" style="html=1;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="675" y="640" width="110" height="50" as="geometry" />
</mxCell>
<mxCell id="CDSpDMA8NM7_elaY5DCL-1" value="" style="endArrow=block;dashed=1;endFill=0;endSize=12;html=1;rounded=0;entryX=0.25;entryY=1;entryDx=0;entryDy=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" edge="1" parent="1" source="cwrDArwZGd7g-K7oJVQ2-1" target="uSu6PvIy16e7wkabvxPg-15">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="295" y="410" as="sourcePoint" />
<mxPoint x="363" y="350" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="CDSpDMA8NM7_elaY5DCL-2" value="" style="endArrow=block;dashed=1;endFill=0;endSize=12;html=1;rounded=0;entryX=0.75;entryY=1;entryDx=0;entryDy=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" edge="1" parent="1" source="cwrDArwZGd7g-K7oJVQ2-2" target="uSu6PvIy16e7wkabvxPg-15">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="530" y="650" as="sourcePoint" />
<mxPoint x="593" y="580" as="targetPoint" />
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Binary file added subprojects/common/ltl/doc/ltl2buchi.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions subprojects/common/ltl/doc/ltl_conversion_pipeline.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0" version="25.0.3">
<diagram name="Page-1" id="Jl_npFH5Yj2_PmD-pZwg">
<mxGraphModel dx="2314" dy="1187" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="BjMexAeEebLPS58inpm7-13" value="Preprocess" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="BjMexAeEebLPS58inpm7-11" target="BjMexAeEebLPS58inpm7-12">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="BjMexAeEebLPS58inpm7-11" value="F x == 9" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="40" y="110" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="BjMexAeEebLPS58inpm7-15" value="Convert" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="BjMexAeEebLPS58inpm7-12" target="BjMexAeEebLPS58inpm7-14">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="BjMexAeEebLPS58inpm7-12" value="F p0" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="240" y="110" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="BjMexAeEebLPS58inpm7-17" value="BuchiBuilder" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="BjMexAeEebLPS58inpm7-14" target="BjMexAeEebLPS58inpm7-16">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="BjMexAeEebLPS58inpm7-14" value="HOA v1..." style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="110" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="BjMexAeEebLPS58inpm7-16" value="CFA" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="640" y="110" width="120" height="60" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 02d08eb

Please sign in to comment.