Native GPU-Accelerated Simulation and Estimation of Network Models

A self-contained native engine (a C interface over 'CUDA' kernels and C++ host logic) for stochastic actor-oriented models (the model family of 'RSiena'), exponential random graph models (cross-sectional, temporal, and separable temporal), and models for binary actor attributes, callable from R without a Python runtime. Modelled on the 'torch' package: the CRAN build is CPU-only from source; the GPU path is compiled from source when a 'CUDA' toolkit is detected at configure time. The data preparation, host statistics ('RSiena' Appendix B conventions), and moment targets are validated bit-for-bit against the reference implementation and reproduce 'RSiena' targets on public datasets to machine precision; the estimators match 'RSiena', 'ergm', 'btergm', and 'tergm' on public benchmark models.


cusna (native) — GPU-accelerated SAOM/RSiena, ERGM, and friends for R

cusna is a self-contained native engine — a C ABI over CUDA kernels and C++ host logic (libcusna) — callable from R without a Python runtime. It is the native counterpart of the reticulate-based cusna R wrapper, modelled on the R torch package:

  • the CRAN build is CPU-only from source (pure C++, needs only a C++17 compiler);
  • the GPU path is compiled from source when a CUDA 12.x toolkit (nvcc) is detected at configure time.

cusna_has_cuda() reports which build you have.

What the package provides

Family Functions Validated against
SAOM (RSiena) saom_data(), cusna_effect(), mom_estimate(), cusna_fit methods; behavior co-evolution, composition change, mom_estimate_multinet(), cusna_fran() data/masks/targets bit-identical to the reference; estimates within simulation SE; RSiena targets to machine zero
ERGM ergm_simulate() (TNT sampler), ergm_stats(), ergm_mple(), ergm_mcmle() sampler ≡ ergm::simulate; MLE matches ergm::ergm()
Temporal ERGM tergm_mple() (+ block bootstrap), tergm_simulate(), stergm_cmle() matches btergm to machine precision; tergm CMLE within SE
ALAAM alaam_mple(), alaam_mcmle(), alaam_simulate() MPLE ≡ glm; MLE recovers observed moments
Low-level cusna_network_stats(), cusna_behavior_stats(), cusna_gof_distribution() RSiena Appendix B conventions, machine zero

The underlying C ABI is bit-for-bit validated in native/test (see native/VALIDATION.md).

Reviewer quickstart (CPU-only, no GPU needed)

# from a checkout of the monorepo (configure vendors ../../native sources):
install.packages("cpp11")            # build-time only
# then, with a C++17 toolchain (Rtools on Windows):
#   R CMD INSTALL Rpkg-native
library(cusna)
cusna_has_cuda()                     # FALSE on the CPU-only build

# a two-wave panel and a Method-of-Moments SAOM fit, all native:
set.seed(7)
w1 <- matrix(as.integer(runif(400) < 0.12), 20, 20); diag(w1) <- 0L
w2 <- w1; flip <- sample(400, 40); w2[flip] <- 1L - w2[flip]; diag(w2) <- 0L
fit <- mom_estimate(saom_data(list(w1, w2)),
                    effects = list(cusna_effect("density"), cusna_effect("recip")))
summary(fit)

# an ERGM maximum-likelihood fit on the same data:
ergm_mcmle(w1, list(ergm_term("edges"), ergm_term("mutual")), directed = TRUE)

See vignette("cusna") for the full tour (covariates, co-evolution, multi-network models, TERGM/STERGM/ALAAM) and vignette("siena07-backend") for driving RSiena's siena07() on the native simulator.

Building

See BUILD.md. In short: the CPU-only build needs a C++17 compiler (Rtools on Windows); the GPU build additionally needs a CUDA 12.x toolkit. The native sources are vendored from ../../native/ by configure.

License

MIT (see LICENSE). We compare outputs against RSiena but do not link its code.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("cusna")

0.1.0 by Artem Maltsev, 3 months ago


https://github.com/artemmaltsev74-techcom/cusna


Report a bug at https://github.com/artemmaltsev74-techcom/cusna/issues


Browse source code at https://github.com/cran/cusna


Authors: Artem Maltsev [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports stats, utils

Suggests testthat, jsonlite, litedown, RSiena

Linking to cpp11

System requirements: C++17; optionally a CUDA 12.x toolkit (nvcc) for the GPU path


See at CRAN