statnet / ergm

Fit, Simulate and Diagnose Exponential-Family Models for Networks
Other
94 stars 36 forks source link

Error with dependencies, MCMLE #510

Closed dgzara closed 1 year ago

dgzara commented 1 year ago

Hi all,

I tried to run an ergm with structural and edgecov terms. I didn't have trouble with prior versions of R (<4.2.2) and ergm (< 4.4). Now, I'm getting the following error.

I'm not sure why I'm getting caught segfault errors now. I'd appreciate any help. Thanks!

Starting maximum pseudolikelihood estimation (MPLE):
Evaluating the predictor and response matrix.
Maximizing the pseudolikelihood.
Finished MPLE.
Starting Monte Carlo maximum likelihood estimation (MCMLE):
Iteration 1 of at most 50:

 *** caught segfault ***
address 0x7fd04e835370, cause 'memory not mapped'

Traceback:
 1: ergm_MCMC_slave(state[[1]], burnin = burnin, samplesize = samplesize,     interval = interval, eta = eta, control = control.parallel,     verbose = verbose, ...)
 2: doruns(burnin = interval, samplesize = samplesize, interval = interval)
 3: ergm_MCMC_sample(s, control, theta = mcmc.init, verbose = max(verbose -     1, 0))
 4: ergm.MCMLE(init, nw, model, initialfit = (initialfit <- NULL),     control = control, proposal = proposal, proposal.obs = proposal.obs,     verbose = verbose, ...)
 5: ergm(as.formula(paste0("g ~ ", ergm.formula)), constraints = ~blockdiag("project_id"),     control = control.ergms, eval.loglik = F)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

Here is my session info

R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Ventura 13.2.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rglpk_0.6-4    slam_0.1-50    ergm_4.4.0     network_1.18.1

loaded via a namespace (and not attached):
 [1] lpSolveAPI_5.5.2.0-17.9 magrittr_2.0.3          MASS_7.3-58.1           lattice_0.20-45         rlang_1.0.6             fastmap_1.1.0           fansi_1.0.4             tools_4.2.2             rbibutils_2.2.13        parallel_4.2.2         
[11] grid_4.2.2              rle_0.9.2               utf8_1.2.3              cli_3.6.0               coda_0.19-4             tibble_3.1.8            lifecycle_1.0.3         Matrix_1.5-1            purrr_1.0.1             vctrs_0.5.2            
[21] Rdpack_2.4              trust_0.1-8             robustbase_0.95-0       memoise_2.0.1           glue_1.6.2              cachem_1.0.6            statnet.common_4.8.0    DEoptimR_1.0-11         compiler_4.2.2          pillar_1.8.1           
[31] pkgconfig_2.0.3  
mbojan commented 1 year ago

Thanks @dgzara for reporting. Please provide a reproducible example that includes the offending call of ergm() together with (perhaps artificial) data that we can use to trace the problem. Otherwise it is difficult to investigate.

dgzara commented 1 year ago

Thanks, @mbojan. Here is the code I'm running. I can send you the dataset if needed.

I believe the error comes from the solver. I ran the same R script in a cluster from my university and the MCMC works. It runs and I get this message instead:

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.

ergm_code.txt

dgzara commented 1 year ago

I created the ERGM, saved the Rdata, and used those objects to continue the script in my computer. Still, I'm getting the error coming from summary.ergm_state(state)

` caught segfault address 0x7f8cac2a6ae8, cause 'memory not mapped'

Traceback: 1: summary.ergm_state(state) 2: summary(state) 3: summary.ergm_model(m, nw, term.options = control$term.options) 4: summary(m, nw, term.options = control$term.options) 5: simulate.ergm_model(m, nsim = nsim, seed = seed, coef = coef, constraints = proposal, monitor = mon.m, basis = nw, esteq = esteq, output = output, simplify = simplify, sequential = sequential, control = control, verbose = verbose, return.args = return.args, ...) 6: simulate(m, nsim = nsim, seed = seed, coef = coef, constraints = proposal, monitor = mon.m, basis = nw, esteq = esteq, output = output, simplify = simplify, sequential = sequential, control = control, verbose = verbose, return.args = return.args, ...) 7: simulate_formula.network(object, nsim = nsim, seed = seed, ..., basis = attr(object, ".Basis")) 8: simulate_formula(object, nsim = nsim, seed = seed, ..., basis = attr(object, ".Basis")) 9: simulate.formula_lhs_network(object = g ~ edges + gwidegree(decay, fixed = T) + gwodegree(decay, fixed = T) + edgecov(network.work.no.enjoy) + edgecov(network.enjoy.work) + edgecov(network.ranking, "ranking"), nsim = nsim, seed = seed, coef = coef, response = response, reference = reference, esteq = esteq, sequential = sequential, constraints = constraints, observational = observational, monitor = monitor, output = output, simplify = simplify, control = control, verbose = verbose) 10: stats::simulate(object = g ~ edges + gwidegree(decay, fixed = T) + gwodegree(decay, fixed = T) + edgecov(network.work.no.enjoy) + edgecov(network.enjoy.work) + edgecov(network.ranking, "ranking"), nsim = nsim, seed = seed, coef = coef, response = response, reference = reference, esteq = esteq, sequential = sequential, constraints = constraints, observational = observational, monitor = monitor, output = output, simplify = simplify, control = control, verbose = verbose) 11: eval(cl, parent.frame()) 12: eval(cl, parent.frame()) 13: simulate.formula(object$formula, nsim = nsim, coef = coef, response = response, reference = reference, esteq = esteq, sequential = sequential, constraints = constraints, observational = observational, monitor = monitor, basis = basis, output = output, simplify = simplify, control = control, verbose = verbose, seed = seed, ...) 14: simulate(object$formula, nsim = nsim, coef = coef, response = response, reference = reference, esteq = esteq, sequential = sequential, constraints = constraints, observational = observational, monitor = monitor, basis = basis, output = output, simplify = simplify, control = control, verbose = verbose, seed = seed, ...) 15: simulate.ergm(mod.1, nsim = 100, verbose = T) 16: simulate(mod.1, nsim = 100, verbose = T)

Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace `

mbojan commented 1 year ago

Thanks @dgzara .

The message about Rglpk is benign, but you may want to install it because it is preferred in general to the fallback lpSolveAPI.

So to summarize: your estimation code failed with segafult on your personal computer but completed succesfully on a different compuer (cluster)? Then you wanted to simulate from the estimated model on your personal computer and this, again, resulted with a segfault. Is that correct?

Can you please provide an RData so that I can try to reproduce the problem just by running simulate()?

mbojan commented 1 year ago

My hypotheses so far:

CC @krivit

krivit commented 1 year ago

Without a working example, I can't really speculate.

martinamorris commented 1 year ago

Maybe a clean install of R and packages would be a good idea?

On Tue, Mar 14, 2023 at 2:04 AM Pavel N. Krivitsky @.***> wrote:

Without a working example, I can't really speculate.

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/statnet/ergm/issues/510*issuecomment-1467678784__;Iw!!K-Hz7m0Vt54!myZfWf_hgQLeD-i9VmaLAcYaKcttOm3b056VQtShPSA9dB5Lf9PA9yf97iPGSJrfLg4OlxkqFWvcIz8wu96hTsk$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AB6QTYXYMJL6TRE5WTPHW3LW4AYARANCNFSM6AAAAAAVBFI5XM__;!!K-Hz7m0Vt54!myZfWf_hgQLeD-i9VmaLAcYaKcttOm3b056VQtShPSA9dB5Lf9PA9yf97iPGSJrfLg4OlxkqFWvcIz8wGMtJIdY$ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

krivit commented 1 year ago

Since there hasn't been any word from the reporter, I assume this was resolved. If not, please reopen.