Experiments: Simulations in parallel#

As simulations involve random processes it is often necessary to inspect multiple simulation runs to ensure one didn’t end up with an outlier. The experiment() function can process any number of simulations in parallel.

Warning

Calling experiment() will start the requested simulations immediately. By default, it will use all available CPUs on your system to do so. Depending on the set-up, this can keep your machine busy for quite some time. You can employ less CPUs by changing the max_workers setting in the executor argument.

taupy.simulation.simulation.experiment(n, *, sim_type=<class 'taupy.simulation.simulation.Simulation'>, executor={}, simulations={}, runs={})[source]#

Generate and execute n number of Simulations and output their results. The Simulations can be controlled via a dictionary passed to simulations. The Simulation.run() can be controlled with a dictionary passed to runs.

Settings to the ProcessPoolExecutor should be forwarded in a dictionary to executor.

This function calls two Executors. The first is responsible for setting up the Simulations in parallel. The second performs the simulation runs. This is particularly helpful for Simulation types that involve substantial computation for set-up, such as FixedDebateSimulation.

# First, create 10 positions with strategy random
positions = [Position(debate=None, introduction_strategy=strategies.random) for _ in range(10)]

# Run 4 simulations in an experiment (multi-threaded!):
my_experiments = experiment(n=4,
                            simulations={"positions": positions,
                                         "sentencepool": "p:10",
                                         "argumentlength": [2,3]},
                            runs={"max_density": 0.8,
                                  "max_steps": 200}
                            )

This creates an object my_experiments with four elements: my_experiments[0] contains the first simulation, the second is in my_experiments[1], etc.

The dictionary in the simulations argument contains the arguments for creation of the Simulation objects. For example, the above call to taupy.experiment() creates simulation object s that look like this:

s = Simulation(positions=positions, sentencepool="p:10", "argumentlength"=[2,3])

And the directives in the dictionary runs are arguments to the method Simulation.run() which is called by the experiments. The settings above are equivalent to:

s.run(max_density=0.8, max_steps=200)