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 0 0 I->0 1 1 0->1 a 1->1 !b 1->1 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/__init__.py in automaton(filename, **kwargs)
    463     See `spot.automata` for a list of supported formats."""
    464     try:
--> 465         return next(automata(filename, **kwargs))
    466     except StopIteration:
    467         raise RuntimeError("Failed to read automaton from {}".format(filename))

/home/adl/git/spot/python/spot/__init__.py in automata(timeout, ignore_abort, trust_hoa, no_sid, debug, *sources)
    448                 del proc
    449                 if ret:
--> 450                     raise subprocess.CalledProcessError(ret, filename[:-1])
    451     # deleting o explicitely now prevents Python 3.5 from
    452     # 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/__init__.py in automata(timeout, ignore_abort, trust_hoa, no_sid, debug, *sources)
    448                 del proc
    449                 if ret:
--> 450                     raise subprocess.CalledProcessError(ret, filename[:-1])
    451     # deleting o explicitely now prevents Python 3.5 from
    452     # 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|')
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
/home/adl/git/spot/python/spot/__init__.py in automaton(filename, **kwargs)
    464     try:
--> 465         return next(automata(filename, **kwargs))
    466     except StopIteration:

StopIteration: 

During handling of the above exception, another exception occurred:

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

/home/adl/git/spot/python/spot/__init__.py in automaton(filename, **kwargs)
    465         return next(automata(filename, **kwargs))
    466     except StopIteration:
--> 467         raise RuntimeError("Failed to read automaton from {}".format(filename))
    468 
    469 

RuntimeError: Failed to read automaton from true|
In [ ]: