Running 'degree.mean.age.R' [7s]
  Running 'dynamic_EGMME.R' [0s]
  Running 'dynamic_MLE_blockdiag.R' [0s]
  Running 'dynamic_MLE_blockdiag.bipartite.R' [0s]
  Running 'sim_gf_sum.R' [7s]
  Running 'simulate_networkDynamic.R' [169s]
  Running 'tergm_offset_tests.R' [0s]
  Running 'tergm_parallel.R' [130s]
  Running 'testthat.R' [107s]
Running the tests in 'tests/simulate_networkDynamic.R' failed.
Complete output:
  > #  File tests/simulate_networkDynamic.R in package tergm, part of the
  > #  Statnet suite of packages for network analysis, https://statnet.org .
  > #
  > #  This software is distributed under the GPL-3 license.  It is free,
  > #  open source, and has the attribution requirements (GPL Section 7) at
  > #  https://statnet.org/attribution .
  > #
  > #  Copyright 2008-2023 Statnet Commons
  > ################################################################################
  > library(tergm)
  Loading required package: ergm
  Loading required package: network
  
  'network' 1.18.2 (2023-12-04), part of the Statnet Project
  * 'news(package="network")' for changes since last version
  * 'citation("network")' for citation information
  * 'https://statnet.org' for help, support, and other information
  
  
  'ergm' 4.6.0 (2023-12-17), part of the Statnet Project
  * 'news(package="ergm")' for changes since last version
  * 'citation("ergm")' for citation information
  * 'https://statnet.org' for help, support, and other information
  
  'ergm' 4 is a major update that introduces some backwards-incompatible
  changes. Please type 'news(package="ergm")' for a list of major
  changes.
  
  Loading required package: networkDynamic
  
  'networkDynamic' 0.11.4 (2023-12-10?), part of the Statnet Project
  * 'news(package="networkDynamic")' for changes since last version
  * 'citation("networkDynamic")' for citation information
  * 'https://statnet.org' for help, support, and other information
  
  Registered S3 method overwritten by 'tergm':
    method                   from
    simulate_formula.network ergm
  
  'tergm' 4.2.0 (2023-05-30), part of the Statnet Project
  * 'news(package="tergm")' for changes since last version
  * 'citation("tergm")' for citation information
  * 'https://statnet.org' for help, support, and other information
  
  
  Attaching package: 'tergm'
  
  The following object is masked from 'package:ergm':
  
      snctrl
  
  > 
  > set.seed(0)
  > 
  > logit<-function(p)log(p/(1-p))
  > coef.form.f<-function(coef.diss,density) -log(((1+exp(coef.diss))/(density/(1-density)))-1)
  > 
  > # Construct a network with 20 nodes and 20 edges
  > n<-20
  > target.stats<-edges<-20
  > g0<-network.initialize(n,dir=TRUE)
  > g1<-san(g0~edges,target.stats=target.stats,verbose=TRUE)
  Initializing unconstrained Metropolis-Hastings proposal: 'ergm:MH_TNT'.
  Initializing model...
  Model initialized.
  Starting 4 SAN iterations of 524288 steps each.
  #1 of 4: Exact match found.
  SAN Metropolis-Hastings accepted   0.000% of 32768 proposed steps.
  SAN summary statistics:
  edges 
     20 
  Meanstats Goal:
  edges 
     20 
  Difference: SAN target.stats - Goal target.stats =
  edges 
      0 
  New statistics scaling =
  [1] 1
  Scaled Mahalanobis distance = 0
  Target statistics matched exactly.
  > 
  > S<-10
  > 
  > # To get an average duration of 10...
  > duration<-10
  > coef.diss<-logit(1-1/duration)
  > 
  > # To get an average of 20 edges...
  > dyads<-network.dyadcount(g1)
  > density<-edges/dyads
  > coef.form<-coef.form.f(coef.diss,density)
  > 
  > 
  > 
  > # Simulate a networkDynamic for five steps
  > dynsim<-simulate(g1 ~ Form(~edges) + Persist(~edges),coef=c(coef.form,coef.diss),time.slices=S,dynamic=TRUE)
  > 
  > # ----- check net.obs.period encoding ----
  > 
  > # should have a net.obs.period object from 0 to 5
  > if (!all(unlist((dynsim%n%'net.obs.period')$observations)==c(0,1,1,11))){
  +   stop("simulate.network did not encode net.obs.period$observation correctly")
  + }
  > 
  > # "Resume" the simulation for five steps
  > dynsim2<-simulate(dynsim ~ Form(~edges) + Persist(~edges),time.slices=S,dynamic=TRUE)
  > 
  > if (!all(unlist((dynsim2%n%'net.obs.period')$observations)==c(0,1,1,11,11,21))){
  +   stop("simulate.networkDynamic did not encode net.obs.period$observation correctly")
  + }
  > 
  > # check a realistic example of starting a sim from scratch
  > mean.rel.dur <- 10
  > msm.sim <- network.initialize(100,directed=F)
  > activate.vertices(msm.sim,-Inf,Inf)
  > set.network.attribute(msm.sim,'net.obs.period',list(observations=list(c(-1,0)),
  +                                                     mode="discrete", time.increment=1,time.unit="step"))
  > formation <- ~edges
  > dissolution <- ~offset(edges)
  > target.stats <- 40
  > coef.diss <- log(mean.rel.dur-1)
  > formation.with.stnet <- update.formula(formation,msm.startnet~.)
  > msm.startnet <- network.collapse(msm.sim,at=0)
  > msm.est <- ergm(formation.with.stnet,target.stats=target.stats)
  Starting maximum pseudolikelihood estimation (MPLE):
  Obtaining the responsible dyads.
  Evaluating the predictor and response matrix.
  Maximizing the pseudolikelihood.
  Finished MPLE.
  Evaluating log-likelihood at the estimate. 
  > coef.form <- coef(msm.est)
  > coef.form[1] <- coef.form[1] - coef.diss
  > msm.edgelist <- as.edgelist(simulate(msm.est,dynamic=FALSE))
  Warning message:
  Argument(s) 'dynamic' were not recognized or used. Did you mistype an argument name? 
  > add.edges(msm.sim,msm.edgelist[,1],msm.edgelist[,2])
  > activate.edges(msm.sim, -Inf, Inf)
  > 
  > #first timestep 
  > msm.sim <- simulate(msm.sim ~ Form(~edges) + Persist(~edges),
  +                     coef=c(coef.form,coef.diss),
  +                     time.slices = 1,
  +                     monitor="all",
  +                     verbose=TRUE,
  +                     dynamic=TRUE
  + )
  extracting state of networkDynamic at time  -1
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 01 ).
  > #second timestep
  > msm.sim <- simulate(msm.sim ~ Form(~edges) + Persist(~edges),
  +                     coef=c(coef.form,coef.diss),
  +                     time.slices = 1,
  +                     monitor="all",
  +                     verbose=TRUE,
  +                     dynamic=TRUE
  + )
  extracting state of networkDynamic at time  0
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 12 ).
  > 
  > if(!all(unlist((msm.sim%n%'net.obs.period')$observations)==c(-1,  0,  0,  1,  1,  2))){
  +   stop('net.obs.period (and simulation) was not constructed as expected when stopping and restarting simulate.networkdynamic')
  + }
  > 
  > 
  > # test a sim with vertex dynamics applied after the sim stage
  > mean.rel.dur <- 10
  > msm.sim <- network.initialize(100,directed=F)
  > activate.vertices(msm.sim,-Inf,Inf)
  > set.network.attribute(msm.sim,'net.obs.period',list(observations=list(c(-1,0)),
  +                                                     mode="discrete", time.increment=1,time.unit="step"))
  > formation <- ~edges
  > dissolution <- ~offset(edges)
  > target.stats <- 40
  > coef.diss <- log(mean.rel.dur-1)
  > formation.with.stnet <- update.formula(formation,msm.startnet~.)
  > # simulate a set of edges to use as the starting point for the network
  > msm.startnet <- network.collapse(msm.sim,at=0)
  > msm.est <- ergm(formation.with.stnet,target.stats=target.stats)
  Starting maximum pseudolikelihood estimation (MPLE):
  Obtaining the responsible dyads.
  Evaluating the predictor and response matrix.
  Maximizing the pseudolikelihood.
  Finished MPLE.
  Evaluating log-likelihood at the estimate. 
  > coef.form <- coef(msm.est)
  > coef.form[1] <- coef.form[1] - coef.diss
  > msm.edgelist <- as.edgelist(simulate(msm.est,dynamic=FALSE))
  Warning message:
  Argument(s) 'dynamic' were not recognized or used. Did you mistype an argument name? 
  > add.edges(msm.sim,msm.edgelist[,1],msm.edgelist[,2])
  > activate.edges(msm.sim, -Inf, Inf)
  > 
  > # simulate first timestep (0,1)
  > msm.sim <- simulate(msm.sim ~ Form(~edges) + Persist(~edges),
  +                     coef=c(coef.form,coef.diss),
  +                     time.slices = 1,
  +                     monitor="formation",
  +                     verbose=TRUE,
  +                     dynamic=TRUE
  + )
  extracting state of networkDynamic at time  -1
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 01 ).
  > 
  > # toggle off vertices for the step just simulated
  > msm.sim<-deactivate.vertices(msm.sim,v=sample(which(is.active(msm.sim,v=1:network.size(msm.sim),at=0)),size=10),onset=0,terminus=Inf,deactivate.edges=TRUE)
  > add.vertices.active(msm.sim,nv=5,onset=0,terminus=Inf)
  > 
  > 
  > # simulate second timestep (1,2)
  > msm.sim <- simulate(msm.sim ~ Form(~edges) + Persist(~edges),
  +                     coef=c(coef.form,coef.diss),
  +                     time.slices = 1,
  +                     monitor="all",
  +                     verbose=TRUE,
  +                     dynamic=TRUE
  + )
  extracting state of networkDynamic at time  0
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 12 ).
  > 
  > msm.sim<-deactivate.vertices(msm.sim,v=sample(which(is.active(msm.sim,v=1:network.size(msm.sim),at=1)),size=10),onset=1,terminus=Inf,deactivate.edges=TRUE)
  > add.vertices.active(msm.sim,nv=1,onset=1,terminus=Inf)
  > 
  > # check for correct activity
  > if(!all(sapply(-1:2,function(t){network.size.active(msm.sim,at=t)})==c(100,95,86,86))){
  +   stop('vertex dynamics did not seem to generate correct activity in stergm sim')
  + }
  > 
  > if(!all(network.dynamic.check(msm.sim,complete=FALSE)$dyad.checks)){
  +   stop('vertex dynamics in stergm sim created inconsistent dyads')
  + }
  > 
  > # at this point msm.sim has observations as far as 2.  Try sampling at 2 and upating from (2,3)
  > msm.sim <- simulate(msm.sim ~ Form(~edges) + Persist(~edges),
  +                     coef=c(coef.form,coef.diss),
  +                     time.slices = 1, time.start=2,time.offset=0,
  +                     monitor="formation",
  +                     verbose=TRUE,
  +                     dynamic=TRUE
  + )
  extracting state of networkDynamic at time  2
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 23 ).
  Warning message:
  Argument time.start of 2 specified for a network that already has a time stamp of 1. Overriding the time stamp. 
  > 
  > if (max(unlist((msm.sim%n%'net.obs.period')$observations)) > 3){
  +   stop("simulate.networkDynamic updated net.obs.period inappropriately when time.start and time.offset was explicitly set" )
  + }
  > if (!all(get.change.times(msm.sim)==0:2)){
  +   stop("simulate.networkDynamic updated edge spells inappropriately when time.start and time.offset was explicitly set")
  + }
  > 
  > # try it again to make sure nothing got mangled
  > msm.sim <- simulate(msm.sim ~ Form(~edges) + Persist(~edges),
  +                     coef=c(coef.form,coef.diss),
  +                     time.slices = 1, time.start=3,time.offset=0,
  +                     monitor="all",
  +                     verbose=TRUE,
  +                     dynamic=TRUE
  + )
  extracting state of networkDynamic at time  3
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 34 ).
  Warning message:
  Argument time.start of 3 specified for a network that already has a time stamp of 2. Overriding the time stamp. 
  > if (max(unlist((msm.sim%n%'net.obs.period')$observations)) > 4){
  +   stop("simulate.networkDynamic updated net.obs.period inappropriately when time.start and time.offset was explicitly set" )
  + }
  > if (!all(get.change.times(msm.sim)==0:3)){
  +   stop("simulate.networkDynamic updated edge spells inappropriately when time.start and time.offset was explicitly set")
  + }
  > 
  > 
  > # check that vertex ids in changes are correctly translated
  > dyn<-as.networkDynamic(network.initialize(4))
  > deactivate.vertices(dyn,v=1)
  > # define stergm that should toggle on all ties
  > changes<-simulate(dyn ~ Form(~edges) + Persist(~edges),coef = c(1,0),output='changes',dynamic=TRUE)
  > # check if any changes involve vertex 1 (shouldn't because it is inactive)
  > if(any(changes[,2:3]==1)){
  +   stop("simulate.networkDynamic returned changes involving an inactive vertex" )
  + }
  > 
  > 
  > mean.rel.dur <- 10
  > msm.sim <- as.networkDynamic(network.initialize(100,directed=F))
  > #set.network.attribute(msm.sim,'net.obs.period',list(observations=list(c(-1,0)),
  > #                                                    mode="discrete", time.increment=1,time.unit="step"))
  > formation <- ~edges
  > dissolution <- ~offset(edges)
  > target.stats <- 40
  > coef.diss <- log(mean.rel.dur-1)
  > formation.with.stnet <- update.formula(formation,msm.startnet~.)
  > # simulate a set of edges to use as the starting point for the network
  > msm.startnet <- network.collapse(msm.sim,at=0)
  > msm.est <- ergm(formation.with.stnet,target.stats=target.stats)
  Starting maximum pseudolikelihood estimation (MPLE):
  Obtaining the responsible dyads.
  Evaluating the predictor and response matrix.
  Maximizing the pseudolikelihood.
  Finished MPLE.
  Evaluating log-likelihood at the estimate. 
  > coef.form <- coef(msm.est)
  > coef.form[1] <- coef.form[1] - coef.diss
  > msm.edgelist <- as.edgelist(simulate(msm.est,dynamic=FALSE))
  Warning message:
  Argument(s) 'dynamic' were not recognized or used. Did you mistype an argument name? 
  > add.edges(msm.sim,msm.edgelist[,1],msm.edgelist[,2])
  > 
  > msm.sim <- simulate(msm.sim ~ Form(~edges) + Persist(~edges),
  +                     coef=c(coef.form,coef.diss),
  +                     time.slices = 1, time.start=0,time.offset=0,
  +                     monitor="all",
  +                     verbose=TRUE,
  +                     dynamic=TRUE
  + )
  extracting state of networkDynamic at time  0
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 01 ).
  > 
  > 
  > if(length((msm.sim%n%'net.obs.period')$observations)>1){
  +   stop('simulate.networkDynamic mangled net.obs.period with time.offset=0 argument')
  + }
  > 
  > 
  > # --- check that adding and deleting vertices behaves properly ---
  > g0<-network.initialize(20,dir=TRUE)
  > g1<-san(g0~edges,target.stats=20,verbose=TRUE)
  Initializing unconstrained Metropolis-Hastings proposal: 'ergm:MH_TNT'.
  Initializing model...
  Model initialized.
  Starting 4 SAN iterations of 524288 steps each.
  #1 of 4: Exact match found.
  SAN Metropolis-Hastings accepted   0.000% of 32768 proposed steps.
  SAN summary statistics:
  edges 
     20 
  Meanstats Goal:
  edges 
     20 
  Difference: SAN target.stats - Goal target.stats =
  edges 
      0 
  New statistics scaling =
  [1] 1
  Scaled Mahalanobis distance = 0
  Target statistics matched exactly.
  > # Simulate a networkDynamic from static 
  > dynsim<-simulate(g1 ~ Form(~edges) + Persist(~edges),
  +                  coef=c(-9.326322,2.197225),
  +                  time.slices=1,verbose=TRUE, dynamic=TRUE)
  Returned from STERGM burnin
  > # add more vertices
  > add.vertices(dynsim,3)
  > # simulate another step
  > dynsim<-simulate(dynsim ~ Form(~edges) + Persist(~edges),
  +                  coef = c(-9.326322,2.197225),
  +                  time.slices=1,verbose=TRUE, dynamic=TRUE)
  extracting state of networkDynamic at time  1
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 23 ).
  > # expect to see a pid defined, but will just be numeric values
  > if (dynsim%n%'vertex.pid'!="tergm_pid"){
  +   stop("simulate.networkDynamic net not add a vertex.pid to the network as expected")
  + }
  > if(!all(is.numeric(dynsim%v%"tergm_pid"))){
  +   stop("simulate.networkDynamic did not create new numeric vertex pid as expected")
  + }
  > 
  > 
  > # add more (at this point there should be some non-numeric pids created)
  > add.vertices(dynsim,3)
  > if(all(is.numeric(dynsim%v%"tergm_pid"))){
  +   stop("add.vertices did not create new non-numeric vertex pids as expected")
  + }
  > 
  > # simulate
  > dynsim<-simulate(dynsim ~ Form(~edges) + Persist(~edges),
  +                  coef=c(-9.326322,2.197225),
  +                  time.slices=1,verbose=TRUE, dynamic=TRUE)
  extracting state of networkDynamic at time  2
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 34 ).
  > # delete some vertices
  > delete.vertices(dynsim,vid = 5:10)
  > dynsim<-simulate(dynsim ~ Form(~edges) + Persist(~edges),
  +                  coef=c(-9.326322,2.197225),
  +                  time.slices=1,verbose=TRUE, dynamic=TRUE)
  extracting state of networkDynamic at time  3
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 45 ).
  > 
  > # test with an externally defined PID  --------------
  > 
  > # Simulate a networkDynamic from static 
  > dynsim<-simulate(g1 ~ Form(~edges) + Persist(~edges),
  +                  coef=c(-9.326322,2.197225),
  +                  time.slices=1,verbose=TRUE, dynamic=TRUE)
  Returned from STERGM burnin
  > dynsim%n%'vertex.pid'<-'letters'
  > dynsim%v%'letters'<-LETTERS[1:20]
  > # simulate another step
  > dynsim<-simulate(dynsim ~ Form(~edges) + Persist(~edges),
  +                  coef=c(-9.326322,2.197225),
  +                  time.slices=1,verbose=TRUE, dynamic=TRUE)
  extracting state of networkDynamic at time  1
  Returned from STERGM burnin
  Updating networkDynamic with simulated time: ( 23 ).
  > # expect to see a pid defined, but will just be numeric values
  > if (dynsim%n%'vertex.pid'!="letters"){
  +   stop("simulate.networkDynamic vertex pid missing")
  + }
  > if(!all(is.na(dynsim%v%"tergm_pid"))){
  +   stop("simulate.networkDynamic created a tergm_pid when a vertex.pid already existed")
  + }
  > 
  > 
  > 
  > # ---- check summary.statistics.networkDynamic ---
  > # this was giving error in #958
  > my.nD <- network.initialize(10,directed=F)
  > activate.vertices(my.nD, onset=0, terminus = 10)
  > class(my.nD)
  [1] "networkDynamic" "network"       
  > summary(my.nD~isolates, at=1)
       isolates
  [1,]       10
  > 
  > 
  > # --- checking simulate with Inf coefficients ---
  > # was giving error to #995
  > n <- 10
  > nw <- network.initialize(n, directed = FALSE)
  > nw <- set.vertex.attribute(nw, "loc", rep(0:1, each = n/2))
  > 
  > fit <- ergm(nw ~ edges + offset(nodemix("loc", levels2=-c(1, 3))),
  +             target.stats = 3,
  +             offset.coef = -Inf)
  Starting maximum pseudolikelihood estimation (MPLE):
  Obtaining the responsible dyads.
  Evaluating the predictor and response matrix.
  Maximizing the pseudolikelihood.
  Finished MPLE.
  Starting Monte Carlo maximum likelihood estimation (MCMLE):
  Iteration 1 of at most 60:
  Warning: 'glpk' selected as the solver, but package 'Rglpk' is not available; falling back to 'lpSolveAPI'. This should be fine unless the sample size and/or the number of parameters is very big.
  Optimizing with step length 1.0000.
  The log-likelihood improved by 0.0007.
  Convergence test p-value: < 0.0001. Converged with 99% confidence.
  Finished MCMLE.
  Evaluating log-likelihood at the estimate. Fitting the dyad-independent submodel...
  Bridging between the dyad-independent submodel and the full model...
  Setting up bridge sampling...
  Using 16 bridges: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .
  Bridging finished.
  
  This model was fit using MCMC.  To examine model diagnostics and check
  for degeneracy, use the mcmc.diagnostics() function.
  Warning message:
  In ergm.bridge.llr(form.aug, constraints = constraints, obs.constraints = obs.constraints,  :
    Using target.stats for a model with offset terms may produce an inaccurate estimate of the log-likelihood and derived quantities (deviance, AIC, BIC, etc.), because some of the target stats must be imputed.
  > coef.form <- coef(fit)
  > coef.form[1] <- coef.form[1] - log(40-1)
  > 
  > fit.sim <- simulate(fit, dynamic=FALSE)
  Warning message:
  Argument(s) 'dynamic' were not recognized or used. Did you mistype an argument name? 
  > diag.sim <- simulate(fit.sim ~ Form(~ edges + offset(nodemix("loc", levels2=-c(1, 3)))) + Persist(~offset(edges)),
  +                      coef=c(coef.form,log(40-1)),
  +                      time.slices = 10,
  +                      monitor = "formation",
  +                      nsim = 1,dynamic=TRUE)
  > 
  > proc.time()
     user  system elapsed 
     4.90    0.35    5.25 
Running the tests in 'tests/tergm_parallel.R' failed.
Complete output:
  > #  File tests/tergm_parallel.R in package tergm, part of the
  > #  Statnet suite of packages for network analysis, https://statnet.org .
  > #
  > #  This software is distributed under the GPL-3 license.  It is free,
  > #  open source, and has the attribution requirements (GPL Section 7) at
  > #  https://statnet.org/attribution .
  > #
  > #  Copyright 2008-2023 Statnet Commons
  > ################################################################################
  > library(statnet.common)
  
  Attaching package: 'statnet.common'
  
  The following objects are masked from 'package:base':
  
      attr, order
  
  > opttest({
  +   library(tergm)
  +   data(florentine)
  +   net <- flobusiness
  +   set.seed(1)
  +   
  +   mod1 <- tergm(flobusiness ~ Form(~edges + degree(3)) + Persist(~offset(edges)),
  +                  offset.coef=log(9),
  +                  targets="formation",
  +                  estimate="EGMME",
  +                  control=control.tergm(parallel=2, parallel.type="PSOCK")
  +   )
  + 
  + }, testname='tergm_parallel')
  tergm_parallel test(s) skipped. Set ENABLE_statnet_TESTS environment variable to run.
  > 
  > opttest({
  +   data(florentine)
  +   net <- flobusiness
  +   set.seed(1)
  +   
  +   mod1 <- tergm(flobusiness ~ Form(~edges + degree(3)) + Persist(~offset(edges)),
  +                  offset.coef=log(9),
  +                  targets="formation",
  +                  estimate="EGMME",
  +                  control=control.tergm(parallel=2, parallel.type="MPI")
  +   )
  +   
  + }, testname='tergm_parallel_MPI', testvar="ENABLE_MPI_TESTS")
  tergm_parallel_MPI test(s) skipped. Set ENABLE_MPI_TESTS environment variable to run.
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.06    0.26