matrix-bgpsim documentation¶
matrix-bgpsim is a Python project that provides a high-performance BGP routing simulator built on matrix operations. It enables full-scale AS-level route generation across the entire global Internet topology (77k+ ASes) in just a few hours, following the Gao-Rexford simulation model. It supports CPU backend with Python-native multiprocessing, and optionally GPU acceleration via PyTorch and CuPy backends.
Current version: 1.0.2.
CPU multiprocessing¶
Version 1.0.2 fixes CPU worker initialization with the spawn and
forkserver start methods, including the defaults on Windows and macOS,
and on Linux with Python 3.14. See PR #2.
When running a CPU simulation from a Python script, protect the entry point
with if __name__ == "__main__": so worker processes can safely import it:
from matrix_bgpsim import RMatrix
if __name__ == "__main__":
rmatrix = RMatrix("20250101.as-rel2.txt")
rmatrix.run(n_jobs=4, backend="cpu", save_next_hop=True)
print(rmatrix.get_path("7018", "3356"))
API Reference:
- matrix_bgpsim
RMatrixRMatrix.BranchRouteRMatrix.C2PRMatrix.P2CRMatrix.P2PRMatrix.RelMapRMatrix.asn2brts()RMatrix.asn2idx()RMatrix.caida_reader()RMatrix.construct_topology()RMatrix.dump()RMatrix.get_path()RMatrix.get_state()RMatrix.has_asn()RMatrix.idx2asn()RMatrix.idx2ngbrs()RMatrix.is_branch_asn()RMatrix.is_core_asn()RMatrix.load()RMatrix.run()