The following was posted on the R interface bugs, but I think it is a Pyper bug since I cannot reproduce it in R.
Scott Tetrick 2011-11-02 00:58:06 EDT
I have a windows & Python (w/ Pyper) routine that opens R. All the vectors are
in "R-space", just the control is in python. I have a .Call routine that is
called, but the result seems to be forgotten by R. I even tried to put the PID
number in the database, because the initial error was seen during a "make -j4".
The error occurred on 2.13.2 as well.
I get this error in the Cygwin window when running the program even single
threaded:
Traceback (most recent call last):
File "TwoLMR3.py", line 657, in <module>
mymain()
File "TwoLMR3.py", line 648, in mymain
my_files.append(trace(fn,xfg,cnt,r,options,warmup=WARM,ra=mylist,plotRA=WARM
))
File "TwoLMR3.py", line 391, in __init__
self.tstat[llist][(rbw,wbw)].append(getR(r,"mean(%s$pid)" % vec,D))
File "TwoLMR3.py", line 161, in getR
return r[s.substitute(D)]
File "C:\Python26\lib\site-packages\pyper.py", line 519, in __getitem__
raise RError(rlt)
pyper.RError: 'try({.getRvalue4Python__(mean(niopwr6936),
use_dict=NULL)})\r\n\r
\nTraceback:\r\n 1: mean(niopwr6936)\r\n 2: is.factor(x)\r\n 3: Str4Py(x,
outmos
t = TRUE)\r\n 4: .getRvalue4Python__(mean(niopwr6936), use_dict = NULL)\r\n 5:
d
oTryCatch(return(expr), name, parentenv, handler)\r\n 6: tryCatchOne(expr,
names
, parentenv, handlers[[1L]])\r\n 7: tryCatchList(expr, classes, parentenv,
handl
ers)\r\n 8: tryCatch(expr, error = function(e) { call <- conditionCall(e)
if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch)))
call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <-
paste("Error in", dcall, ": ") LONG <- 75L msg <-
conditionMessage
(e) sm <- strsplit(msg, "\\n")[[1L]] w <- 14L + nchar(dcall, type
= "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L +
n
char(dcall, type = "b") + nchar(sm[1L], type = "b") if
(w
> LONG) prefix <- paste(prefix, "\\n ", sep = "") } else
pre
fix <- "Error : " msg <- paste(prefix, conditionMessage(e), "\\n", sep = "")
.Internal(seterrmessage(msg[1L])) if (!silent &&
identical(getOption("show
.error.messages"), TRUE)) { cat(msg, file = stderr())
.Int
ernal(printDeferredWarnings()) } invisible(structure(msg, class =
"try-err
or", condition = e))})\r\n 9: try({ .getRvalue4Python__(mean(niopwr6936),
use
_dict = NULL)})\r\nError in mean(niopwr6936) : caught access violation -
continu
e with care\r\n'
This looks like an R error, like it forgets niopwr6936 somewhere.
The Python/R code looks like this:
sendR(r,"""ans$pid <-
.Call('CompThrot',rbw$pid,wbw$pid,%g,%g)""" % (rbw,wbw),D)
sendR(r,"""pxrd$pid <- ans$pid[1,]
pxwr$pid <- ans$pid[2,]""",D)
sendR(r,"npwr$pid <- (pxrd$pid * 1e-12 * $ReadpJ + pxwr$pid *
1e-12 * $WritepJ) * 8 * (1+$ECCBYTES/$ECCBLOCK)",D)
sendR(r,"niopwr$pid <- pxrd$pid * (1+$ECCBYTES/$ECCBLOCK) *
$IOPower/($IOPowerBW*1e9)",D)
sendR(r,"ntotpwr$pid <- npwr$pid + niopwr$pid",D)
self.tstat["ComplexArrayPwr"][(rbw,wbw)]=[]
self.tstat["ComplexIOPwr"][(rbw,wbw)]=[]
self.tstat["ComplexTotPwr"][(rbw,wbw)]=[]
if self.warm < self.length:
lims = "[%d:%d]" % (self.warm+1,self.length)
self.tstat["RTComplexArrayPwr"][(rbw,wbw)]=[]
self.tstat["RTComplexIOPwr"][(rbw,wbw)]=[]
self.tstat["RTComplexTotPwr"][(rbw,wbw)]=[]
pass
for (vec,llist) in zip(("npwr","niopwr","ntotpwr"),
("ComplexArrayPwr","ComplexIOPwr","ComplexTotPwr")):
#ERROR in THIS LINE BELOW:
self.tstat[llist][(rbw,wbw)].append(getR(r,"mean(%s$pid)" %
vec,D))
if self.warm < self.length:
self.tstat["RT"+llist][(rbw,wbw)].append(getR(r,"mean(%s$pid%s)" %
(vec,lims),D))
pass
pass
sendR just sends the quoted text to R with the appropriate $VALUES replaced.
You can see that this is not the first reference to niopwr$pid.
[reply] [-] Comment 1 Brian Ripley 2011-11-02 04:13:46 EDT
There is no evidence here that the error is in R. Most likely the
error is in the interface.
Apriori, any error invilving .Call is an error in the compiled code,
which we don't have here.
So please provide an example of doing this purely in R, or we'll close
the report.
[reply] [-] Comment 2 Scott Tetrick 2011-11-02 18:37:27 EDT
Created an attachment (id=1244) [details]
.Call routine in C
This is the C routine that fails in the Pyper call.
[reply] [-] Comment 3 Scott Tetrick 2011-11-02 18:38:08 EDT
Created an attachment (id=1245) [details]
Second .Call routine in C (both are used)
[reply] [-] Comment 4 Scott Tetrick 2011-11-02 18:40:27 EDT
Trying to duplicate in "pure R" failed.
Ran the following, and both ran to completion:
> dyn.load('SimpThrot.dll')
> for (i in 1:1000) {
+ r <- abs(rnorm(500000))
+ w <- abs(rnorm(500000))
+ a <- .Call("SimpThrot",r,w,1,1)
+ }
> dyn.load('CompThrot.dll')
> for (i in 1:1000) {
+ r <- abs(rnorm(500000))
+ w <- abs(rnorm(500000))
+ a <- .Call("CompThrot",r,w,1,1)
+ }
>
No failure, so I would have to agree that it appears that PYPER is our problem
with .Call.