{ "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3+" }, "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import display\n", "import spot\n", "spot.setup()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "a = spot.translate('a U b')\n", "for fmt in ('hoa', 'spin', 'dot', 'lbtt'):\n", " print(a.to_str(fmt))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "HOA: v1\n", "States: 2\n", "Start: 1\n", "AP: 2 \"a\" \"b\"\n", "acc-name: Buchi\n", "Acceptance: 1 Inf(0)\n", "properties: trans-labels explicit-labels state-acc deterministic\n", "properties: stutter-invariant inherently-weak\n", "--BODY--\n", "State: 0 {0}\n", "[t] 0\n", "State: 1\n", "[1] 0\n", "[0&!1] 1\n", "--END--\n", "never {\n", "T0_init:\n", " if\n", " :: ((b)) -> goto accept_all\n", " :: ((a) && (!(b))) -> goto T0_init\n", " fi;\n", "accept_all:\n", " skip\n", "}\n", "\n", "digraph G {\n", " rankdir=LR\n", " node [shape=\"circle\"]\n", " fontname=\"Lato\"\n", " node [fontname=\"Lato\"]\n", " edge [fontname=\"Lato\"]\n", " size=\"10.2,5\" node[style=filled,fillcolor=\"#ffffaa\"] edge[arrowhead=vee, arrowsize=.7]\n", " I [label=\"\", style=invis, width=0]\n", " I -> 1\n", " 0 [label=\"0\", peripheries=2]\n", " 0 -> 0 [label=<1>]\n", " 1 [label=\"1\"]\n", " 1 -> 0 [label=]\n", " 1 -> 1 [label=]\n", "}\n", "\n", "2 1\n", "0 1 -1\n", "1 \"b\"\n", "0 & \"a\" ! \"b\"\n", "-1\n", "1 0 0 -1\n", "1 t\n", "-1\n", "\n" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "a.save('example.aut').save('example.aut', format='lbtt', append=True)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 3, "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "I->1\n", "\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "a & !b\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "1->0\n", "\n", "\n", "b\n", "\n", "\n", "0->0\n", "\n", "\n", "1\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7f4d702fb090> >" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "!cat example.aut" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "HOA: v1\r\n", "States: 2\r\n", "Start: 1\r\n", "AP: 2 \"a\" \"b\"\r\n", "acc-name: Buchi\r\n", "Acceptance: 1 Inf(0)\r\n", "properties: trans-labels explicit-labels state-acc deterministic\r\n", "properties: stutter-invariant inherently-weak\r\n", "--BODY--\r\n", "State: 0 {0}\r\n", "[t] 0\r\n", "State: 1\r\n", "[1] 0\r\n", "[0&!1] 1\r\n", "--END--\r\n", "2 1\r\n", "0 1 -1\r\n", "1 \"b\"\r\n", "0 & \"a\" ! \"b\"\r\n", "-1\r\n", "1 0 0 -1\r\n", "1 t\r\n", "-1\r\n" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "for a in spot.automata('example.aut'):\n", " display(a)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "display_data", "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "I->1\n", "\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "a & !b\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "1->0\n", "\n", "\n", "b\n", "\n", "\n", "0->0\n", "\n", "\n", "1\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7f4d702fb060> >" ] }, { "metadata": {}, "output_type": "display_data", "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "0->0\n", "\n", "\n", "a & !b\n", "\n", "\n", "1\n", "\n", "\n", "1\n", "\n", "\n", "0->1\n", "\n", "\n", "b\n", "\n", "\n", "1->1\n", "\n", "\n", "1\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7f4d702fb0f0> >" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Test `--ABORT--`\n", "----------------" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%file example.aut\n", "HOA: v1\n", "States: 2\n", "Start: 1\n", "AP: 2 \"a\" \"b\"\n", "acc-name: Buchi\n", "Acceptance: 1 Inf(0)\n", "--BODY--\n", "State: 0 {0}\n", "[t] 0\n", "--ABORT-- /* the previous automaton should be ignored */\n", "HOA: v1\n", "States: 2\n", "Start: 1\n", "AP: 2 \"a\" \"b\"\n", "Acceptance: 1 Inf(0)\n", "--BODY--\n", "State: 0 {0}\n", "[t] 0\n", "State: 1\n", "[1] 0\n", "[0&!1] 1\n", "--END--" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Overwriting example.aut\n" ] } ], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "for a in spot.automata('example.aut'):\n", " display(a)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "display_data", "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "I->1\n", "\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "a & !b\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "1->0\n", "\n", "\n", "b\n", "\n", "\n", "0->0\n", "\n", "\n", "1\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7f4d702fb180> >" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "for a in spot.automata(\"\"\"\n", "HOA: v1\n", "States: 2\n", "Start: 1\n", "name: \"Hello world\"\n", "AP: 2 \"a\" \"b\"\n", "Acceptance: 1 Inf(0)\n", "--BODY--\n", "State: 0 {0}\n", "[t] 0\n", "State: 1\n", "[1] 0\n", "[0&!1] 1\n", "--END--\n", "HOA: v1\n", "States: 1\n", "Start: 0\n", "name: \"Hello world 2\"\n", "AP: 2 \"a\" \"b\"\n", "Acceptance: 2 Inf(0)&Inf(1)\n", "--BODY--\n", "State: 0 {0}\n", "[t] 0 {1}\n", "[0&!1] 0\n", "--END--\n", "\"\"\"):\n", " display(a)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "display_data", "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "I->1\n", "\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "a & !b\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "1->0\n", "\n", "\n", "b\n", "\n", "\n", "0->0\n", "\n", "\n", "1\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7f4d702e67b0> >" ] }, { "metadata": {}, "output_type": "display_data", "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "0->0\n", "\n", "\n", "1\n", "\u24ff\n", "\u2776\n", "\n", "\n", "0->0\n", "\n", "\n", "a & !b\n", "\u24ff\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7f4d702e6720> >" ] } ], "prompt_number": 8 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Test syntax errors\n", "------------------" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%file example.aut\n", "HOA: v1\n", "States: 2\n", "Start: 1\n", "AP: 2 \"a\" \"b\"\n", "acc-name: Buchi\n", "Acceptance: 1 Inf(0)\n", "--BODY--\n", "State: 0 {0}\n", "[t] 1\n", "State: 1\n", "[t] 1\n", "--END--\n", "HOA: v1\n", "States: 2\n", "Start: 1\n", "AP: 2 \"a\" \"b\"\n", "Acceptance: 1 Inf(0)\n", "--BODY--\n", "State: 0 {0}\n", "[a] 3\n", "State: 1\n", "[1] 0\n", "[0&!1] 1\n", "--END--" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Overwriting example.aut\n" ] } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "for a in spot.automata('example.aut'):\n", " display(a)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "display_data", "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "I->1\n", "\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "1\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "0->1\n", "\n", "\n", "1\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7f4d71fbfc90> >" ] }, { "ename": "SyntaxError", "evalue": "\nexample.aut:20.2: syntax error, unexpected identifier\nexample.aut:20.1-3: ignoring this invalid label\nexample.aut:20.5: state number is larger than state count...\nexample.aut:14.1-9: ... declared here.\n ()", "output_type": "pyerr", "traceback": [ "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32munknown\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m \nexample.aut:20.2: syntax error, unexpected identifier\nexample.aut:20.1-3: ignoring this invalid label\nexample.aut:20.5: state number is larger than state count...\nexample.aut:14.1-9: ... declared here.\n\n" ] } ], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "rm example.aut" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "spot.automaton('example.aut')" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "RuntimeError", "evalue": "Cannot open file example.aut", "output_type": "pyerr", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mspot\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mautomaton\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'example.aut'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;32m/home-ssd/adl/git/spot/wrap/python/spot.py\u001b[0m in \u001b[0;36mautomaton\u001b[1;34m(filename)\u001b[0m\n\u001b[0;32m 216\u001b[0m See `spot.automata()` for a list of supported formats.\"\"\"\n\u001b[0;32m 217\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 218\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mautomata\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 219\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 220\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Failed to read automaton from {}\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m/home-ssd/adl/git/spot/wrap/python/spot.py\u001b[0m in \u001b[0;36mautomata\u001b[1;34m(*filenames)\u001b[0m\n\u001b[0;32m 183\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 184\u001b[0m \u001b[0mproc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 185\u001b[1;33m \u001b[0mp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mautomaton_stream_parser\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 186\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 187\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m/home-ssd/adl/git/spot/wrap/python/spot_impl.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, *args)\u001b[0m\n\u001b[0;32m 2452\u001b[0m \u001b[0m__repr__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_swig_repr\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2453\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2454\u001b[1;33m \u001b[0mthis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_spot_impl\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnew_automaton_stream_parser\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2455\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mthis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mthis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2456\u001b[0m \u001b[1;32mexcept\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mthis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mthis\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mRuntimeError\u001b[0m: Cannot open file example.aut" ] } ], "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [ "spot.automaton('non-existing-cmd |')" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "RuntimeError", "evalue": "Command non-existing-cmd exited with exit status 127", "output_type": "pyerr", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mspot\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mautomaton\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'non-existing-cmd |'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;32m/home-ssd/adl/git/spot/wrap/python/spot.py\u001b[0m in \u001b[0;36mautomaton\u001b[1;34m(filename)\u001b[0m\n\u001b[0;32m 216\u001b[0m See `spot.automata()` for a list of supported formats.\"\"\"\n\u001b[0;32m 217\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 218\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mautomata\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 219\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 220\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Failed to read automaton from {}\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m/home-ssd/adl/git/spot/wrap/python/spot.py\u001b[0m in \u001b[0;36mautomata\u001b[1;34m(*filenames)\u001b[0m\n\u001b[0;32m 208\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mret\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 209\u001b[0m raise RuntimeError(\"Command {} exited with exit status {}\"\n\u001b[1;32m--> 210\u001b[1;33m .format(filename[:-1], ret))\n\u001b[0m\u001b[0;32m 211\u001b[0m \u001b[1;32mreturn\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 212\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mRuntimeError\u001b[0m: Command non-existing-cmd exited with exit status 127" ] } ], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": null } ], "metadata": {} } ] }