Examples#

Here is a basic usage example to get you started running cubewalkers.

Basic usage#
import cubewalkers as cw

# Define the rules. Various formats are accepted . . .
rules = '''
X,  !X
Y,  X & !Z
Z,  Y'''

# For example, these two versions of `rules` are equivalent.
rules = '''
X* = !X
Y* = X and not Z
Z* = Y'''

# Alternatively, rules can be imported from a text file by converting to a string, e.g.,
# with open('/path/to/rule/file.bnet') as f:
#  rules = f.read()

# Convert the `rules` string into a `cubewalkers` model
model = cw.Model(rules)

# Specify the default number of time steps and walkers (independent simulations)
model.n_time_steps = 25
model.n_walkers = 5

# Simulate the model ensemble (synchronous update is the default)
model.simulate_ensemble()

# The simulation results are stored in `model.trajectories` as a
# `n_time_steps` x `n_variables` x `n_walkers` array of node values at
# each timestep for each node and walker
print(model.trajectories)

# Simulate again, but this time,
# 1) only keep the last 10 time steps
# 2) only track the average values of nodes in the ensemble
# 3) use asynchronous update
# Points 1) and 2) are useful for memory efficiency in large simulations.
model.simulate_ensemble(
T_window = 10,
averages_only = True,
maskfunction = cw.update_schemes.asynchronous)

# The `model.trajectories` variable is overwritten. It now contains
# a `T_window` x `n_variables` array of averaged node values at each timestep
# for each node, averaged across `n_walkers` simulations.
print(model.trajectories)

Additional examples can be found in the notebooks in the Examples and Tutorials folder in the cubewalkers GitHub repository.

Basic Usage.ipynb shows how to run simple simulations and plot the results.

CANA example.ipynb shows how to import and simulate networks from CANA.

InfluenzaTest.ipynb gives a demonstration of quantifying stochastic variations in model trajectories.

Further example usage can be found in our cubewalkers-analysis respository, in which we conduct an in-depth analysis of the Cell Collective.