Package: simmon
A simple monitor for simulations and other numeric processesOverviewThis 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 filesPlotsA config file with configuration constantsA summary text fileLoading an output directory to continue working with a simulation that's been terminated.Preventing your computer from going into sleep mode (requirespyautoguimodule).InstallationInstall withpip:pip install simmonUsageYou can find the documentation of this projecthere.
Here's a quick example of theMonitorclass used to track a moving object simulation:fromsimmonimportMonitor# create Monitor - this already opens an output directory and a toggle-buttons control windowmon=Monitor('Example Monitor')# add a new 'tracker' to track variablestr=mon.tracker('time','velocity')# set simulation configuration constantsmon.its=10000# if declared as mon's attribute, the value will bemon.dt=0.1# added to the config.txt filemon.a=1# helper variablestime=0v=0# simulateforiinrange(mon.its):# update tracker: provide time and velocitytr.update(time,v)# calculate next time steptime+=mon.dtv+=mon.a*mon.dt# finalize - saves all data and closes necessary processes and windowsmon.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 withoneindependent variable,
and multiple dependent variables. When callingupdate()the number of values provided should be equal to the number of variable labels.Variables declared as attributes of the Monitor object (likeitsanddt) 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 trackersEach 'tracker' added to theMonitoris provided with a sequence of data labels.
As mentioned, a 'tracker' is associated with one independent variable and multiple dependent variables:tr=mon.tracker('x','y1','y2','y3')# 'y4', 'y5', ...By default, theupdate()method of a tracker does not save the data into the output file.
To change that, setautosave=to True: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 whenfinalize()is called. To give the tracker a title, set thetitle=keyword argument.Use theplot()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: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 togglesThe 'Toggles' window is opened from the moment a Monitor is created and untilfinalize()is called.
Some toggles are added by default. Custom toggles can be added in a very simple way:fromsimmonimportMonitor# after this, the toggles window is openedmon=Monitor('Custom Toggles Example')# add a toggle button that quits the simulationquit_toggle=mon.add_toggle(desc='Quit simulation')...whilenotquit_toggle.toggled():# simulate stuff...As you can see, new toggles can be added very easily. Theadd_toggle()method
returns a Toggle object, whosetoggled()method returns True for every toggle made
by the user.Loading Monitor dataFinally, 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:fromsimmonimportMonitormon=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 Monitorprint(len(mon.trackers))# a list of all trackersmon.plot(mon.trackers[0])# same data can be plottedmon.plot('Things against x')# even the same titlesprint(mon.dt,mon.its)# config variables are still thereContributingPlease report any bug you might come across. Contributions and enhancements are very welcome!
Take a look at thedocumentationof this project.