{
"metadata": {
"name": "",
"signature": "sha256:5cb288dca975d2e3b9a45bf32740468542c11fbd89d5a3df2155fe7e53ce9834"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This first chunk just makes sure the version of DiVinE installed accepts the `--LTSmin` option. If that is not the case, this notebook should be skipped by the test suite: `sys.exit(77)` does that."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import sys\n",
"# Make sure we have divine and that it is patched to accept the --LTSmin option.\n",
"import shutil\n",
"if shutil.which(\"divine\") == None:\n",
" sys.exit(77)\n",
"import subprocess\n",
"out = subprocess.check_output(['divine', 'compile', '--help'], stderr=subprocess.STDOUT)\n",
"if b'LTSmin' not in out:\n",
" sys.exit(77)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The real test case starts here."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import spot\n",
"import spot.ltsmin\n",
"# This is notebook also tests the limitation of the number of states in the GraphViz output\n",
"spot.setup(max_states=10)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write an example DiVinE model. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%file test1.dve\n",
"int a = 0, b = 0;\n",
"\n",
"process P {\n",
" state x;\n",
" init x;\n",
"\n",
" trans\n",
" x -> x { guard a < 3 && b < 3; effect a = a + 1; },\n",
" x -> x { guard a < 3 && b < 3; effect b = b + 1; };\n",
"}\n",
"\n",
"process Q {\n",
" state wait, work;\n",
" init wait;\n",
" trans\n",
" wait -> work { guard b > 1; },\n",
" work -> wait { guard a > 1; };\n",
"}\n",
"\n",
"system async;"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Overwriting test1.dve\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compile the model using the `ltlmin` interface and load it. This should work with DiVinE models if `divine --LTSmin` works, and with Promela models if `spins` is installed.\n",
"\n",
"Printing an ltsmin model shows some information about the variables it contains and their types."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"m = spot.ltsmin.load('test1.dve')\n",
"m"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": [
"ltsmin model with the following variables:\n",
" a: int\n",
" b: int\n",
" P: ['x']\n",
" Q: ['wait', 'work']"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"sorted(m.info().items())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"[('state_size', 4),\n",
" ('types', [('int', []), ('P', ['x']), ('Q', ['wait', 'work'])]),\n",
" ('variables', [('a', 0), ('b', 0), ('P', 1), ('Q', 2)])]"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"k = m.kripke([\"a<1\", \"b>2\"])\n",
"k"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"svg": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text": [
" *' at 0x7f7f00239600> >"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"k.show('.<15')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"svg": [
""
],
"text": [
""
]
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"k.show('.<0') # unlimited output"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"svg": [
""
],
"text": [
""
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"a = spot.translate('\"a<1\" U \"b>2\"'); a"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"svg": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text": [
" *' at 0x7f7f00198690> >"
]
}
],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"spot.otf_product(k, a)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 10,
"svg": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text": [
" *' at 0x7f7f00239cc0> >"
]
}
],
"prompt_number": 10
}
],
"metadata": {}
}
]
}