Skip to content

Fix MCMC.maxchanges = Inf integer coercion warning in tergm#956

Merged
smjenness merged 1 commit intomainfrom
fix-mcmc-maxchanges
Mar 1, 2026
Merged

Fix MCMC.maxchanges = Inf integer coercion warning in tergm#956
smjenness merged 1 commit intomainfrom
fix-mcmc-maxchanges

Conversation

@smjenness
Copy link
Copy Markdown
Collaborator

@smjenness smjenness commented Feb 27, 2026

Replace MCMC.maxchanges = Inf with .Machine$integer.max in netdx(), control.net(), and netest() defaults.

When Inf is passed as MCMC.maxchanges, it flows to tergm::tergm_MCMC_slave() which calls as.integer(maxchanges) before the .Call to MCMCDyn_wrapper. as.integer(Inf) produces NA with a warning: "NAs introduced by coercion to integer range".

Note that tergm wraps the analogous MCMC.maxedges parameter with deInf(maxedges, "maxint") before as.integer(), which correctly converts Inf to .Machine$integer.max. The same deInf() wrapper is missing for MCMC.maxchanges in tergm_MCMC_slave(). This is arguably a bug in tergm -- see the relevant code:

tergm::tergm_MCMC_slave:
maxedges <- NVL(control$MCMC.maxedges, Inf)
maxchanges <- control$MCMC.maxchanges
z <- .Call("MCMCDyn_wrapper", ...,
as.integer(deInf(maxedges, "maxint")), # <- wrapped
as.integer(maxchanges), # <- NOT wrapped
...)

This warning surfaced after ergm 4.12.0 (2026-02-17) triggered a recompilation of the tergm binary, likely changing how the C code uses the maxchanges argument.

Using .Machine$integer.max (2,147,483,647) is functionally equivalent to Inf for this purpose -- it effectively removes the limit on MCMC changes per step -- while avoiding the integer coercion warning.

Replace MCMC.maxchanges = Inf with .Machine$integer.max in netdx(),
control.net(), and netest() defaults.

When Inf is passed as MCMC.maxchanges, it flows to
tergm::tergm_MCMC_slave() which calls as.integer(maxchanges) before
the .Call to MCMCDyn_wrapper. as.integer(Inf) produces NA with a
warning: "NAs introduced by coercion to integer range".

Note that tergm wraps the analogous MCMC.maxedges parameter with
deInf(maxedges, "maxint") before as.integer(), which correctly
converts Inf to .Machine$integer.max. The same deInf() wrapper is
missing for MCMC.maxchanges in tergm_MCMC_slave(). This is arguably
a bug in tergm -- see the relevant code:

  tergm::tergm_MCMC_slave:
    maxedges <- NVL(control$MCMC.maxedges, Inf)
    maxchanges <- control$MCMC.maxchanges
    z <- .Call("MCMCDyn_wrapper", ...,
              as.integer(deInf(maxedges, "maxint")),  # <- wrapped
              as.integer(maxchanges),                  # <- NOT wrapped
              ...)

This warning surfaced after ergm 4.12.0 (2026-02-17) triggered a
recompilation of the tergm binary, likely changing how the C code
uses the maxchanges argument.

Using .Machine$integer.max (2,147,483,647) is functionally equivalent
to Inf for this purpose -- it effectively removes the limit on MCMC
changes per step -- while avoiding the integer coercion warning.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@smjenness
Copy link
Copy Markdown
Collaborator Author

@AdrienLeGuillou : could you review this before I merge it in? Although you made the Inf change way back in 2024, I think some new warnings were triggered by recent updates to ergm last week.

Copy link
Copy Markdown
Member

@AdrienLeGuillou AdrienLeGuillou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your assessment.
I will check next week with HIV-p if things need to be updated as well there for this and the deprecated ERGM term (similar to #953)

@smjenness smjenness merged commit 07b2960 into main Mar 1, 2026
7 checks passed
@smjenness smjenness deleted the fix-mcmc-maxchanges branch March 1, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants