morphata 2.0.8__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.
- {morphata-2.0.8 → morphata-2.0.9}/CHANGELOG.md +22 -0
- {morphata-2.0.8 → morphata-2.0.9}/PKG-INFO +1 -1
- {morphata-2.0.8 → morphata-2.0.9}/bench/README.md +4 -0
- morphata-2.0.9/bench/test_hoa_exporter_perf.py +124 -0
- {morphata-2.0.8 → morphata-2.0.9}/pyproject.toml +1 -1
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/hoa/exporter.py +74 -20
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/symbolic/persistence.py +38 -3
- {morphata-2.0.8 → morphata-2.0.9}/uv.lock +1 -1
- {morphata-2.0.8 → morphata-2.0.9}/.basedpyright/baseline.json +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.claude/settings.local.json +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.dockerignore +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.editorconfig +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.envrc +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.envrc.recommended +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.fdignore +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.gitattributes +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.gitignore +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.mailmap +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.python-version +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/.rstcheck.cfg +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/AGENTS.md +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/CLAUDE.md +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/CONTRIBUTING.md +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/LICENSE +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/README.md +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/bench/__init__.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/bench/conftest.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/bench/test_equivalence_perf.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/bench/test_sere_nlm_perf.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/bench/test_successors_for_alphabet_perf.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/ci/make-release +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/cliff.toml +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/_static/navigation.html +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/modules.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.acceptance.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.alphabet.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.automaton.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.builder.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.hoa.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.logic.ltl.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.logic.psl.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.logic.sere.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.logic.strel.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.operators.matrix.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.operators.polynomial.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.operators.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/api/morphata.symbolic.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/concepts/acceptance.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/concepts/hoa.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/concepts/index.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/concepts/operators.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/concepts/spec.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/concepts/weights.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/conf.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/index.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/quick-start.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/docs/symbolic-transforms.rst +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/justfile +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/mypy.ini +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/pixi.lock +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/pixi.toml +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/project.utf-8.add +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/project.utf-8.add.spl +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/pyrefly.toml +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/pyrightconfig.json +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/pytest.toml +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/ruff.toml +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/__init__.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/acceptance.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/alphabet.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/automaton.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/builder.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/hoa/__init__.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/hoa/__main__.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/hoa/acc_expr.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/hoa/hoa.lark +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/hoa/parser.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/logic/__init__.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/logic/_common.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/logic/ltl.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/logic/psl.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/logic/sere.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/logic/strel.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/operators/__init__.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/operators/_backend.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/operators/matrix.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/operators/polynomial.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/py.typed +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/symbolic/__init__.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/symbolic/automaton.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/symbolic/bdd.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/symbolic/compose.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/symbolic/equivalence.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/src/morphata/symbolic/transforms.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/conftest.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut1.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut11.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut2.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut3.2.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut3.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut4.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut5.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut6.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut7.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/aut8.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/finite_aut.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/gen_buchi_3.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/gen_cobuchi_2.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/rabin_2pair.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/streett_2pair.hoa +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/test_exporter_basic.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/test_exporter_roundtrip.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/test_exporter_streaming.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/hoa/test_parser.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/logic/__init__.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/logic/test_ltl.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/logic/test_psl.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/logic/test_sere.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/logic/test_sere_properties.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/logic/test_strel.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/operators/test_matrix_from_ir.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/operators/test_matrix_from_ltl.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/operators/test_polynomial_from_ir.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_alphabet_aware_transitions.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_bdd_helpers.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_compose.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_composition_map.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_equivalence_naive_property.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_from_hoaf.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_ltlf2dfa_equivalence.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_persistence.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_step.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_symbolic_automaton.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_symbolic_from_ir.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_to_hoa.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_transforms.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_transforms_ir.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/symbolic/test_transforms_properties.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/test_alphabet.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/test_automaton.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/test_builder.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/tests/test_from_parsed.py +0 -0
- {morphata-2.0.8 → morphata-2.0.9}/ty.toml +0 -0
|
@@ -1,5 +1,27 @@
|
|
|
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
|
+
|
|
3
25
|
## 2.0.8 — 2026-06-03
|
|
4
26
|
|
|
5
27
|
### Added
|
|
@@ -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,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
|
|
@@ -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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
265
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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]]]:
|
|
@@ -44,8 +44,12 @@ semantics should write to a scratch directory and rename the directory.
|
|
|
44
44
|
from __future__ import annotations
|
|
45
45
|
|
|
46
46
|
import json
|
|
47
|
+
import shutil
|
|
48
|
+
import tempfile
|
|
47
49
|
from pathlib import Path
|
|
48
|
-
from typing import TYPE_CHECKING, Any
|
|
50
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
51
|
+
|
|
52
|
+
from dd import _copy as _dd_copy
|
|
49
53
|
|
|
50
54
|
from morphata.acceptance import (
|
|
51
55
|
AcceptanceCondition,
|
|
@@ -143,6 +147,37 @@ def _meta_path_for(bdd_path: Path) -> Path:
|
|
|
143
147
|
return Path(str(bdd_path) + ".meta.json")
|
|
144
148
|
|
|
145
149
|
|
|
150
|
+
# dd's public ``dump_json`` / ``load_json`` wrappers open a ``shelve`` at a
|
|
151
|
+
# hardcoded relative ``__shelve__`` directory and ``os.makedirs`` it without
|
|
152
|
+
# ``exist_ok``, so a stale dir from a crashed prior run breaks the next call
|
|
153
|
+
# and concurrent calls collide. The underscore variants take the cache as a
|
|
154
|
+
# parameter, so we re-wrap them against a per-call tempdir.
|
|
155
|
+
def _dump_json_safe(nodes: dict[str, Function], file_name: str) -> None:
|
|
156
|
+
shelve_dir = Path(tempfile.mkdtemp(prefix="morphata-dd-"))
|
|
157
|
+
try:
|
|
158
|
+
shelf_path = shelve_dir / "shelf"
|
|
159
|
+
with (
|
|
160
|
+
_dd_copy._open_shelf(str(shelf_path)) as cache,
|
|
161
|
+
open(file_name, "w") as fd,
|
|
162
|
+
):
|
|
163
|
+
_dd_copy._dump_json(cast(Any, nodes), fd, cache)
|
|
164
|
+
finally:
|
|
165
|
+
shutil.rmtree(shelve_dir, ignore_errors=True)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _load_json_safe(file_name: str, bdd: Manager, load_order: bool = False) -> dict[str, Function]:
|
|
169
|
+
shelve_dir = Path(tempfile.mkdtemp(prefix="morphata-dd-"))
|
|
170
|
+
try:
|
|
171
|
+
shelf_path = shelve_dir / "shelf"
|
|
172
|
+
with (
|
|
173
|
+
_dd_copy._open_shelf(str(shelf_path)) as cache,
|
|
174
|
+
open(file_name) as fd,
|
|
175
|
+
):
|
|
176
|
+
return cast("dict[str, Function]", _dd_copy._load_json(fd, bdd, load_order, cache))
|
|
177
|
+
finally:
|
|
178
|
+
shutil.rmtree(shelve_dir, ignore_errors=True)
|
|
179
|
+
|
|
180
|
+
|
|
146
181
|
def to_bdd_json(sym: "SymbolicAutomaton[Any]", path: str | Path) -> None:
|
|
147
182
|
"""Persist *sym* to ``path`` (BDD JSON) plus a ``<path>.meta.json`` sidecar.
|
|
148
183
|
|
|
@@ -232,7 +267,7 @@ def to_bdd_json(sym: "SymbolicAutomaton[Any]", path: str | Path) -> None:
|
|
|
232
267
|
}
|
|
233
268
|
|
|
234
269
|
if bdd_roots:
|
|
235
|
-
|
|
270
|
+
_dump_json_safe(bdd_roots, str(bdd_partial))
|
|
236
271
|
with open(meta_partial, "w") as f:
|
|
237
272
|
json.dump(meta, f, indent=2, sort_keys=True)
|
|
238
273
|
|
|
@@ -296,7 +331,7 @@ def from_bdd_json(
|
|
|
296
331
|
if meta.get("bdd_file_empty", False):
|
|
297
332
|
roots: dict[str, Function] = {}
|
|
298
333
|
else:
|
|
299
|
-
loaded =
|
|
334
|
+
loaded = _load_json_safe(str(bdd_path), manager)
|
|
300
335
|
if not isinstance(loaded, dict):
|
|
301
336
|
raise ValueError(
|
|
302
337
|
f"BDD JSON load returned {type(loaded).__name__}; expected a "
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|