morphata 2.0.7__tar.gz → 2.0.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. {morphata-2.0.7 → morphata-2.0.9}/CHANGELOG.md +61 -0
  2. {morphata-2.0.7 → morphata-2.0.9}/PKG-INFO +1 -1
  3. {morphata-2.0.7 → morphata-2.0.9}/bench/README.md +4 -0
  4. morphata-2.0.9/bench/test_equivalence_perf.py +57 -0
  5. morphata-2.0.9/bench/test_hoa_exporter_perf.py +124 -0
  6. morphata-2.0.9/bench/test_successors_for_alphabet_perf.py +124 -0
  7. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.symbolic.rst +7 -0
  8. {morphata-2.0.7 → morphata-2.0.9}/pyproject.toml +1 -1
  9. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/hoa/exporter.py +74 -20
  10. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/symbolic/__init__.py +2 -0
  11. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/symbolic/automaton.py +68 -12
  12. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/symbolic/compose.py +205 -106
  13. morphata-2.0.9/src/morphata/symbolic/equivalence.py +187 -0
  14. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/symbolic/persistence.py +38 -3
  15. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/symbolic/transforms.py +22 -2
  16. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_alphabet_aware_transitions.py +28 -0
  17. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_compose.py +20 -18
  18. morphata-2.0.9/tests/symbolic/test_composition_map.py +264 -0
  19. morphata-2.0.9/tests/symbolic/test_equivalence_naive_property.py +130 -0
  20. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_ltlf2dfa_equivalence.py +39 -0
  21. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_symbolic_automaton.py +21 -0
  22. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_transforms.py +38 -0
  23. {morphata-2.0.7 → morphata-2.0.9}/uv.lock +1 -1
  24. morphata-2.0.7/src/morphata/symbolic/equivalence.py +0 -114
  25. {morphata-2.0.7 → morphata-2.0.9}/.basedpyright/baseline.json +0 -0
  26. {morphata-2.0.7 → morphata-2.0.9}/.claude/settings.local.json +0 -0
  27. {morphata-2.0.7 → morphata-2.0.9}/.dockerignore +0 -0
  28. {morphata-2.0.7 → morphata-2.0.9}/.editorconfig +0 -0
  29. {morphata-2.0.7 → morphata-2.0.9}/.envrc +0 -0
  30. {morphata-2.0.7 → morphata-2.0.9}/.envrc.recommended +0 -0
  31. {morphata-2.0.7 → morphata-2.0.9}/.fdignore +0 -0
  32. {morphata-2.0.7 → morphata-2.0.9}/.gitattributes +0 -0
  33. {morphata-2.0.7 → morphata-2.0.9}/.gitignore +0 -0
  34. {morphata-2.0.7 → morphata-2.0.9}/.mailmap +0 -0
  35. {morphata-2.0.7 → morphata-2.0.9}/.python-version +0 -0
  36. {morphata-2.0.7 → morphata-2.0.9}/.rstcheck.cfg +0 -0
  37. {morphata-2.0.7 → morphata-2.0.9}/AGENTS.md +0 -0
  38. {morphata-2.0.7 → morphata-2.0.9}/CLAUDE.md +0 -0
  39. {morphata-2.0.7 → morphata-2.0.9}/CONTRIBUTING.md +0 -0
  40. {morphata-2.0.7 → morphata-2.0.9}/LICENSE +0 -0
  41. {morphata-2.0.7 → morphata-2.0.9}/README.md +0 -0
  42. {morphata-2.0.7 → morphata-2.0.9}/bench/__init__.py +0 -0
  43. {morphata-2.0.7 → morphata-2.0.9}/bench/conftest.py +0 -0
  44. {morphata-2.0.7 → morphata-2.0.9}/bench/test_sere_nlm_perf.py +0 -0
  45. {morphata-2.0.7 → morphata-2.0.9}/ci/make-release +0 -0
  46. {morphata-2.0.7 → morphata-2.0.9}/cliff.toml +0 -0
  47. {morphata-2.0.7 → morphata-2.0.9}/docs/_static/navigation.html +0 -0
  48. {morphata-2.0.7 → morphata-2.0.9}/docs/api/modules.rst +0 -0
  49. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.acceptance.rst +0 -0
  50. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.alphabet.rst +0 -0
  51. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.automaton.rst +0 -0
  52. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.builder.rst +0 -0
  53. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.hoa.rst +0 -0
  54. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.logic.ltl.rst +0 -0
  55. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.logic.psl.rst +0 -0
  56. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.logic.sere.rst +0 -0
  57. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.logic.strel.rst +0 -0
  58. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.operators.matrix.rst +0 -0
  59. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.operators.polynomial.rst +0 -0
  60. {morphata-2.0.7 → morphata-2.0.9}/docs/api/morphata.operators.rst +0 -0
  61. {morphata-2.0.7 → morphata-2.0.9}/docs/concepts/acceptance.rst +0 -0
  62. {morphata-2.0.7 → morphata-2.0.9}/docs/concepts/hoa.rst +0 -0
  63. {morphata-2.0.7 → morphata-2.0.9}/docs/concepts/index.rst +0 -0
  64. {morphata-2.0.7 → morphata-2.0.9}/docs/concepts/operators.rst +0 -0
  65. {morphata-2.0.7 → morphata-2.0.9}/docs/concepts/spec.rst +0 -0
  66. {morphata-2.0.7 → morphata-2.0.9}/docs/concepts/weights.rst +0 -0
  67. {morphata-2.0.7 → morphata-2.0.9}/docs/conf.py +0 -0
  68. {morphata-2.0.7 → morphata-2.0.9}/docs/index.rst +0 -0
  69. {morphata-2.0.7 → morphata-2.0.9}/docs/quick-start.rst +0 -0
  70. {morphata-2.0.7 → morphata-2.0.9}/docs/symbolic-transforms.rst +0 -0
  71. {morphata-2.0.7 → morphata-2.0.9}/justfile +0 -0
  72. {morphata-2.0.7 → morphata-2.0.9}/mypy.ini +0 -0
  73. {morphata-2.0.7 → morphata-2.0.9}/pixi.lock +0 -0
  74. {morphata-2.0.7 → morphata-2.0.9}/pixi.toml +0 -0
  75. {morphata-2.0.7 → morphata-2.0.9}/project.utf-8.add +0 -0
  76. {morphata-2.0.7 → morphata-2.0.9}/project.utf-8.add.spl +0 -0
  77. {morphata-2.0.7 → morphata-2.0.9}/pyrefly.toml +0 -0
  78. {morphata-2.0.7 → morphata-2.0.9}/pyrightconfig.json +0 -0
  79. {morphata-2.0.7 → morphata-2.0.9}/pytest.toml +0 -0
  80. {morphata-2.0.7 → morphata-2.0.9}/ruff.toml +0 -0
  81. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/__init__.py +0 -0
  82. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/acceptance.py +0 -0
  83. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/alphabet.py +0 -0
  84. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/automaton.py +0 -0
  85. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/builder.py +0 -0
  86. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/hoa/__init__.py +0 -0
  87. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/hoa/__main__.py +0 -0
  88. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/hoa/acc_expr.py +0 -0
  89. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/hoa/hoa.lark +0 -0
  90. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/hoa/parser.py +0 -0
  91. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/logic/__init__.py +0 -0
  92. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/logic/_common.py +0 -0
  93. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/logic/ltl.py +0 -0
  94. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/logic/psl.py +0 -0
  95. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/logic/sere.py +0 -0
  96. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/logic/strel.py +0 -0
  97. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/operators/__init__.py +0 -0
  98. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/operators/_backend.py +0 -0
  99. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/operators/matrix.py +0 -0
  100. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/operators/polynomial.py +0 -0
  101. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/py.typed +0 -0
  102. {morphata-2.0.7 → morphata-2.0.9}/src/morphata/symbolic/bdd.py +0 -0
  103. {morphata-2.0.7 → morphata-2.0.9}/tests/conftest.py +0 -0
  104. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut1.hoa +0 -0
  105. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut11.hoa +0 -0
  106. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut2.hoa +0 -0
  107. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut3.2.hoa +0 -0
  108. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut3.hoa +0 -0
  109. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut4.hoa +0 -0
  110. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut5.hoa +0 -0
  111. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut6.hoa +0 -0
  112. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut7.hoa +0 -0
  113. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/aut8.hoa +0 -0
  114. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/finite_aut.hoa +0 -0
  115. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/gen_buchi_3.hoa +0 -0
  116. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/gen_cobuchi_2.hoa +0 -0
  117. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/rabin_2pair.hoa +0 -0
  118. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/streett_2pair.hoa +0 -0
  119. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/test_exporter_basic.py +0 -0
  120. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/test_exporter_roundtrip.py +0 -0
  121. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/test_exporter_streaming.py +0 -0
  122. {morphata-2.0.7 → morphata-2.0.9}/tests/hoa/test_parser.py +0 -0
  123. {morphata-2.0.7 → morphata-2.0.9}/tests/logic/__init__.py +0 -0
  124. {morphata-2.0.7 → morphata-2.0.9}/tests/logic/test_ltl.py +0 -0
  125. {morphata-2.0.7 → morphata-2.0.9}/tests/logic/test_psl.py +0 -0
  126. {morphata-2.0.7 → morphata-2.0.9}/tests/logic/test_sere.py +0 -0
  127. {morphata-2.0.7 → morphata-2.0.9}/tests/logic/test_sere_properties.py +0 -0
  128. {morphata-2.0.7 → morphata-2.0.9}/tests/logic/test_strel.py +0 -0
  129. {morphata-2.0.7 → morphata-2.0.9}/tests/operators/test_matrix_from_ir.py +0 -0
  130. {morphata-2.0.7 → morphata-2.0.9}/tests/operators/test_matrix_from_ltl.py +0 -0
  131. {morphata-2.0.7 → morphata-2.0.9}/tests/operators/test_polynomial_from_ir.py +0 -0
  132. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_bdd_helpers.py +0 -0
  133. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_from_hoaf.py +0 -0
  134. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_persistence.py +0 -0
  135. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_step.py +0 -0
  136. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_symbolic_from_ir.py +0 -0
  137. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_to_hoa.py +0 -0
  138. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_transforms_ir.py +0 -0
  139. {morphata-2.0.7 → morphata-2.0.9}/tests/symbolic/test_transforms_properties.py +0 -0
  140. {morphata-2.0.7 → morphata-2.0.9}/tests/test_alphabet.py +0 -0
  141. {morphata-2.0.7 → morphata-2.0.9}/tests/test_automaton.py +0 -0
  142. {morphata-2.0.7 → morphata-2.0.9}/tests/test_builder.py +0 -0
  143. {morphata-2.0.7 → morphata-2.0.9}/tests/test_from_parsed.py +0 -0
  144. {morphata-2.0.7 → morphata-2.0.9}/ty.toml +0 -0
@@ -1,5 +1,66 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.9 — 2026-06-04
4
+
5
+ ### Fixed
6
+
7
+ - `dd._copy` was using `shelve` to create a hard-coded `__shelve__` directory in the
8
+ current working directory.
9
+ This caused a clash whenever we ran multiple data generation processes
10
+ (either different runs or multiprocessing), and a fatal error.
11
+ This release fixes that by, unfortunately,
12
+ duplicating the code that is used to serialize/deserialize BDDs in `dd`,
13
+ but using a `tempfile.mkdtemp` block to ensure the `shelve` is in a namespaced
14
+ directory.
15
+
16
+ ### Performance
17
+
18
+ - This is a major performance thing.
19
+ In addition to all the previous things we have done,
20
+ we now ensure that `symbolic_automaton_to_hoa`
21
+ (and in-effect, `SymbolicAutomaton.to_hoa`) **does not materialize any `BoolExpr`**.
22
+ Instead, we opt to use a (locally cached) BDD to label/guard expression function,
23
+ which increases throughput like CRAZY!!!
24
+
25
+ ## 2.0.8 — 2026-06-03
26
+
27
+ ### Added
28
+
29
+ - `compose_min_dfa` and `min_dfa_of_conjunction` are variadic now
30
+ and always return a `CompositionMap`: the per-factor automata,
31
+ the representative-to-tuple map,
32
+ and the full surjection from reachable per-factor tuples to composed states.
33
+ I initially wanted the section-only view,
34
+ but minimization can merge classes such
35
+ that a representative's per-factor successor lands on a non-representative tuple,
36
+ so the full surjection has to be there.
37
+ - `iter_composed_transitions` enumerates `(state, symbol, successor)`
38
+ of a composed DFA without building the product BDD, walking factor
39
+ deltas directly and hitting `tuple_to_class` once per
40
+ `(state, symbol)`.
41
+
42
+ ### Performance
43
+
44
+ - `successors_for_alphabet` drops the `|Sigma| * |rows|` cofactor sweep
45
+ for a per-row support-projected symbol partition with a constant-guard fast path.
46
+ Fixes the small-row regression from 2.0.6 while keeping the wide-state win.
47
+ Same treatment for `language_equivalent` and `canonical_form`,
48
+ so sparse guards over a big AP universe stop iterating the full powerset.
49
+ - Bucketing rows by guard support amortizes the partition
50
+ and per-class point dicts across same-support rows.
51
+ Conjunction-fold DFAs get 1.3-1.6x; `F a & F b & F c & F d` q1 went ~343us -> ~175us.
52
+ - `isomorphic` routes through a compact support-reduced fingerprint
53
+ and skips the broadcast expansion. `|AP|=19` sparse case:
54
+ ~333ms -> ~83ms.
55
+
56
+ ### Changed
57
+
58
+ - `SymbolicAutomaton` carries a derived `ap_inverse: Mapping[str, AP]`
59
+ populated in `__post_init__`; `to_automaton` and
60
+ `compose._merge_managers` route through it.
61
+ - New symbolic benches are pytest-benchmark cases, so timings get
62
+ recorded rather than gated on a hard-coded threshold.
63
+
3
64
  ## 2.0.7 — 2026-06-02
4
65
 
5
66
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: morphata
3
- Version: 2.0.7
3
+ Version: 2.0.9
4
4
  Summary: Representation theory for automata, made practical.
5
5
  Project-URL: Documentation, https://docs.anandb.dev/morphata
6
6
  Project-URL: Repository, https://git.anandb.dev/morphata.git
@@ -16,6 +16,10 @@ To get pytest-benchmark's tabular wall-time output:
16
16
  - `test_sere_nlm_perf.py` -- NLM-intersection state-space blowup.
17
17
  Cases: `NLMInter(a0..a_{n-1})` for n in 2..6, `NLMInter(a_i;b_i)`
18
18
  for n in 2..4, plus length-matching `Inter` baselines.
19
+ - `test_hoa_exporter_perf.py` -- ``symbolic_automaton_to_hoa`` end-to-end
20
+ wall time across regimes that stress the per-row guard/successor
21
+ caching (small DFA, sparse-big-alphabet DFA, conjunction min-DFA, raw
22
+ AFA without minimization).
19
23
 
20
24
  ## Recording results
21
25
 
@@ -0,0 +1,57 @@
1
+ """Micro-benchmarks for the rewritten equivalence functions.
2
+
3
+ The case: an LTLf min-DFA whose AP universe is large (|aps| ~ 19) but
4
+ whose guards mention only 4 APs. Pre-rewrite this regime explodes;
5
+ post-rewrite the per-pair (language_equivalent) and per-automaton
6
+ (isomorphic) support reductions keep work bounded.
7
+
8
+ pytest-benchmark records the timing distribution; no hard-coded
9
+ thresholds, the dataset is the regression signal.
10
+
11
+ Run with: ``pytest bench/test_equivalence_perf.py -v``
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import logic_asts.ltl as ltl
17
+ from pytest_benchmark.fixture import BenchmarkFixture as Benchmark
18
+
19
+ from morphata.alphabet import powerset_alphabet
20
+ from morphata.automaton import Automaton
21
+ from morphata.logic.ltl import Input, ltl_to_automaton
22
+ from morphata.symbolic import isomorphic
23
+ from morphata.symbolic.automaton import SymbolicAutomaton
24
+ from morphata.symbolic.equivalence import language_equivalent
25
+
26
+
27
+ def _sparse_big_alphabet_dfa() -> SymbolicAutomaton[str]:
28
+ aps = frozenset({f"p{i}" for i in range(15)} | {"a", "b", "c", "d"})
29
+ formula = ltl.And(
30
+ (
31
+ ltl.Eventually(ltl.Variable("a")),
32
+ ltl.Eventually(ltl.Variable("b")),
33
+ ltl.Eventually(ltl.Variable("c")),
34
+ ltl.Eventually(ltl.Variable("d")),
35
+ )
36
+ )
37
+ alphabet = powerset_alphabet(aps)
38
+ aut: Automaton[int, Input[str], str] = ltl_to_automaton(formula, finite=True)
39
+ return SymbolicAutomaton.from_automaton(aut, alphabet=alphabet).to_min_dfa()
40
+
41
+
42
+ def test_language_equivalent_sparse_big_alphabet(benchmark: Benchmark) -> None:
43
+ dfa = _sparse_big_alphabet_dfa()
44
+
45
+ def _run() -> bool:
46
+ return language_equivalent(dfa, dfa)
47
+
48
+ assert benchmark(_run)
49
+
50
+
51
+ def test_isomorphic_sparse_big_alphabet(benchmark: Benchmark) -> None:
52
+ dfa = _sparse_big_alphabet_dfa()
53
+
54
+ def _run() -> bool:
55
+ return isomorphic(dfa, dfa)
56
+
57
+ assert benchmark(_run)
@@ -0,0 +1,124 @@
1
+ """Micro-benchmarks for ``symbolic_automaton_to_hoa``.
2
+
3
+ Targets the per-row ``bdd_to_boolexpr`` work in
4
+ ``morphata.hoa.exporter.symbolic_automaton_to_hoa``. The export walks
5
+ every cached ``(guard_bdd, succ_bdd)`` row, decodes both BDDs into
6
+ ``BoolExpr`` trees, and renders text. In real workloads the same
7
+ ``dd.Function`` recurs heavily across rows -- canonical guards shared by
8
+ many transitions, and successor BDDs shared by many guards in DFAs --
9
+ so caching the per-Function rendering is expected to dominate raw
10
+ ``bdd_to_boolexpr`` cost.
11
+
12
+ These cases hit the three regimes that matter:
13
+
14
+ - ``small_alphabet_dfa``: small AP universe, dense DFA. Baseline; cache
15
+ effect should be small (few distinct guards anyway).
16
+ - ``sparse_big_alphabet_dfa``: large AP universe but sparse guards
17
+ (mirrors ``test_equivalence_perf``). Many rows, few distinct
18
+ ``guard_bdd`` Functions -> label cache pays.
19
+ - ``conjunction_min_dfa``: ``Eventually(a) & ... & Eventually(d)`` min-DFA
20
+ with extra padding APs. Both caches pay: same guards across many
21
+ states, and many guards point to the same successor partition.
22
+ - ``afa_no_minimize``: raw LTL -> AFA without minimization. Exercises
23
+ the un-determinized regime where successor BDDs are richer (one per
24
+ conjunctive obligation).
25
+
26
+ Run with: ``pytest bench/test_hoa_exporter_perf.py -v``
27
+ """
28
+
29
+ from __future__ import annotations
30
+
31
+ import logic_asts.ltl as ltl
32
+ from pytest_benchmark.fixture import BenchmarkFixture as Benchmark
33
+
34
+ from morphata.alphabet import powerset_alphabet
35
+ from morphata.hoa.exporter import symbolic_automaton_to_hoa
36
+ from morphata.symbolic.automaton import SymbolicAutomaton
37
+ from morphata.symbolic.bdd import Manager
38
+
39
+
40
+ def _small_alphabet_dfa(mgr: Manager) -> SymbolicAutomaton[str]:
41
+ aps = frozenset({"a", "b"})
42
+ formula = ltl.Eventually(ltl.And((ltl.Variable("a"), ltl.Variable("b"))))
43
+ alphabet = powerset_alphabet(aps)
44
+ return SymbolicAutomaton.from_ltl(formula, alphabet=alphabet, manager=mgr, finite=True).to_min_dfa()
45
+
46
+
47
+ def _sparse_big_alphabet_dfa(mgr: Manager) -> SymbolicAutomaton[str]:
48
+ aps = frozenset({f"p{i}" for i in range(15)} | {"a", "b", "c", "d"})
49
+ formula = ltl.And(
50
+ (
51
+ ltl.Eventually(ltl.Variable("a")),
52
+ ltl.Eventually(ltl.Variable("b")),
53
+ ltl.Eventually(ltl.Variable("c")),
54
+ ltl.Eventually(ltl.Variable("d")),
55
+ )
56
+ )
57
+ alphabet = powerset_alphabet(aps)
58
+ return SymbolicAutomaton.from_ltl(formula, alphabet=alphabet, manager=mgr, finite=True).to_min_dfa()
59
+
60
+
61
+ def _conjunction_min_dfa(mgr: Manager) -> SymbolicAutomaton[str]:
62
+ aps = frozenset({f"q{i}" for i in range(8)} | {"a", "b", "c", "d", "e"})
63
+ formula = ltl.And(
64
+ (
65
+ ltl.Eventually(ltl.Variable("a")),
66
+ ltl.Eventually(ltl.Variable("b")),
67
+ ltl.Eventually(ltl.Variable("c")),
68
+ ltl.Eventually(ltl.Variable("d")),
69
+ ltl.Eventually(ltl.Variable("e")),
70
+ )
71
+ )
72
+ alphabet = powerset_alphabet(aps)
73
+ return SymbolicAutomaton.from_ltl(formula, alphabet=alphabet, manager=mgr, finite=True).to_min_dfa()
74
+
75
+
76
+ def _afa_no_minimize(mgr: Manager) -> SymbolicAutomaton[str]:
77
+ aps = frozenset({"a", "b", "c", "d"})
78
+ formula = ltl.Until(
79
+ ltl.Variable("a"),
80
+ ltl.And(
81
+ (
82
+ ltl.Variable("b"),
83
+ ltl.Eventually(ltl.And((ltl.Variable("c"), ltl.Eventually(ltl.Variable("d"))))),
84
+ )
85
+ ),
86
+ )
87
+ alphabet = powerset_alphabet(aps)
88
+ return SymbolicAutomaton.from_ltl(formula, alphabet=alphabet, manager=mgr, finite=True)
89
+
90
+
91
+ def test_hoa_export_small_alphabet_dfa(benchmark: Benchmark, bench_mgr: Manager) -> None:
92
+ sym = _small_alphabet_dfa(bench_mgr)
93
+
94
+ def _run() -> int:
95
+ return len(symbolic_automaton_to_hoa(sym))
96
+
97
+ assert benchmark(_run) > 0
98
+
99
+
100
+ def test_hoa_export_sparse_big_alphabet_dfa(benchmark: Benchmark, bench_mgr: Manager) -> None:
101
+ sym = _sparse_big_alphabet_dfa(bench_mgr)
102
+
103
+ def _run() -> int:
104
+ return len(symbolic_automaton_to_hoa(sym))
105
+
106
+ assert benchmark(_run) > 0
107
+
108
+
109
+ def test_hoa_export_conjunction_min_dfa(benchmark: Benchmark, bench_mgr: Manager) -> None:
110
+ sym = _conjunction_min_dfa(bench_mgr)
111
+
112
+ def _run() -> int:
113
+ return len(symbolic_automaton_to_hoa(sym))
114
+
115
+ assert benchmark(_run) > 0
116
+
117
+
118
+ def test_hoa_export_afa_no_minimize(benchmark: Benchmark, bench_mgr: Manager) -> None:
119
+ sym = _afa_no_minimize(bench_mgr)
120
+
121
+ def _run() -> int:
122
+ return len(symbolic_automaton_to_hoa(sym))
123
+
124
+ assert benchmark(_run) > 0
@@ -0,0 +1,124 @@
1
+ """Micro-benchmarks for :func:`morphata.symbolic.successors_for_alphabet`.
2
+
3
+ Two cases:
4
+
5
+ - Wide-cofactor: source = initial state of the min-DFA for
6
+ ``F a & F b & F c & F d``; many outgoing rows, ~1-4 APs in support
7
+ per row. Exercises the support-projection win.
8
+ - Narrow-cofactor: source = a deep-BFS state of the same DFA after
9
+ most eventualities discharged; few rows, narrow support. Exercises
10
+ non-regression vs. the pre-rewrite ``T_src`` shape.
11
+
12
+ Run with: ``pytest bench/test_successors_for_alphabet_perf.py -v``
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import time
18
+
19
+ import logic_asts.ltl as ltl
20
+ from pytest_benchmark.fixture import BenchmarkFixture as Benchmark
21
+
22
+ from morphata.alphabet import BooleanAlphabet, finite_alphabet
23
+ from morphata.symbolic import SymbolicAutomaton, successors_for_alphabet
24
+
25
+
26
+ def _build_min_dfa() -> SymbolicAutomaton[str]:
27
+ formula = ltl.And(
28
+ (
29
+ ltl.Eventually(ltl.Variable("a")),
30
+ ltl.Eventually(ltl.Variable("b")),
31
+ ltl.Eventually(ltl.Variable("c")),
32
+ ltl.Eventually(ltl.Variable("d")),
33
+ )
34
+ )
35
+ alphabet = finite_alphabet(frozenset({"a", "b", "c", "d"}))
36
+ sym = SymbolicAutomaton.from_ltl(formula, alphabet=alphabet, finite=True)
37
+ return sym.to_min_dfa()
38
+
39
+
40
+ def _wide_alphabet_with_overlap() -> BooleanAlphabet[str, str]:
41
+ """26-symbol alphabet over AP universe {a, b, c, d}.
42
+
43
+ sym_0..sym_3 carry the AP truths for a/b/c/d (one each); sym_4..sym_25
44
+ carry no AP truth. Forces ``successors_for_alphabet`` to iterate over
45
+ a moderate-size symbol list with non-trivial classes per row.
46
+ """
47
+ aps = frozenset({"a", "b", "c", "d"})
48
+ labels: dict[str, frozenset[str]] = {f"sym_{i}": frozenset() for i in range(26)}
49
+ labels["sym_0"] = frozenset({"a"})
50
+ labels["sym_1"] = frozenset({"b"})
51
+ labels["sym_2"] = frozenset({"c"})
52
+ labels["sym_3"] = frozenset({"d"})
53
+ return BooleanAlphabet(predicates=aps, labeling=lambda s: labels[s])
54
+
55
+
56
+ def _initial_index(sym: SymbolicAutomaton[str]) -> int:
57
+ for k in range(sym.num_states):
58
+ if sym.initial == sym.manager.var(f"q{k}"):
59
+ return k
60
+ raise AssertionError("min-DFA initial must be a single state variable")
61
+
62
+
63
+ def test_wide_cofactor_state_runs_quickly() -> None:
64
+ """Initial state of F a & F b & F c & F d: many outgoing rows, wide support."""
65
+ sym = _build_min_dfa()
66
+ alphabet = _wide_alphabet_with_overlap()
67
+ symbols = [f"sym_{i}" for i in range(26)]
68
+ initial = _initial_index(sym)
69
+
70
+ t0 = time.perf_counter()
71
+ pairs = list(successors_for_alphabet(sym, initial, alphabet, symbols))
72
+ elapsed = time.perf_counter() - t0
73
+
74
+ assert pairs, "expected at least one successor for the initial state"
75
+ # Generous bound; rewrite runs in well under 1s on this case.
76
+ assert elapsed < 1.0, f"successors_for_alphabet on initial took {elapsed:.3f}s"
77
+
78
+
79
+ def test_narrow_cofactor_state_runs_quickly() -> None:
80
+ """A deep-BFS state with few rows must not regress vs. the old T_src path."""
81
+ sym = _build_min_dfa()
82
+ alphabet = _wide_alphabet_with_overlap()
83
+ symbols = [f"sym_{i}" for i in range(26)]
84
+
85
+ # Walk a few steps from the initial state to discharge a/b/c.
86
+ cur = sym.initial
87
+ for s in ("sym_0", "sym_1", "sym_2"):
88
+ cur = sym.step(cur, s)
89
+ deep_index = -1
90
+ for k in range(sym.num_states):
91
+ if cur == sym.manager.var(f"q{k}"):
92
+ deep_index = k
93
+ break
94
+ assert deep_index != -1, "expected to land on a single state after three steps"
95
+
96
+ t0 = time.perf_counter()
97
+ pairs = list(successors_for_alphabet(sym, deep_index, alphabet, symbols))
98
+ elapsed = time.perf_counter() - t0
99
+
100
+ assert pairs, "expected at least one successor"
101
+ assert elapsed < 0.5, f"deep-state enumeration took {elapsed:.3f}s"
102
+
103
+
104
+ def test_q1_post_discharge_state_per_call_cost(benchmark: Benchmark) -> None:
105
+ """Per-call cost of successors_for_alphabet at the 16-row / sup-4 state.
106
+
107
+ q1 has 16 outgoing rows that all share support {a, b, c, d}. With
108
+ per-bucket amortization the symbol partition and per-class point
109
+ dicts are built once for the bucket and shared across the 16
110
+ rows; the per-row cost reduces to |classes| cofactor calls.
111
+ pytest-benchmark records the timing distribution -- no hard-coded
112
+ threshold here, the dataset is the regression signal.
113
+ """
114
+ sym = _build_min_dfa()
115
+ alphabet = _wide_alphabet_with_overlap()
116
+ symbols = [f"sym_{i}" for i in range(26)]
117
+
118
+ q1 = next(k for k in range(sym.num_states) if len(sym.transitions[k]) == 16)
119
+
120
+ def _run() -> int:
121
+ return sum(1 for _ in successors_for_alphabet(sym, q1, alphabet, symbols))
122
+
123
+ n_yielded = benchmark(_run)
124
+ assert n_yielded > 0
@@ -33,6 +33,13 @@ Structural Transforms
33
33
  :members:
34
34
  :show-inheritance:
35
35
 
36
+ Composition
37
+ -----------
38
+
39
+ .. automodule:: morphata.symbolic.compose
40
+ :members:
41
+ :show-inheritance:
42
+
36
43
  Language Equivalence
37
44
  --------------------
38
45
 
@@ -2,7 +2,7 @@
2
2
  name = "morphata"
3
3
  authors = [{ name = "Anand Balakrishnan", email = "anandbala1597@gmail.com" }]
4
4
  description = "Representation theory for automata, made practical."
5
- version = "2.0.7"
5
+ version = "2.0.9"
6
6
  requires-python = ">=3.12"
7
7
  classifiers = [
8
8
  "Intended Audience :: Science/Research",
@@ -205,13 +205,7 @@ def symbolic_automaton_to_hoa(
205
205
 
206
206
  ap_order = sorted(sym.ap_registry, key=repr)
207
207
  ap_to_index: dict[ty.Any, int] = {ap: i for i, ap in enumerate(ap_order)}
208
- ap_decoder_map: dict[str, ty.Any] = {var: ap for ap, var in sym.ap_registry.items()}
209
-
210
- def _ap_decode(name: str) -> ty.Any: # noqa: ANN401
211
- try:
212
- return ap_decoder_map[name]
213
- except KeyError as exc:
214
- raise ValueError(f"Guard BDD references variable {name!r} not in the AP registry.") from exc
208
+ bdd_var_to_ap_index: dict[str, int] = {var: ap_to_index[ap] for ap, var in sym.ap_registry.items()}
215
209
 
216
210
  acc_name, acc_expr_text, num_sets, acc_state_sets = _acceptance_to_hoa(sym.acceptance)
217
211
  if true_sink is not None:
@@ -248,11 +242,22 @@ def symbolic_automaton_to_hoa(
248
242
  if properties:
249
243
  buf.write("properties: " + " ".join(properties) + "\n")
250
244
 
245
+ # Per-call caches keyed by dd.Function identity. Guards and successor
246
+ # BDDs recur heavily across rows (shared canonical guards; many guards
247
+ # leading to the same target set in DFAs). With the pick_iter-based
248
+ # renderers below the per-Function rendering cost is much smaller
249
+ # than it was with the bdd_to_boolexpr + _label_to_hoa pipeline, but
250
+ # the caches still pay back on shared Functions. Kept as two separate
251
+ # dicts since the pipelines produce different shapes (str vs list[str]);
252
+ # freed explicitly before return to limit Function references held
253
+ # against the CUDD backend.
254
+ label_cache: dict[ty.Any, str] = {}
255
+ dsts_cache: dict[ty.Any, list[str]] = {}
256
+ marker_by_state = _markers_by_state(acc_state_sets)
257
+
251
258
  buf.write("--BODY--\n")
252
259
  for s in states:
253
- sets_for_s = sorted(idx for idx, members in acc_state_sets.items() if s in members)
254
- marker = (" {" + " ".join(str(i) for i in sets_for_s) + "}") if sets_for_s else ""
255
- buf.write(f"State: {s}{marker}\n")
260
+ buf.write(f"State: {s}{marker_by_state.get(s, '')}\n")
256
261
  for guard_bdd, succ_bdd in sym.transitions.get(s, ()):
257
262
  if succ_bdd == mgr.true:
258
263
  assert true_sink is not None
@@ -260,22 +265,27 @@ def symbolic_automaton_to_hoa(
260
265
  elif succ_bdd == mgr.false:
261
266
  assert false_sink is not None
262
267
  dsts = [str(false_sink)]
268
+ elif succ_bdd in dsts_cache:
269
+ dsts = dsts_cache[succ_bdd]
270
+ else:
271
+ dsts = _bdd_state_cubes(succ_bdd, mgr=mgr)
272
+ dsts_cache[succ_bdd] = dsts
273
+ if guard_bdd in label_cache:
274
+ label = label_cache[guard_bdd]
263
275
  else:
264
- succ_expr = ty.cast("logic.BoolExpr[int]", bdd_to_boolexpr(succ_bdd))
265
- dsts = _state_expr_to_edges(succ_expr)
266
- guard_expr = bdd_to_boolexpr(guard_bdd, var_decoder=_ap_decode)
267
- label = _label_to_hoa(guard_expr, ap_to_index)
276
+ label = _bdd_to_hoa_label(guard_bdd, mgr=mgr, bdd_var_to_ap_index=bdd_var_to_ap_index)
277
+ label_cache[guard_bdd] = label
268
278
  for dst in dsts:
269
279
  buf.write(f"[{label}] {dst}\n")
270
280
  for sink in (true_sink, false_sink):
271
281
  if sink is None:
272
282
  continue
273
- sets_for_sink = sorted(idx for idx, members in acc_state_sets.items() if sink in members)
274
- marker = (" {" + " ".join(str(i) for i in sets_for_sink) + "}") if sets_for_sink else ""
275
- buf.write(f"State: {sink}{marker}\n")
283
+ buf.write(f"State: {sink}{marker_by_state.get(sink, '')}\n")
276
284
  buf.write(f"[t] {sink}\n")
277
285
  buf.write("--END--\n")
278
286
 
287
+ del label_cache, dsts_cache
288
+
279
289
  if owns_buffer:
280
290
  assert isinstance(buf, io.StringIO)
281
291
  return buf.getvalue()
@@ -475,11 +485,10 @@ def _write_body(
475
485
  from morphata.automaton import Outgoing
476
486
 
477
487
  assert isinstance(aut.delta, Outgoing)
488
+ marker_by_state = _markers_by_state(acc_state_sets)
478
489
  buf.write("--BODY--\n")
479
490
  for s in states:
480
- sets_for_s = sorted(idx for idx, members in acc_state_sets.items() if s in members)
481
- marker = (" {" + " ".join(str(i) for i in sets_for_s) + "}") if sets_for_s else ""
482
- buf.write(f"State: {s}{marker}\n")
491
+ buf.write(f"State: {s}{marker_by_state.get(s, '')}\n")
483
492
  for guard, succ in aut.delta.fn(s):
484
493
  label_text = _label_to_hoa(guard, ap_to_index)
485
494
  for dst_text in _state_expr_to_edges(succ):
@@ -595,6 +604,34 @@ def _cube_to_hoa_label(
595
604
  return "(" + " & ".join(parts) + ")"
596
605
 
597
606
 
607
+ def _bdd_to_hoa_label(
608
+ node: "Function",
609
+ *,
610
+ mgr: "Manager",
611
+ bdd_var_to_ap_index: Mapping[str, int],
612
+ ) -> str:
613
+ """Render a guard BDD as a single HOA label string.
614
+
615
+ Bypasses :func:`~morphata.symbolic.bdd.bdd_to_boolexpr` -- which
616
+ walks the BDD via Shannon expansion, builds a ``logic_asts``
617
+ ``BoolExpr`` tree, and runs NNF normalisation -- by enumerating the
618
+ BDD's cubes directly with ``mgr.pick_iter`` and joining their HOA
619
+ renderings with ``|``. Output shape matches the prior
620
+ ``bdd_to_boolexpr`` + :func:`_label_to_hoa` pipeline for HOA
621
+ consumers: one label per row, possibly disjunctive.
622
+ """
623
+ if node == mgr.true:
624
+ return "t"
625
+ if node == mgr.false:
626
+ return "f"
627
+ cube_labels = [_cube_to_hoa_label(cube, bdd_var_to_ap_index) for cube in mgr.pick_iter(node)]
628
+ if not cube_labels:
629
+ return "f"
630
+ if len(cube_labels) == 1:
631
+ return cube_labels[0]
632
+ return "(" + " | ".join(cube_labels) + ")"
633
+
634
+
598
635
  def _bdd_state_cubes(node: "Function", *, mgr: "Manager") -> list[str]:
599
636
  """Enumerate satisfying cubes of *node* over state variables as HOA dst strings.
600
637
 
@@ -629,6 +666,23 @@ def _bdd_state_cubes(node: "Function", *, mgr: "Manager") -> list[str]:
629
666
  # ---------------------------------------------------------------------------
630
667
 
631
668
 
669
+ def _markers_by_state(
670
+ acc_state_sets: Mapping[int, AbstractSet[int]],
671
+ ) -> dict[int, str]:
672
+ """Invert ``acc_state_sets`` into per-state ``" {i j ...}"`` markers.
673
+
674
+ Replaces the per-state ``sorted(idx for ... if s in members)`` scan
675
+ in the body loop, which is O(|states| * |acc_sets|). Inverting once
676
+ is O(sum of set sizes). Only states with at least one membership get
677
+ an entry; callers default to ``""`` via ``dict.get(s, "")``.
678
+ """
679
+ by_state: dict[int, list[int]] = {}
680
+ for idx, members in acc_state_sets.items():
681
+ for s in members:
682
+ by_state.setdefault(s, []).append(idx)
683
+ return {s: " {" + " ".join(str(i) for i in sorted(indices)) + "}" for s, indices in by_state.items()}
684
+
685
+
632
686
  def _acceptance_to_hoa(
633
687
  cond: AcceptanceCondition[int],
634
688
  ) -> tuple[str | None, str, int, Mapping[int, AbstractSet[int]]]:
@@ -38,7 +38,9 @@ from morphata.symbolic.bdd import guard_to_bdd as guard_to_bdd
38
38
  from morphata.symbolic.bdd import make_ap_registry as make_ap_registry
39
39
  from morphata.symbolic.bdd import make_manager as make_manager
40
40
  from morphata.symbolic.bdd import state_var_name as state_var_name
41
+ from morphata.symbolic.compose import CompositionMap as CompositionMap
41
42
  from morphata.symbolic.compose import compose_min_dfa as compose_min_dfa
43
+ from morphata.symbolic.compose import iter_composed_transitions as iter_composed_transitions
42
44
  from morphata.symbolic.compose import min_dfa_of_conjunction as min_dfa_of_conjunction
43
45
  from morphata.symbolic.equivalence import canonical_form as canonical_form
44
46
  from morphata.symbolic.equivalence import isomorphic as isomorphic