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.1.tar.gz (26.7 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.1-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: morphata-1.0.1.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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.1.tar.gz
Algorithm Hash digest
SHA256 876edafe80269b60265118c03d6760a50e21b625ee4f6ce0bc58f73d4c00efa7
MD5 0138deb69ba4d773b99058e2d436ac22
BLAKE2b-256 0b8735d4bee7f1bae992a5ec2109f35fa7f4712cf83bdbaadbd9bf60485996de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: morphata-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 902d27b732555e41fbafd7d7301abff09c6a1464cd1f1880d68e01d337fadcb5
MD5 ef955a386b17cf6141506db90b2492ec
BLAKE2b-256 ef6a1bd3201dd0440313c38a4b22809e1be88182381744972c8fa93a684097b4

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