Name | simple-simon JSON |
Version |
0.0.6
JSON |
| download |
home_page | |
Summary | A simple simulation monitor |
upload_time | 2023-05-13 15:24:38 |
maintainer | |
docs_url | None |
author | Roie Zemel |
requires_python | >=3.6 |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|

# A simple monitor for simulations and other processes
## Overview
This project provides a simple tool for tracking simulations and
other numeric processes. It provides a Monitor class that has
all the following functionality:
- Tracking numeric variables.
- Plotting the data.
- An updating live view of the tracked variables.
- A window of convenience toggles to control the progress
of a long-running simulation.
- Automatically saving all the collected data in a single output directory, including:
- .csv files
- Plots
- A config file with configuration constants
- A summary text file
- Loading an output directory to continue working with a simulation that's been terminated.
## Installation
Install with `pip`:
```commandline
pip install simple-simon
```
## Usage
Here's a quick example of the `Monitor` class used to track a moving object simulation:
```python
from simon import Monitor
# create Monitor - this already opens an output directory and a toggle-buttons control window
mon = Monitor('Example Monitor')
# add a new 'tracker' to track variables
tr = mon.tracker('time', 'velocity')
# set simulation configuration constants
mon.its = 10000 # if declared as mon's attribute, the value will be
mon.dt = 0.1 # added to the config.txt file
mon.a = 1
# helper variables
time = 0
v = 0
# simulate
for i in range(mon.its):
# update tracker: provide time and velocity
tr.update(time, v)
# calculate next time step
time += mon.dt
v += mon.a * mon.dt
# finalize - saves all data and closes necessary processes and windows
mon.finalize()
```
A few notes:
- When creating a Monitor instance, an output directory is automatically created (unless disabled, see tip below).
- Also, a window of toggles opens to give the user some control over the progress of the simulation. One of the toggles
opens the live view of the data.
- Later, a 'tracker' is added to the Monitor to track velocity against time. Each tracker is associated with **one** independent variable,
and multiple dependent variables. When calling `update()` the number of values provided should be equal to the number of variable labels.
- Variables declared as attributes of the Monitor object (like `its` and `dt`) are considered configuration constants. These values will be
added to the config.txt file at the end.
- `finalize()` is an important method that closes all subprocesses that haven't been closed and saves all the data that hasn't been saved.
Tip: For a traceless Monitor with no output directory, use the
QuietMonitor class instead.
### About trackers
Each 'tracker' added to the `Monitor` is provided with a sequence of data labels.
As mentioned, a 'tracker' is associated with one independent variable and multiple dependent variables:
```python
tr = mon.tracker('x', 'y1', 'y2', 'y3') # 'y4', 'y5', ...
```
By default, the `update()` method of a tracker does not save the data into the output file.
To change that, set `autosave=` to True:
```python
tr = mon.tracker('time', 'force on body', autosave=True)
```
Sometimes, it might be helpful to give each tracker a title. This helps with the neat organization
of the data in the output directory. Trackers with the same title are plotted on the same
figure when `finalize()` is called. To give the tracker a title, set the `title=` keyword argument.
Use the `plot()` method of Monitor to show graphs of
the collected data.
`plot()` receives any number of arguments. Each argument can either be a
title, a tracker object, or an iterable of tracker objects:
```python
tr1 = mon.tracker('x', 'y1', title='Things against x')
tr2 = mon.tracker('x', 'y2', title='Things against x')
tr3 = mon.tracker('time', 'force')
...
# plot everything at once:
mon.plot('Things against x', tr3, [tr1, tr2, tr3])
```
### About toggles
The 'Toggles' window is opened from the moment a Monitor is created and until `finalize()` is called.
Some toggles are added by default. Custom toggles can be added in a very simple way:
```python
from simon import Monitor
# after this, the toggles window is opened
mon = Monitor('Custom Toggles Example')
# add a toggle button that quits the simulation
quit_toggle = mon.add_toggle(desc='Quit simulation')
...
while not quit_toggle.toggled():
# simulate stuff
...
```
As you can see, new toggles can be added very easily. The `add_toggle()` method
returns a Toggle object, whose `toggled()` method returns True for every toggle made
by the user.
### Loading Monitor data
Finally, another cool feature of the Monitor class, is that all the data stored in
an output directory, can later be loaded into a Monitor object. This way, a simulation
that's been terminated can be resumed, and the data will keep streaming to the same place:
```python
from simon import Monitor
mon = Monitor('Example Monitor')
mon.load_from_dir() # this loads all the data from the 'Example Monitor' output directory
# now all data has been loaded back to the Monitor
print(len(mon.trackers)) # a list of all trackers
mon.plot(mon.trackers[0]) # same data can be plotted
mon.plot('Things against x') # even the same titles
print(mon.dt, mon.its) # config variables are still there
```
## Contributing
Please report any bug you might come across. Contributions and enhancements are very welcome!
Raw data
{
"_id": null,
"home_page": "",
"name": "simple-simon",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Roie Zemel",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/3d/b9/e46f8d479f7de0d8238f3c6c66cd6fe414bd6223b59c693dd0986da4fdd3/simple-simon-0.0.6.tar.gz",
"platform": null,
"description": "\r\n\r\n# A simple monitor for simulations and other processes\r\n\r\n## Overview\r\nThis project provides a simple tool for tracking simulations and \r\nother numeric processes. It provides a Monitor class that has \r\nall the following functionality:\r\n- Tracking numeric variables.\r\n- Plotting the data.\r\n- An updating live view of the tracked variables.\r\n- A window of convenience toggles to control the progress\r\nof a long-running simulation.\r\n- Automatically saving all the collected data in a single output directory, including:\r\n - .csv files\r\n - Plots\r\n - A config file with configuration constants\r\n - A summary text file\r\n- Loading an output directory to continue working with a simulation that's been terminated.\r\n\r\n## Installation\r\nInstall with `pip`:\r\n```commandline\r\npip install simple-simon\r\n```\r\n\r\n## Usage\r\nHere's a quick example of the `Monitor` class used to track a moving object simulation:\r\n\r\n```python\r\nfrom simon import Monitor\r\n\r\n# create Monitor - this already opens an output directory and a toggle-buttons control window\r\nmon = Monitor('Example Monitor')\r\n\r\n# add a new 'tracker' to track variables\r\ntr = mon.tracker('time', 'velocity')\r\n\r\n# set simulation configuration constants\r\nmon.its = 10000 # if declared as mon's attribute, the value will be \r\nmon.dt = 0.1 # added to the config.txt file\r\nmon.a = 1\r\n\r\n# helper variables\r\ntime = 0\r\nv = 0\r\n\r\n# simulate\r\nfor i in range(mon.its):\r\n # update tracker: provide time and velocity\r\n tr.update(time, v)\r\n\r\n # calculate next time step\r\n time += mon.dt\r\n v += mon.a * mon.dt\r\n\r\n# finalize - saves all data and closes necessary processes and windows\r\nmon.finalize()\r\n```\r\nA few notes:\r\n- When creating a Monitor instance, an output directory is automatically created (unless disabled, see tip below).\r\n- Also, a window of toggles opens to give the user some control over the progress of the simulation. One of the toggles \r\nopens the live view of the data.\r\n- Later, a 'tracker' is added to the Monitor to track velocity against time. Each tracker is associated with **one** independent variable, \r\nand multiple dependent variables. When calling `update()` the number of values provided should be equal to the number of variable labels.\r\n- Variables declared as attributes of the Monitor object (like `its` and `dt`) are considered configuration constants. These values will be\r\nadded to the config.txt file at the end.\r\n- `finalize()` is an important method that closes all subprocesses that haven't been closed and saves all the data that hasn't been saved.\r\n\r\nTip: For a traceless Monitor with no output directory, use the \r\nQuietMonitor class instead.\r\n\r\n### About trackers\r\nEach 'tracker' added to the `Monitor` is provided with a sequence of data labels.\r\nAs mentioned, a 'tracker' is associated with one independent variable and multiple dependent variables:\r\n```python\r\ntr = mon.tracker('x', 'y1', 'y2', 'y3') # 'y4', 'y5', ...\r\n```\r\nBy default, the `update()` method of a tracker does not save the data into the output file.\r\nTo change that, set `autosave=` to True:\r\n```python\r\ntr = mon.tracker('time', 'force on body', autosave=True)\r\n```\r\nSometimes, it might be helpful to give each tracker a title. This helps with the neat organization \r\nof the data in the output directory. Trackers with the same title are plotted on the same \r\nfigure when `finalize()` is called. To give the tracker a title, set the `title=` keyword argument.\r\n\r\nUse the `plot()` method of Monitor to show graphs of\r\nthe collected data.\r\n`plot()` receives any number of arguments. Each argument can either be a \r\ntitle, a tracker object, or an iterable of tracker objects:\r\n```python\r\ntr1 = mon.tracker('x', 'y1', title='Things against x')\r\ntr2 = mon.tracker('x', 'y2', title='Things against x')\r\ntr3 = mon.tracker('time', 'force')\r\n\r\n...\r\n\r\n# plot everything at once:\r\nmon.plot('Things against x', tr3, [tr1, tr2, tr3])\r\n```\r\n\r\n### About toggles\r\nThe 'Toggles' window is opened from the moment a Monitor is created and until `finalize()` is called.\r\nSome toggles are added by default. Custom toggles can be added in a very simple way:\r\n\r\n```python\r\nfrom simon import Monitor\r\n\r\n# after this, the toggles window is opened\r\nmon = Monitor('Custom Toggles Example')\r\n\r\n# add a toggle button that quits the simulation\r\nquit_toggle = mon.add_toggle(desc='Quit simulation')\r\n\r\n...\r\n\r\nwhile not quit_toggle.toggled():\r\n# simulate stuff\r\n\r\n...\r\n```\r\n\r\nAs you can see, new toggles can be added very easily. The `add_toggle()` method\r\nreturns a Toggle object, whose `toggled()` method returns True for every toggle made \r\nby the user.\r\n\r\n\r\n### Loading Monitor data\r\nFinally, another cool feature of the Monitor class, is that all the data stored in \r\nan output directory, can later be loaded into a Monitor object. This way, a simulation \r\nthat's been terminated can be resumed, and the data will keep streaming to the same place:\r\n\r\n```python\r\nfrom simon import Monitor\r\n\r\nmon = Monitor('Example Monitor')\r\nmon.load_from_dir() # this loads all the data from the 'Example Monitor' output directory\r\n\r\n# now all data has been loaded back to the Monitor\r\nprint(len(mon.trackers)) # a list of all trackers\r\nmon.plot(mon.trackers[0]) # same data can be plotted\r\nmon.plot('Things against x') # even the same titles\r\nprint(mon.dt, mon.its) # config variables are still there\r\n```\r\n\r\n## Contributing\r\nPlease report any bug you might come across. Contributions and enhancements are very welcome!\r\n",
"bugtrack_url": null,
"license": "",
"summary": "A simple simulation monitor",
"version": "0.0.6",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b43dfad381077d4555b107bcb76e773c7b0cffb78aa47b066060b08951b88aa4",
"md5": "c7a8d985877c4970bf0f18e0f21cacbd",
"sha256": "08144c9861ecd98b8a56e2d0ca8c54f5e592f584639924544e4f904166502377"
},
"downloads": -1,
"filename": "simple_simon-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c7a8d985877c4970bf0f18e0f21cacbd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 12286,
"upload_time": "2023-05-13T15:24:36",
"upload_time_iso_8601": "2023-05-13T15:24:36.483636Z",
"url": "https://files.pythonhosted.org/packages/b4/3d/fad381077d4555b107bcb76e773c7b0cffb78aa47b066060b08951b88aa4/simple_simon-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3db9e46f8d479f7de0d8238f3c6c66cd6fe414bd6223b59c693dd0986da4fdd3",
"md5": "250dff9bf98839de4bde22d796f5bded",
"sha256": "5960e6fc6da47ffc5b56ddc31cd92f2feae6fe1d6c9319d5d7c1d0d683c09ab9"
},
"downloads": -1,
"filename": "simple-simon-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "250dff9bf98839de4bde22d796f5bded",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 14307,
"upload_time": "2023-05-13T15:24:38",
"upload_time_iso_8601": "2023-05-13T15:24:38.610181Z",
"url": "https://files.pythonhosted.org/packages/3d/b9/e46f8d479f7de0d8238f3c6c66cd6fe414bd6223b59c693dd0986da4fdd3/simple-simon-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-13 15:24:38",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "simple-simon"
}