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

Uploaded Python 3

File details

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

File metadata

  • Download URL: morphata-1.0.2.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2.tar.gz
Algorithm Hash digest
SHA256 c623094e3e43c59601b31bd938af33ef2362567e74b035f47f37c5d0f03c9a64
MD5 1fdf0927664b3711036ec65d224d8920
BLAKE2b-256 8eea76d9d3d76b6e45b882ca6fd20031c4b81fb520d8dc88a4f90d836611b20c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: morphata-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0d551b90acd211402282a25ff3e8189de9c3d8d2d43b0dcddf81bbc9328640bc
MD5 a083d2a6068a4bba0161883da1d45845
BLAKE2b-256 f25ddf5e05724fd946fd036980659fe631a4dea871ca61f9c349c4347ab8e06a

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