NetworkDynamics.jl -- Composing and simulating complex networks in Julia

Michael Lindner, Lucas Lincoln, Fenja Drauschke, Julia Monika Koulen, Hans Würfel, Anton Plietzsch, Frank HellmannarXiv 2020 · DOI

TL;DR

NetworkDynamics.jl is an open-source Julia package designed for the high-performance simulation of heterogeneous dynamical systems on complex networks. By leveraging Julia’s just-in-time (JIT) compilation and the robust DifferentialEquations.jl ecosystem, it allows researchers to compose complex models—including those with algebraic constraints, time delays, and stochasticity—using a high-level syntax that matches the performance of hand-optimized low-level code.

What Problem Does This Paper Address?

Simulating large-scale complex networks, such as power grids, neural circuits, or epidemic spreading models, presents a significant engineering challenge. Researchers typically face the "two-language problem": they prototype in high-level scripting languages like Python for ease of use, but must rewrite performance-critical sections in C, C++, or Fortran to handle systems with thousands of dimensions and long integration times.

Furthermore, existing tools often struggle with heterogeneity. In a real-world power grid, different nodes (generators vs. consumers) and different lines (transmission vs. distribution) follow different physical laws. Managing this variety while maintaining computational efficiency—especially when adding advanced features like time-delays or event-driven changes (e.g., a line failing)—is notoriously difficult.

Methods

The authors introduce a graph abstraction model where the network is viewed as a collection of nodes and edges. Crucially, edges are not just connections; they can have their own internal states and dynamics.

Figure 1. A diagram showing the relationship between the graph abstraction model used by NetworkDynamics.jl, a traditional mathematical graph, and the underlying equations. Ni denotes the set of variables of neighbors of node i. Nodes are connected to arbitrarily many edges, while each edge is connected to exactly two nodes. The equations are given for node dynamics described by ODEs coupled via algebraic interactions. Many modifications of this basic setup are possible.

Key technical features include:

  • Component Types: The package provides specialized wrappers like ODEVertex, StaticEdge, and DDEVertex. This allows the user to mix and match different types of dynamics (e.g., coupling an ODE-based generator with a static algebraic load).
  • Zero-Cost Abstraction: The package uses Julia’s multiple dispatch and custom data structures (caches and views) to construct an optimized, allocation-free function for the solver. This ensures that the high-level "network" description doesn't introduce overhead compared to a flat, hand-coded system of equations.
  • Ecosystem Integration: Because it is built in Julia, it natively supports DifferentialEquations.jl solvers, LightGraphs.jl for topology, and DiffEqFlux.jl for training neural networks as components within the physical system (Universal Differential Equations).

Datasets

As a software-focused paper, the "datasets" consist of paradigmatic benchmark models used for performance evaluation:

  • Kuramoto Oscillators: A standard model for synchronization dynamics. The authors use this to compare NetworkDynamics.jl against pure Julia, Python (SciPy and JiTCODE), and Fortran.
  • Watts-Strogatz Networks: Used to generate the underlying topologies for the benchmarks, ranging from 10 to 1,000 nodes to test scalability.

Key Insights and Ideas

  • Solving the Two-Language Problem: The paper demonstrates that Julia allows for a single-language workflow that is both user-friendly for researchers and fast enough for production-grade simulations.
  • The Power of Composability: A standout feature is the ability to easily introduce complex behaviors. For example, adding a time delay to an edge or a "failure" event to a node requires only a few lines of code, whereas in traditional compiled frameworks, this might require a complete rewrite of the core integration loop.
  • Heterogeneity as a First-Class Citizen: By treating every node and edge as a potentially unique object, the package naturally handles the "messiness" of real-world infrastructure models (see Figure 3 for a system with mixed node types).
Simulation of a heterogeneous system where different nodes follow different dynamical laws.

Key Results

The authors conducted extensive benchmarks comparing execution time across different languages and libraries:

  • Speedup vs. Python: NetworkDynamics.jl outperformed the popular JiTCODE library by a factor of 2x to 4x. Compared to pure interpreted SciPy, the speedup was massive, ranging from 100x to 10,000x for large systems.
  • Comparison to Fortran: The Julia implementation was consistently faster than the Fortran version for the moderately sized systems tested, likely due to more efficient handling of sparse data structures and anti-symmetry in coupling functions.
  • Abstraction Efficiency: The benchmarks showed that using the package's high-level abstractions was just as fast as writing hand-optimized sparse matrix multiplication in pure Julia.
Phase dynamics of Kuramoto oscillators simulated using the package.

Limitations and Future Work

  • Startup Time: The primary drawback noted is Julia's "time to first plot" or startup latency. Initializing the runtime and JIT-compiling the solvers for the first run can take significantly longer than the execution of a small simulation itself. However, this cost is amortized over long runs or repeated experiments.
  • Future Directions: The authors plan to integrate more deeply with ModelingToolkit.jl for symbolic network specification. They also aim to add support for heterogeneous time-delays (where different edges have different lag times) and automatic derivation of Jacobian-Vector products to speed up implicit solvers for very large, stiff systems.

Summary updated

BibTeX
@misc{lindner2020networkdynamics,
  author = {Michael Lindner and Lucas Lincoln and Fenja Drauschke and Julia Monika Koulen and Hans Würfel and Anton Plietzsch and Frank Hellmann},
  title = {{NetworkDynamics.jl -- Composing and simulating complex networks in Julia}},
  year = {2020},
  eprint = {2012.12696},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.12696},
}
Figure