Running Simulations
You can run simulations using a configuration file with the polygraphs
command. PolyGraphs requires a YAML file which specifies the parameters of a simulation. Create a file called test.yaml
and paste in the following:
# Initial beliefs are random uniform between 0 and 1
init.kind: "uniform"
# Chance that action B is better than action A
epsilon: 0.01
# Kind and size of network (a complete network with 10 agents)
network.kind: "complete"
network.size: 16
# Enable logging; print progress every 100 steps
logging.enabled: True
logging.interval: 100
# Enable snapshots; take one every 100 steps
snapshots.enabled: True
snapshots.interval: 100
# Run 1,000 steps per simulation; repeat simulation 10 times
simulation.steps: 1000
simulation.repeats: 5
# Set seed
seed: 123456789
# Set model
op: "BalaGoyalOp"
Navigate to the location of the test.yaml
file in your terminal and run the polygraphs
command:
polygraphs -f test.yaml
This will output some logs from the simulations telling us how many steps each simulation took and the ratio of beliefs between A
and B
believers in the network. The example below shows five simulations that took between 49 and 107 steps to complete:
[MON] step 0001 Ksteps/s 0.00 A/B 0.56/0.44
[MON] step 0049 Ksteps/s 0.77 A/B 0.00/1.00
INFO polygraphs> Sim #0001: 49 steps 0.07s; action: B undefined: 0 converged: 1 polarized: 0
[MON] step 0001 Ksteps/s 0.00 A/B 0.56/0.44
[MON] step 0073 Ksteps/s 0.76 A/B 0.00/1.00
INFO polygraphs> Sim #0002: 73 steps 0.10s; action: B undefined: 0 converged: 1 polarized: 0
[MON] step 0001 Ksteps/s 0.00 A/B 0.56/0.44
[MON] step 0100 Ksteps/s 0.78 A/B 0.00/1.00
[MON] step 0107 Ksteps/s 0.78 A/B 0.00/1.00
INFO polygraphs> Sim #0003: 107 steps 0.14s; action: B undefined: 0 converged: 1 polarized: 0
[MON] step 0001 Ksteps/s 0.00 A/B 0.44/0.56
[MON] step 0064 Ksteps/s 0.79 A/B 0.00/1.00
INFO polygraphs> Sim #0004: 64 steps 0.08s; action: B undefined: 0 converged: 1 polarized: 0
[MON] step 0001 Ksteps/s 0.00 A/B 0.62/0.38
[MON] step 0093 Ksteps/s 0.81 A/B 0.00/1.00
INFO polygraphs> Sim #0005: 93 steps 0.11s; action: B undefined: 0 converged: 1 polarized: 0
Bye.
Configuration File
The test.yaml
asked PolyGraphs to create a complete network with 16 nodes using network.kind
and network.size
. The epsilon
, or the chances of B being better than A is set at 0.01. Our nodes start with a random set of beliefs that are drawn from a uniform distribution using init.kind
which is initially created with a random seed
of 123456789.
The configuration asks PolyGraphs to print out the beliefs to the screen every 100 steps using logging.interval
and save a snapshot of all node beliefs every 100 steps using snapshots.interval
. PolyGraphs will use the BalaGoyalOp
operation and run five different simulations simulation.repeats
for a maximum of 1000 steps in each simulation simulation.steps
, unless the network converges earlier on a belief.
Results
PolyGraphs stores the results from simulations inside the polygraphs-cache
directory which it creates by default inside your home directory. The cache directory has the following structure: ~/polygraphs-cache/results/<date>/<unique id>/
.
TIP
You can change the location of the polygraphs-cache
directory by setting a POLYGRAPHS_CACHE
environment variable on your operating system pointing to a new location
Simulation results are stored in a directory called results
containing further sub-directories for each date and a unique id for each batch of simulations.
1.bin 1.hd5
2.bin 2.hd5
3.bin 3.hd5
4.bin 4.hd5
5.bin 5.hd5
configuration.json data.csv
Inside a folder with results you will find .bin
files numbered by simulation containing the initial beliefs and the network graph. You will also find a .hd5
file for each simulation which contains the snapshot of beliefs from subsequent iterations of the simulation at a rate that was set in the snapshot.interval
parameter of the configuration. The configuration.json
file contains the configuration and the data.csv
file contains an overview of information about the simulations.
WARNING
You should not change the name of a folder with a simulation from its unique id or make changes to the files inside the folder as the next step of processing simulation results looks for the specific folder structure generated by the run.py
script in the ~/polygraphs-cache
directory.
Batch Jobs
Batch jobs can be generated for the Slurm workload manager using the job-array-generator script.
Next Steps
- Process the results from simulations for analysis