Sibilla Python - quasylab/sibilla GitHub Wiki

Sibilla provides a Python front end that permits interacting with Sibilla back end from Python programs. The use of this front end permits using many of the available Python libraries likes, for instance, Matplotlib that simplifies data visualisation. Moreover, Sibilla can be used within a web-based IDE such as Jupyter notebook/lab and in Google Colaboratory.

Start Sibilla Python on Google Colaboratory

The Python front end can be easily used via Google Colaboratory or via Jupyter Notebook. To use Google Colaboratory you don’t need to install anything, you just need any browser. You just need to log in to your Google account and then create a new notebook. In the notebook enter these commands in a new cell and run them to install everything is needed for Sibilla.

!git clone https://github.com/quasylab/sibilla
!cd sibilla && ./gradlew build -x test && ./gradlew installDist
!cp -a sibilla/shell/src/dist/scripts/sibilla_py .
!cd sibilla_py && pip install .

In a second cell enter the next lines of code and run them too.

import os
os.environ["SSHELL_PATH"]="/content/sibilla/shell/build/install/sshell/"
import sibilla

and that’s it, you are ready to use Sibilla. You can try yourself at the following link, which considers a Population Model.

Start Sibilla Python on your Machine

Eventually you can install the Sibilla Python package in your own machine. To do that follow that, after the framework installation, the user should go via CLI into the folder shell/build/install/sshell/scripts/sibilla_py and type:

pip install .

It is important to set the environment variable SSHELL PATH as follows

export SSHELL_PATH=/path/repository/sibilla/shell/build/install/sshell

for *nix Systems,

setx SSHELL_PATH "\path\repository\sibilla\shell\build\install\sshell" /M

for Windows Systems.

Below is a simple example of a python script where the seir model is simulated.

import sibilla

sr = sibilla.SibillaRuntime()
sr.load_module("population")
sr.load_from_file("seir.pm")
sr.set_configuration("initial_2")
sr.add_all_measures()
sr.set_deadline(20)
sr.set_dt(0.5)
sr.set_replica(100)
sim_res = sr.simulate("test")

Use Sibilla Python

In the following table, a detailed list of methods that are provided:

Method Name Description
get_modules() Return an array with the names of all enabled modules.
load_module() Load the module with the given name.
load_from_file(file_name: str) Load a specification from file.
load(code: str) Load a specification from a string.
info() Return info about the module state.
set_parameter(name: str, value: float, keep_configuration : bool = False, silent : bool = True) Set a parameter to a given value. You can also keep the previous configuration by setting keep configuration keep configuration True. If silent is False, it will print the operation, showing the previous parameter and the one just set.
get_parameters() Get the array of current model parameter.
get_evaluation_environment() Return the EvaluationEnvironment of the current model.
clear() Cancels all the data loaded in the module.
reset(name: str = None) Reset all the parameters to their default value. If you specify a name the method will reset to the default value only the specified parameter.
get_initial_configurations() Return the array with the names of the initial configurations available in the current module.
get_configuration_info(name: str) Return a string providing info about the given configuration.
set_configuration(name: str, *args: float) Set initial configuration for simulations and property checking.
get_measures() Return the array of measures defined in the module.
is_enabled_measure(name: str) Return true if a specific measure is enabled.
set_measures(*measures: str) Set the measures to sample in a simulation.
add_measures(*args) Add different measures to the ones collected in simulation.
add_measure(name: str) Add a measure to the ones collected in simulation.
remove_measure(name: str) Remove a measure from the ones collected in simulation.
add_all_measures() Add all the available measures to the ones collected in simulation.
remove_all_measures() Remove all measures from the ones collected from simulation.
simulate(label: str, monitor:SimulationMonitor = None) Run a simulation and save results with the given label.
use_descriptive_statistics() Use descriptive statistics.
use_summary_statistics() Use summary statistics.
is_descriptive_statistics() Return true if a descriptive statistics is used.
is_summary_statistics() Return true if a summary statistics is used.
get_statistics() Return a string that describes the kind of used statistics.
check_dt() Return true if the dt has been set.
set_deadline(deadline: float) Set the deadline.
get_deadline() Return the value of the deadline.
set_dt(dt: float) Set the dt (samples per unit).
get_dt() Return the value of the dt.
get_modes() Return the module modes.
set_mode(name: str) Set module mode.
get_mode() Return the current module mode.
set_seed(seed: int) Set a seed for the random generator.
get_seed() Generate and set a new seed that can be used to replicate experiments.
save( output_folder: str, prefix: str, postfix: str, label: str = None) Save last result to a given folder. Data files, in CSV format, are stored in the given output format. The name of each save file, having extension .csv, consists of the string prefix, the name of the series, and the postfix.
set_replica(replica: int) Set the number of replications.
set_replica() Set the number of simulation replica.
get_replica() Return the number of simulation replica.
print_data(label: str) Return a string with the statistics collected by a labeled stimulation.
get_predicates(self) Returns an array of all the predicates of the model
evaluate_reachability( goal: str, delta:float = 0.01, epsilon:float = 0.01, condition: str = None, monitor:SimulationMonitor=None) Evaluate the probability to reach a certain state

The method simulate() return an instance of the class SibillaSimulationResult, this class simplifies the management of simulation results, in particular it allows plot graphs by invoking the methods plot(show_sd : bool = False) and plot_detailed(). The plot(show_sd : bool = False) will show all the measures in the same graph, if show\_sd is set to True the standard deviation will be shown as a colored area around the single measurements. It is also possible to choose which measurement to display in the graph and zoom in on a specific range using the Range Slider.

The plot_detailed() will show all the measures, one for each graph, with the respective standard deviations and the confidence interval.