Skip to main content

Flexible automata representations for regular and ω-regular languages.

Project description

Morphata

Morphata is a Python library for constructing, manipulating, and translating automata over regular and omega-regular languages. It provides flexible graph-based representations for automata without committing to any specific model checking or monitoring algorithm.

Features

  • Graph-based automata implementations

    • Nondeterministic Finite Automata (NFA) for finite words
    • STREL automata for spatio-temporal specifications
  • HOA format parser

    • Extended HOA v1 format with finite-word acceptance support
    • Standard acceptance conditions: Buchi, co-Buchi, Rabin, Streett, Parity, Muller
    • Extension: Final(n) operator for finite-word automata (not in standard HOA v1)
    • Validation and error reporting
  • Acceptance conditions

    • Expression algebra for omega-regular conditions
    • Classical acceptance types (Buchi, generalized-Buchi, co-Buchi, Rabin, Streett, Muller, Parity)
    • Finite-word acceptance for regular languages
  • Pure structural interfaces

    • Base automaton interfaces without weighted semantics
    • NetworkX-based graph representations
    • Clean separation from quantitative monitoring (provided by automatix)

Architecture

Morphata serves as the foundation for the automatix library:

  • morphata: Graph-based automata, HOA parsing, acceptance conditions
  • automatix: Weighted automata over semirings (depends on morphata)
  • algebraic: Pure semiring algebra (independent)

This layered architecture allows morphata to be used independently for structural automata operations, or as a foundation for weighted semantics.

Installation

Morphata is part of the automatix workspace. Install using uv:

uv pip install -e packages/morphata

Quick Example

from morphata.automata import NFA
from logic_asts import base

# Create an NFA
nfa = NFA[str]()
nfa.add_location(0, initial=True)
nfa.add_location(1, final=True)

# Add transition with guard
guard_a = base.Variable("a")
nfa.add_transition(0, 1, guard_a)

# Use the automaton
accepting, next_state = nfa({"a"}, nfa.initial_state)
print(f"Accepting: {accepting}, Next state: {next_state}")

HOA Parser Example

Standard HOA Format (Omega-Automata)

from morphata.hoa.parser import parse

hoa_string = """
HOA: v1
States: 2
Start: 0
acc-name: Buchi
Acceptance: 1 Inf(0)
AP: 1 "a"
--BODY--
State: 0
  [0] 1
State: 1 {0}
  [t] 1
--END--
"""

automaton = parse(hoa_string)
print(f"Acceptance: {automaton.header.acc}")

Extended Format: Finite-Word Acceptance

Morphata extends the HOA v1 format with a Final(n) operator for finite-word automata. This is not part of the standard HOA specification but provides a natural way to express finite-word acceptance in the HOA syntax.

from morphata.hoa.parser import parse

finite_hoa = """
HOA: v1
States: 2
Start: 0
acc-name: Finite
Acceptance: 1 Final(0)
AP: 1 "a"
--BODY--
State: 0
  [0] 1 {0}
  [!0] 0
State: 1
  [t] 1
--END--
"""

automaton = parse(finite_hoa)
# Accepts finite words ending with 'a'

Note: The Final(n) operator semantics differ from Fin(n) and Inf(n):

  • Inf(n): Accept if acceptance set n is visited infinitely often (omega-regular)
  • Fin(n): Accept if acceptance set n is visited finitely often (omega-regular)
  • Final(n): Accept if the run ends in a state marked with acceptance set n (regular)

Development

Run tests:

python -m pytest packages/morphata/tests/ -v

Type checking:

python -m mypy packages/morphata/src/morphata/ --strict

License

Part of the automatix project.

Project details


Download files

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

Source Distribution

morphata-1.0.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

morphata-1.0.0-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file morphata-1.0.0.tar.gz.

File metadata

  • Download URL: morphata-1.0.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"42","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for morphata-1.0.0.tar.gz
Algorithm Hash digest
SHA256 420e678ba06d0ed6264501e86b752c129638983569a0c7d4ac17aac3d9021f24
MD5 6b2b2d6311ec9e8b09e856ee44431731
BLAKE2b-256 2985f4d26388e88247c6f5a705106787f1fbaf66a71c356782c1bc70b43ac63e

See more details on using hashes here.

File details

Details for the file morphata-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: morphata-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"42","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for morphata-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64578d75fb817078b7e369045771750b224e436e71a475982ad521e23e9e3e08
MD5 0e4cf14e7aa7e63bd223177d307a68e3
BLAKE2b-256 9107ff5d9b8b4b6229d5061e68cae50f78734382f995c54fa8bc17624979b5a6

See more details on using hashes here.

Supported by

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