Name | soyutnet JSON |
Version |
0.4.0
JSON |
| download |
home_page | None |
Summary | Place/transition net (petri net) simulator that uses asyncio utilities as backend |
upload_time | 2024-11-11 10:53:21 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | Copyright (c) 2024 Okan Demir Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
discrete-event-systems
petri-net
pt-net
simulator
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# SoyutNet
<img align="left" width="128" height="128" src="https://raw.githubusercontent.com/dmrokan/soyutnet/main/docs/source/_static/soyutnet_logo.png">
SoyutNet is a place/transition net (PT net, Petri net) simulator
that uses Python's asyncio task and synchronization utilities as
backend. (*Soyut means abstract in Turkish.*)
Its documentation can be found at [https://soyutnet.readthedocs.io](https://soyutnet.readthedocs.io)
## Building
```bash
python3 -m venv venv
source venv/bin/activate
pip install -e '.[dev]'
pytest
```
## Installing
```bash
python3 -m venv venv
source venv/bin/activate
pip install soyutnet
```
## An example
This example simulates the PT net given in the diagram below.
![PT net example](https://raw.githubusercontent.com/dmrokan/soyutnet/main/docs/source/_static/images/first_example_T0.png "PT net example")
```python
import sys
import asyncio
import soyutnet
from soyutnet import SoyutNet
from soyutnet.constants import GENERIC_ID, GENERIC_LABEL
def main():
async def scheduled():
await asyncio.sleep(1)
soyutnet.terminate()
with SoyutNet(extra_routines=[scheduled()]) as net:
net.DEBUG_ENABLED = True
LABEL = 1
initial_tokens = {
GENERIC_LABEL: [GENERIC_ID],
LABEL: [1000, 990],
}
o1 = net.Observer(verbose=True)
p1 = net.Place("p1", initial_tokens=initial_tokens, observer=o1)
o2 = net.Observer(verbose=True)
p2 = net.Place("p2", observer=o2)
t1 = net.Transition("t1")
"""Define places and transitions (PTs)"""
_ = net.Arc(labels=(GENERIC_LABEL, LABEL))
p1 >> _ >> t1 >> _ >> p2
"""Connect PTs"""
records = net.registry.get_merged_records()
graph = net.registry.generate_graph(
indent=" ", label_names={LABEL: "🤔", GENERIC_LABEL: "🤌"}
)
print("\nRecorded events:")
{net.print(rec) for rec in records}
print("\nNet graph:")
print(graph, file=sys.stderr)
return records, graph
if __name__ == "__main__":
main()
```
outputs:
```
$ python tests/behavior/readme_example.py
loop(t1, 3): REC: O{(p1, 1)}: (112199.881220, ((0, 1, ), (1, 2, ), ), t1, )
loop(t1, 3): REC: O{(p1, 1)}: (112199.881402, ((0, 0, ), (1, 2, ), ), t1, )
loop(t1, 3): REC: O{(p1, 1)}: (112199.881550, ((0, 0, ), (1, 1, ), ), t1, )
Recorded events:
(p1, (112199.881220, ((0, 1, ), (1, 2, ), ), t1, ), )
(p1, (112199.881402, ((0, 0, ), (1, 2, ), ), t1, ), )
(p1, (112199.881550, ((0, 0, ), (1, 1, ), ), t1, ), )
Net graph:
digraph Net {
subgraph cluster_0 {
p1_0 [shape="circle",fontsize="20",style="filled",color="#000000",fillcolor="#dddddd",label="",xlabel="p1",height="1",width="1",penwidth=3];
p2_0 [shape="circle",fontsize="20",style="filled",color="#000000",fillcolor="#dddddd",label="",xlabel="p2",height="1",width="1",penwidth=3];
t1_0 [shape="box",fontsize="20",style="filled",color="#cccccc",fillcolor="#000000",label="",xlabel="t1",height="0.25",width="1.25",penwidth=3];
t1_0 -> p2_0 [fontsize="20",label="{🤌,🤔}",minlen="2",penwidth="3"];
p1_0 -> t1_0 [fontsize="20",label="{🤌,🤔}",minlen="2",penwidth="3"];
}
clusterrank=none;
}
```
**How to interpret events**
```
('p1', (188597.931257369, ((0, 1), (1, 2)), 't1'))
A list of place markings that show token counts for each label recorded just before a transition is fired:
[('<name of the place>', (<event timestamp in seconds>, ((<token label>, <token count>),), '<firing transition>')), ...]
```
**How to generate the graph**
```bash
sudo apt install graphviz # Which provides 'dot'
python tests/behavior/readme_example.py 2>&1 > /dev/null | dot -Tpng > readme_example.png
```
Outputs:
![PT net graph](https://raw.githubusercontent.com/dmrokan/soyutnet/main/docs/source/_static/images/first_example.png "PT net graph")
## [Credits](https://github.com/dmrokan/soyutnet/blob/main/docs/source/credits.rst)
Raw data
{
"_id": null,
"home_page": null,
"name": "soyutnet",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "Okan Demir <okndemir@gmail.com>",
"keywords": "discrete-event-systems, petri-net, pt-net, simulator",
"author": null,
"author_email": "Okan Demir <okndemir@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/3a/97/0d3d03eff669140b2b675d521ed1bc46dc0cdc120b082ac3245efcece152/soyutnet-0.4.0.tar.gz",
"platform": null,
"description": "# SoyutNet\n\n<img align=\"left\" width=\"128\" height=\"128\" src=\"https://raw.githubusercontent.com/dmrokan/soyutnet/main/docs/source/_static/soyutnet_logo.png\">\n\nSoyutNet is a place/transition net (PT net, Petri net) simulator\nthat uses Python's asyncio task and synchronization utilities as\nbackend. (*Soyut means abstract in Turkish.*)\n\nIts documentation can be found at [https://soyutnet.readthedocs.io](https://soyutnet.readthedocs.io)\n\n## Building\n\n```bash\npython3 -m venv venv\nsource venv/bin/activate\npip install -e '.[dev]'\npytest\n```\n\n## Installing\n\n```bash\npython3 -m venv venv\nsource venv/bin/activate\npip install soyutnet\n```\n\n## An example\n\nThis example simulates the PT net given in the diagram below.\n\n![PT net example](https://raw.githubusercontent.com/dmrokan/soyutnet/main/docs/source/_static/images/first_example_T0.png \"PT net example\")\n\n```python\nimport sys\nimport asyncio\n\nimport soyutnet\nfrom soyutnet import SoyutNet\nfrom soyutnet.constants import GENERIC_ID, GENERIC_LABEL\n\n\ndef main():\n async def scheduled():\n await asyncio.sleep(1)\n soyutnet.terminate()\n\n with SoyutNet(extra_routines=[scheduled()]) as net:\n net.DEBUG_ENABLED = True\n\n LABEL = 1\n initial_tokens = {\n GENERIC_LABEL: [GENERIC_ID],\n LABEL: [1000, 990],\n }\n o1 = net.Observer(verbose=True)\n p1 = net.Place(\"p1\", initial_tokens=initial_tokens, observer=o1)\n o2 = net.Observer(verbose=True)\n p2 = net.Place(\"p2\", observer=o2)\n t1 = net.Transition(\"t1\")\n \"\"\"Define places and transitions (PTs)\"\"\"\n\n _ = net.Arc(labels=(GENERIC_LABEL, LABEL))\n p1 >> _ >> t1 >> _ >> p2\n \"\"\"Connect PTs\"\"\"\n\n records = net.registry.get_merged_records()\n graph = net.registry.generate_graph(\n indent=\" \", label_names={LABEL: \"\ud83e\udd14\", GENERIC_LABEL: \"\ud83e\udd0c\"}\n )\n\n print(\"\\nRecorded events:\")\n {net.print(rec) for rec in records}\n print(\"\\nNet graph:\")\n print(graph, file=sys.stderr)\n\n return records, graph\n\n\nif __name__ == \"__main__\":\n main()\n```\n\noutputs:\n\n```\n$ python tests/behavior/readme_example.py\n\nloop(t1, 3): REC: O{(p1, 1)}: (112199.881220, ((0, 1, ), (1, 2, ), ), t1, )\nloop(t1, 3): REC: O{(p1, 1)}: (112199.881402, ((0, 0, ), (1, 2, ), ), t1, )\nloop(t1, 3): REC: O{(p1, 1)}: (112199.881550, ((0, 0, ), (1, 1, ), ), t1, )\n\nRecorded events:\n(p1, (112199.881220, ((0, 1, ), (1, 2, ), ), t1, ), )\n(p1, (112199.881402, ((0, 0, ), (1, 2, ), ), t1, ), )\n(p1, (112199.881550, ((0, 0, ), (1, 1, ), ), t1, ), )\n\nNet graph:\ndigraph Net {\n subgraph cluster_0 {\n p1_0 [shape=\"circle\",fontsize=\"20\",style=\"filled\",color=\"#000000\",fillcolor=\"#dddddd\",label=\"\",xlabel=\"p1\",height=\"1\",width=\"1\",penwidth=3];\n p2_0 [shape=\"circle\",fontsize=\"20\",style=\"filled\",color=\"#000000\",fillcolor=\"#dddddd\",label=\"\",xlabel=\"p2\",height=\"1\",width=\"1\",penwidth=3];\n t1_0 [shape=\"box\",fontsize=\"20\",style=\"filled\",color=\"#cccccc\",fillcolor=\"#000000\",label=\"\",xlabel=\"t1\",height=\"0.25\",width=\"1.25\",penwidth=3];\n t1_0 -> p2_0 [fontsize=\"20\",label=\"{\ud83e\udd0c,\ud83e\udd14}\",minlen=\"2\",penwidth=\"3\"];\n p1_0 -> t1_0 [fontsize=\"20\",label=\"{\ud83e\udd0c,\ud83e\udd14}\",minlen=\"2\",penwidth=\"3\"];\n }\n clusterrank=none;\n}\n```\n\n**How to interpret events**\n\n```\n('p1', (188597.931257369, ((0, 1), (1, 2)), 't1'))\n\nA list of place markings that show token counts for each label recorded just before a transition is fired:\n[('<name of the place>', (<event timestamp in seconds>, ((<token label>, <token count>),), '<firing transition>')), ...]\n```\n\n**How to generate the graph**\n\n```bash\nsudo apt install graphviz # Which provides 'dot'\npython tests/behavior/readme_example.py 2>&1 > /dev/null | dot -Tpng > readme_example.png\n```\n\nOutputs:\n\n![PT net graph](https://raw.githubusercontent.com/dmrokan/soyutnet/main/docs/source/_static/images/first_example.png \"PT net graph\")\n\n## [Credits](https://github.com/dmrokan/soyutnet/blob/main/docs/source/credits.rst)\n",
"bugtrack_url": null,
"license": "Copyright (c) 2024 Okan Demir Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Place/transition net (petri net) simulator that uses asyncio utilities as backend",
"version": "0.4.0",
"project_urls": {
"Bug Tracker": "https://github.com/dmrokan/soyutnet/issues",
"Changelog": "https://github.com/dmrokan/soyutnet/blob/main/CHANGELOG.md",
"Documentation": "https://github.com/dmrokan/soyutnet",
"Homepage": "https://github.com/dmrokan/soyutnet",
"Repository": "https://github.com/dmrokan/soyutnet"
},
"split_keywords": [
"discrete-event-systems",
" petri-net",
" pt-net",
" simulator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6b958489e3f6118c90a33d8baf9760846cc238fd1a7fa418db6c3cb96de55bcd",
"md5": "8ea717b274f49a305cdfc448ce022a9f",
"sha256": "5933b87dcd24bd337fd5ac457f8c902b9637245372851136571dcb81175b2cfa"
},
"downloads": -1,
"filename": "soyutnet-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8ea717b274f49a305cdfc448ce022a9f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 22968,
"upload_time": "2024-11-11T10:53:19",
"upload_time_iso_8601": "2024-11-11T10:53:19.596301Z",
"url": "https://files.pythonhosted.org/packages/6b/95/8489e3f6118c90a33d8baf9760846cc238fd1a7fa418db6c3cb96de55bcd/soyutnet-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3a970d3d03eff669140b2b675d521ed1bc46dc0cdc120b082ac3245efcece152",
"md5": "55f92fbf3c7826c4145aeae4b0b27ebb",
"sha256": "8060e4a1af09121db0b056fd324ec7a036a8a6e1439bc2efd42f253f4b03a7c6"
},
"downloads": -1,
"filename": "soyutnet-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "55f92fbf3c7826c4145aeae4b0b27ebb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 472797,
"upload_time": "2024-11-11T10:53:21",
"upload_time_iso_8601": "2024-11-11T10:53:21.990968Z",
"url": "https://files.pythonhosted.org/packages/3a/97/0d3d03eff669140b2b675d521ed1bc46dc0cdc120b082ac3245efcece152/soyutnet-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-11 10:53:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dmrokan",
"github_project": "soyutnet",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "soyutnet"
}