Skip to content

Wrap getAFIs and getMIs calls in permuteOnce.mgcfa and permuteOnce.mimic with tryCatch (closes #159)#160

Open
Shotgunosine wants to merge 2 commits into
simsem:masterfrom
Shotgunosine:defend_parallel
Open

Wrap getAFIs and getMIs calls in permuteOnce.mgcfa and permuteOnce.mimic with tryCatch (closes #159)#160
Shotgunosine wants to merge 2 commits into
simsem:masterfrom
Shotgunosine:defend_parallel

Conversation

@Shotgunosine

Copy link
Copy Markdown
Contributor

When getAFIs (calling lavaan::fitMeasures) or getMIs (calling lavaan::lavTestScore) errors during a permutation iteration — for example due to LAPACK dgesdd failures on numerically pathological score-test matrices, see Reference-LAPACK/lapack#672 — the unhandled error kills the worker. Under parallelType = "multicore" this causes mclapply to return a try-error for that permutation, which then crashes the aggregation at line ~990 with Error in x$AFI : $ operator is invalid for atomic vectors.

The fix wraps both calls in tryCatch with the same NA fallback that the function already uses for the sparse/nonconv branch (lines 1404–1410), so a single bad permutation contributes NA to the null distribution rather than terminating the entire call. I applied the same change to permuteOnce.mimic for consistency.

Note that I didn't add a new counter for something like n.LapackFail, so the n.nonConverged counter will be under-counting the true number of failures. I kept this initial proposed fix as narrow in scope as possible, but I can try to add an additional failure counter if you'd like.

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.

1 participant