# R forced closed during run

9 posts / 0 new
Offline
Joined: 09/07/2010 - 17:14
R forced closed during run

I would like to report an instance when R was forced closed without an error message.

I was running an ACE model with the components A C and E being matrices. When specifying the DZ twin covariance I used 0.5*A+C instead of 0.5%x%A+C, which caused the crash. Replacing the * by %x% fixed the problem.

Aside from the crash, it is quite tricky that * cannot be used for scalar-matrix multiplication, which is not consistent with R operations. To represent the scalar multiplication in a linear space as a special case of Kronecker product is a bit weird.

Offline
Joined: 07/31/2009 - 15:24
Could you attach a script

Could you attach a script that reproduces the behavior? WRT the * operator: in OpenMx only matrix types are expressed. All scalar values are converted into 1 x 1 matrices. So * performs element multiplication, see http://openmx.psyc.virginia.edu/wiki/matrix-operators-and-functions. Ah, and you may be seeing an error if our consistency checker is passing in R, but then crashes in the backend.

Offline
Joined: 07/31/2009 - 15:24
As a follow up, the following

As a follow up, the following small example will return a poorly phrased error. But it won't crash the R program. So we need your test case to reproduce the error. With regards to the poorly phrased error, this will be fixed in OpenMx post-1.0 when the mxEval() function is rewritten from scratch.

foo <- mxMatrix('Full', 2, 2, name = 'foo')
bar <- mxAlgebra(0.5 * foo, name = 'bar')
model <- mxModel('model', foo, bar)
modelOut <- mxRun(model)
Offline
Joined: 09/07/2010 - 17:14

I also run the example code you provided in the follow up, but they trigger quite different outcomes. My error messages are not within the R window. Instead, they are pop outs, and R terminates.

Thank you.

> require(OpenMx)
>
> p<-2;
> replication<-1000;
> varnames<-c(paste("var1_",1:p,sep=""),paste("var2_",1:p,sep=""));
>
> pstar<-p(p+1)/2;
> nMZ=1000;
> nDZ=1000;
>
> LA<-mxMatrix(type="Lower",nrow=p,ncol=p,free=T,values=1,
+ label=paste("a",1:pstar,sep=""),name="LA");
> LC<-mxMatrix(type="Lower",nrow=p,ncol=p,free=T,values=1,
+ label=paste("c",1:pstar,sep=""),name="LC");
> LE<-mxMatrix(type="Lower",nrow=p,ncol=p,free=T,values=1,
+ label=paste("e",1:pstar,sep=""),name="LE");
>
> A<-mxAlgebra(expression=LA%
%t(LA),name="A");
> C<-mxAlgebra(expression=LC%%t(LC),name="C");
> E<-mxAlgebra(expression=LE%
%t(LE),name="E");
> ACESigmaMZ<-mxAlgebra(expression=rbind(cbind(A+C+E,A+C),cbind(A+C,A+C+E)),
+ name="ACESigmaMZ");

Now it gives a message with header "Microsoft Visual C++ Runtime Library", saying that the "Rgui.exe" has requested the runtime to terminate in an unusual way. Then another error message with header "RGui: Ggui.exe - Application Error", saying instruction at "0x00530057" referenced memory at (the same string). The memory could not be "read".

Offline
Joined: 07/31/2009 - 15:24
Good news everyone. I'm

Good news everyone. I'm checking in a patch so that the small test problem:

foo <- mxMatrix('Full', 2, 2, name = 'foo')
bar <- mxAlgebra(0.5 * foo, name = 'bar')
model <- mxModel('model', foo, bar)
modelOut <- mxRun(model)

Now produces the error message:

"Error: The following error occurred while evaluating the subexpression '0.5 * model.foo' during the evaluation of 'bar' in model 'model' : non-conformable arrays"

OpenMx is now on a two-track of parallel codebases. This change will appear in the OpenMx 1.1 release, as a part of the larger rewrite of the mxEval() function. To see the changes in the meantime, build the library from the subversion trunk.

Offline
Joined: 07/31/2009 - 15:14
Nice patch! IMHO, the error

Nice patch! IMHO, the error message is correct (great) but inadequate. Better would be:

"Error: The following error occurred while evaluating the subexpression '0.5 * model.foo' during the evaluation of 'bar' in model 'model' : non-conformable arrays. The first matrix is of dimension 1x1 while the second is of dimension 2x2"

Although in this case it is pretty unambiguous as to which part of the subexpression has failed, perhaps with more complicated expressions it would be difficult to discern. Letting the user know matrix dimensions (which must be known when the error is detected) can be really helpful. At the same time, which is "first" and "second" might be difficult to assign, as for example when the left to right ordering of operations has been revised by the use of parentheses. Even if we keep track of where in the input stream the matrices originated, a problematic operation might involve the result of another operation, so that the error would become, e.g., ...while evaluating the subexpression "the result of (A*B+C) is 1x1 but D is 2x2". This level of detail would make for rapid debug of matrix expressions, and adoring users :).

Offline
Joined: 09/07/2010 - 17:14
Thank you for fixing the

Thank you for fixing the problem.

Offline
Joined: 07/31/2009 - 15:12
I was recently attempting to

I was recently attempting to include an exponent in a mxAlgebra, and hit a similar problem with the syntax matrix^scalar. I interpreted element powering (^) as "raise each element in the matrix to the scalar power," when that functionality is actually achieved with kronecker powering (%^%). I understand the logic, that objects in mxAlgebras are treated as matrices, so the closest thing we have to a matrix by scalar is a kronecker exponent of a matrix and the "scalar" 1x1 matrix.

Offline
Joined: 07/31/2009 - 15:24
I have reproduced the error

I have reproduced the error on my machine. Sorry for the bug. I'll run the script under a memory debugger and find the source of the problem.