In [1]:
from IPython.display import display 
import spot
spot.setup()

Reading automata output from processes

If an argument of spot.automata ends with |, then it is interpreted as a shell command that outputs one automaton or more.


In [2]:
for a in spot.automata('ltl2tgba -s "a U b"; ltl2tgba --lbtt "b"|', 'ltl2tgba -H "GFa" "a & GFb"|'):
    display(a)


G 0 0 I->0 0->0 a & !b 1 1 0->1 b 1->1 1
G 0 0 I->0 1 1 0->1 b 1->1 1
G 0 0 I->0 0->0 a 0->0 !a
G 1 1 I->1 0 0 1->0 a 0->0 b 0->0 !b

A single automaton can be read using spot.automaton(), with the same convention.


In [3]:
spot.automaton('ltl2tgba -s6 "a U b"|')


Out[3]:
G 0 0 I->0 0->0 a & !b 1 1 0->1 b 1->1 1

Error handling

If the shell command terminates with a non-zero exit status, we should get an exception.


In [4]:
spot.automaton('non-existing-command|')


---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-4-765c7cc6937f> in <module>()
----> 1 spot.automaton('non-existing-command|')

/home/adl/git/spot/python/spot.py in automaton(filename, **kwargs)
    457     See `spot.automata` for a list of supported formats."""
    458     try:
--> 459         return next(automata(filename, **kwargs))
    460     except StopIteration:
    461         raise RuntimeError("Failed to read automaton from {}".format(filename))

/home/adl/git/spot/python/spot.py in automata(timeout, ignore_abort, trust_hoa, debug, *sources)
    442                 del proc
    443                 if ret:
--> 444                     raise subprocess.CalledProcessError(ret, filename[:-1])
    445     # deleting o explicitely now prevents Python 3.5 from
    446     # reporting the following error: "<built-in function

CalledProcessError: Command 'non-existing-command' returned non-zero exit status 127

In [5]:
for a in spot.automata("ltl2tgba 'a U b'|", 'ltl2tgba "syntax U U error"|'):
    display(a)


G 1 1 I->1 1->1 a & !b 0 0 1->0 b 0->0 1
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-5-1163f8abbaad> in <module>()
----> 1 for a in spot.automata("ltl2tgba 'a U b'|", 'ltl2tgba "syntax U U error"|'):
      2     display(a)

/home/adl/git/spot/python/spot.py in automata(timeout, ignore_abort, trust_hoa, debug, *sources)
    442                 del proc
    443                 if ret:
--> 444                     raise subprocess.CalledProcessError(ret, filename[:-1])
    445     # deleting o explicitely now prevents Python 3.5 from
    446     # reporting the following error: "<built-in function

CalledProcessError: Command 'ltl2tgba "syntax U U error"' returned non-zero exit status 2

Reading an empty file with spot.automaton() is an error.


In [6]:
spot.automaton('true|')


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-f4e056a50029> in <module>()
----> 1 spot.automaton('true|')

/home/adl/git/spot/python/spot.py in automaton(filename, **kwargs)
    459         return next(automata(filename, **kwargs))
    460     except StopIteration:
--> 461         raise RuntimeError("Failed to read automaton from {}".format(filename))
    462 
    463 

RuntimeError: Failed to read automaton from true|

In [ ]: