Open paciorek opened 9 months ago
Indeed this is unrelated to parallization and problem comes from having backward indexing of 3:1
because T
is being set to 1. The error message does point to the problematic model code line but does not indicate the indexing issue.
I'm not sure why we don't warn users when we encounter backward indexing.
@danielturek @perrydv do either of you remember why, when we check allowNegativeIndexSequences
and then if FALSE use nm_seq_noDecrease
why we don't issue some sort of note/warning?
@paciorek I think it was the case that some historical-types of model structures, backwards indexing can just "arise" somewhat naturally, and in those cases, it should be ignored... that was what BUGS did. So, we followed that model (of silently ignoring it), but (per usual) added an option for different behavior, if that's what a user wants (in this case, processing the backwards indexing).
Given all of that. Perhaps one path is to introduce a warning when we ignore such indexing, but perhaps that warning itself could be suppress-able. Or, maybe controlled by our verbose
system option?
A related issue came up recently on nimble-users here.
(The message subject was not really relevant.)
The issue was whether if nimbleModel sees "for(i in a:b)", where a:b
is 1:0
, does it result in no declarations? Evidently in BUGS/JAGS that is the case, and so in nested loops, e.g. "for(i in a:b[j])", one can skip some values of j for the inner loop. However we determined nimble is not supporting that. If you have your hands on these corner cases of for loop indices, is this is also relevant to decide about and handle?
My thoughts echo @danielturek 's. It does not seem like something is broken here. Given that it is a declarative language, index order should not matter. I can see some cases where it might be convenient to allow negative orders, but they seem rare. More often it seems it would be unintentional.
Ok, I will add a warning when we notice backward indexing and it is being ignored (which is the default).
Actually one other note here is that we actually get errors with backwards indexing. (And the exact error depends on other stuff in the model.) So I'm confused as to what use cases we might have checked when we were setting this up.
> code <- nimbleCode({
for(i in 3:1)
y[i] ~ dnorm(0,1)
z ~ dnorm(0,1)
})
m <- nimbleModel(code)
Defining model
Error in genExpandedNodeAndParentNames3(debug = debug) :
confused assigning unrolledIndicesMatrixRow in case with no unrolledRows by numUnrolledNodes != 1 for code y[i] ~ dnorm(mean = 0, sd = 1, lower_ = -Inf, upper_ = Inf, .tau = 1, .var = 1)
> code <- nimbleCode({
for(i in 3:1)
y[i] ~ dnorm(0,1)
# z ~ dnorm(0,1)
})
m <- nimbleModel(code)
Defining model
Error: There are multiple definitions for node(s): NA.
In addition: Warning message:
In origVertexID_2_contigID[contigID_2_origVertexID] <- 1:length(contigID_2_origVertexID) :
number of items to replace is not a multiple of replacement length
This came up as a possible parallelization question, but the error seems like it is probably simply triggered by using
T
without defining it and coercion to the value 1. Try seeing if running it serially but withT
not set also triggers and presuming so, trap the error.