Skip to content

Instantly share code, notes, and snippets.

@maedoc
Created November 19, 2019 06:58
Show Gist options
  • Save maedoc/475db2cdabf72fc7779ecfa9b9445005 to your computer and use it in GitHub Desktop.
Save maedoc/475db2cdabf72fc7779ecfa9b9445005 to your computer and use it in GitHub Desktop.
Trace a TVB simulation to produce pretty call graph
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
from pycallgraph import GlobbingFilter
from pycallgraph import Config
from tvb.simulator.models.wong_wang import ReducedWongWang
from tvb.simulator.lab import *
import numpy
rww = ReducedWongWang(a=numpy.array([0.27]), w=numpy.array([1.0]), I_o=numpy.array([0.3]))
sim = simulator.Simulator(
model=rww,
connectivity=connectivity.Connectivity(
weights=numpy.random.randn(256, 256),
tract_lengths=numpy.zeros((256, 256)),
region_labels=numpy.array([str(i) for i in range(256)]),
centres=numpy.zeros((256, 3))),
coupling=coupling.Linear(a=numpy.array([0.5 / 50.0])),
integrator=integrators.EulerStochastic(dt=1, noise=noise.Additive(nsig=numpy.array([1e-5]))),
monitors=(monitors.TemporalAverage(period=1.),),
simulation_length=5e1
).configure()
(time, data), = sim.run()
graphviz = GraphvizOutput(output_file='trace_binding.png')
config = Config()
config.trace_filter = GlobbingFilter(exclude=[
'pycallgraph.*',
'numpy.*',
'autograd.*'
])
with PyCallGraph(config=config, output=graphviz):
(time, data), = sim.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment