from IPython.display import display
import spot
spot.setup()
Use to_str()
to output a string representing the automaton in different formats.
a = spot.translate('a U b')
for fmt in ('hoa', 'spin', 'dot', 'lbtt'):
print(a.to_str(fmt))
Use save()
to save the automaton into a file.
a.save('example.aut').save('example.aut', format='lbtt', append=True)
!cat example.aut
Use spot.automata()
to read multiple automata from a file, and spot.automaton()
to read only one.
for a in spot.automata('example.aut'):
display(a)
The --ABORT--
feature of the HOA format allows discarding the automaton being read and starting over.
%%file example.aut
HOA: v1
States: 2
Start: 1
AP: 2 "a" "b"
acc-name: Buchi
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[t] 0
--ABORT-- /* the previous automaton should be ignored */
HOA: v1
States: 2
Start: 1
AP: 2 "a" "b"
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[t] 0
State: 1
[1] 0
[0&!1] 1
--END--
for a in spot.automata('example.aut'):
display(a)
Instead of passing a filename, you can also pass the contents of a file. spot.automata()
and spot.automaton()
look for the absence of newline to decide if this is a filename or a string containing some actual automaton text.
for a in spot.automata("""
HOA: v1
States: 2
Start: 1
name: "Hello world"
AP: 2 "a" "b"
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[t] 0
State: 1
[1] 0
[0&!1] 1
--END--
HOA: v1
States: 1
Start: 0
name: "Hello world 2"
AP: 2 "a" "b"
Acceptance: 2 Inf(0)&Inf(1)
--BODY--
State: 0 {0}
[t] 0 {1}
[0&!1] 0
--END--
"""):
display(a)
If an argument of spot.automata
ends with |
, then it is interpreted as a shell command that outputs one automaton or more.
for a in spot.automata('ltl2tgba -s "a U b"; ltl2tgba --lbtt "b"|', 'ltl2tgba -H "GFa" "a & GFb"|'):
display(a)
A single automaton can be read using spot.automaton()
, with the same convention.
spot.automaton('ltl2tgba -s6 "a U b"|')
!rm example.aut