Skip to main content

The automata library

Project description

Mata: The Automata Library

GitHub tag Quality Python-Binding (build-&-test) codecov

Mata is an open source automata library that offers interface for different kinds of automata, e.g. (non-)deterministic finite automata (NFAs), (non-)deterministic finite transducers, etc. Currently, Mata offers two interfaces:

  1. An efficient library implemented in C/C++
  2. A flexible wrapper implemented in Python that uses the efficient library

Requirements and dependencies

For a successful installation of Mata, cmake of version 3.15.0 (or higher) and a C++ compiler with a support of C++-20 standard is required. From optional requirements, doxygen is required for a generation of the documentation and catch2 is required for the unit testing (Mata can still be compiled without these optional dependencies).

The Mata library further depends on the following libraries, included in the 3rdparty directory:

  • cudd for BDD manipulation,
  • re2 for regular expression parsing and the corresponding automata construction, and
  • simlib for a simulation computation.

Building and installing from sources

To build the library, run the following:

git clone https://github.com/VeriFIT/mata
cd mata
make release

In order to install the library, you can run

sudo make install

In order to verify the functionality of the library, you can run the test suite:

make test

You might, need to install the dependencies to measure the coverage of the tests. Run the following to install the dependencies for MacOS:

brew install lcov gcovr

Run the following to install the dependencies for Ubuntu:

sudo apt-get install -y build-essential lcov gcovr xdg-utils

Python binding

Mata offers binding of its efficient library to Python. You can install the binding as an Python package on your system as follows.

Install from PyPI

To install a latest version from the PyPI repository, run

pip3 install libmata

Building from sources

To build from sources first, install the necessary requirements for Python and your system. We recommend using the virtual environemnt (venv) to install and use the library.

python -m pip install --upgrade pip
make -C bindings/python init

sudo apt-get -qq update 
sudo apt-get -qq install -y graphviz graphviz-dev

Now, you can install the library.

make -C bindings/python install

Finally, you can verify the binding woks as expected by running the test suite:

make -C bindings/python test

Getting started

To get started, we refer to the examples in our repository. This directory contains examples of various usage in form of:

  1. C/C++ example programs. By default, they are built with the library. To run for example the first example:
./build/examples/example01-simple
  1. Python example scripts. To run the scripts run the following.
python examples/example01-python-binding.py
  1. Python jupyter notebooks. To run the jupyter notebook, one needs to have jupyter installed as a prerequisite. The run the jupyter notebook, that creates an instance on your local server. Navigate to generated link to see the available jupyter notebooks:
pip3 install jupyter
jupyter notebook

Using the library

The library can be used directly in the C/C++ code. The result of compilation is a static or dynamic library, that can be linked to ones project. Note, that the library is dependent on several other 3rd party libraries (e.g., libre2 or libsimlib), which are included in the repository.

First import the library in your code. If the library is properly installed, you can use the standard include.

#include <mata/nfa/nfa.hh>

We recommend to use the mata::nfa namespace for easier usage:

using namespace mata::nfa;

Start by creating an automaton with fixed number of states.

int main() {
    Nfa aut(4);

You can set the initial and final states directly using the initializers.

    aut.initial = {0, 1};
    aut.final = {2, 3};

Further, you can add transitions in form of tripple (state_from, symbol, targets):

    aut.delta.add(0, 0, 2);
    aut.delta.add(1, 1, 3);

You can verify the state of your automaton by generating the automaton in .dot format.

    aut.print_to_dot(std::cout);

    return 0;
}

We recommend cmake for building projects using Mata. Provided the Mata is installed in the system directories, the CMakeLists.txt file for the example may look like:

cmake_minimum_required (VERSION 3.15.0)
project (mata-example)
set (CMAKE_CXX_STANDARD 20)

find_library(LIBMATA mata REQUIRED)

add_executable(mata-example
    mata-example.cc)
target_link_libraries(mata-example PUBLIC ${LIBMATA})

Using the Python binding

The python binding is installed (by default) to your local python package repository. You can either use the binding in your own scripts or in the python interpreter.

You can start using the binding by importing the libmata package.

import libmata.nfa.nfa as mata_nfa

In your own scripts, we recommend to use the standard guard for running the scripts, as follows.

if __name__ == "__main__":

The usage of the binding copies (to certain levels) the usage of the C++ library.

    aut = mata_nfa.Nfa(4)

    aut.initial_states = {0, 1}
    aut.final_states = {2, 3}
    aut.add_transition(0, 0, 2)
    aut.add_transition(1, 1, 3)

    print(aut.to_dot_str())

You can either run your scripts directly using python or compile it using the cython project.

Supported Automata Models

While we try to keep the provided libray interface stable, Mata is still a project in its infancy. Hence, the interface is subject to change. For further information, see section Versioning.

Mata currently supports (non-)deterministic finite automata (NFAs), defined in include/mata/nfa/.

[!WARNING] Mata provides an experimental (unstable) support for (non-)deterministic finite transducers (NFTs), defined in include/mata/nft/. The provided interface may change.

Versioning

Mata follows the versioning scheme GENERATION.MAJOR.MINOR, e.g. 1.2.3 where 1 is the generation number, and 2 the major version, and 3 the minor version. The MAJOR and MINOR versions follow loosely the Semantic Versioning scheme.

  • The GENERATION number represents our subjective generation of the Mata library. Typically, we increment the GENERATION number when a substantial change to the library is introduced, such as adding support for new automata models, extensive rewrite of (a part of) the Mata library, or to denote a new scientific paper documenting the latest developments in the Mata library is published, etc.
  • Generally, the changes in the MINOR version should not break the existing interface, but exceptions might occur.
  • The changes in the MAJOR version might introduce breaking changes that modify the existing interface and might require changing the code in your projects that use the Mata library.

Publications

Contributing

Please refer to our contributing guidelines.

Links

Also, check out our research group focusing on program analysis, static and dynamic analysis, formal methods, verification and many more: http://www.fit.vutbr.cz/research/groups/verifit/index.php.en.

Licensing

The code of Mata is licensed under MIT licence. See LICENSE.

The folder 3rdparty/ contains 3rd party applications licensed under their own licences, included with the code.

Contacts

See AUTHORS.md

Acknowledgements

We thank for the support received from the Brno University of Technology (BUT FIT).

Development of this tool has been supported by the following projects: ???.

This tool as well as the information provided on this web page reflects only the author's view and no organization is responsible for any use that may be made of the information it contains.

Project details


Release history Release notifications | RSS feed

This version

1.7.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libmata-1.7.0.tar.gz (1.6 MB view details)

Uploaded Source

File details

Details for the file libmata-1.7.0.tar.gz.

File metadata

  • Download URL: libmata-1.7.0.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.20

File hashes

Hashes for libmata-1.7.0.tar.gz
Algorithm Hash digest
SHA256 6a1dad14d777264ab9f7d72fea0e5cd74449da34e6c488303e1615e38bc2ca35
MD5 2a1c31f9a2c5f07b3f87456f13e6dd27
BLAKE2b-256 f3ab5917a440d0f0e230a173700ad4f188d04f15ccb92e72ba7e07b5e8ff03a9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page