Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: Unknown Error code xxxx xxx using R, reticulate and nrel-pysam #150

Open
minimenchmuncher opened this issue May 30, 2023 · 4 comments

Comments

@minimenchmuncher
Copy link

This issue is cross-listed on the GitHub page for reticulate: rstudio/reticulate#1369 . The gist is, I cannot call any compute modules in PySAM using reticulate, on Linux (it seems to work properly on windows, and mac is untested).

However what does work is

  • using the compute modules natively in python, as per the normal documentation, this seems to work perfectly fine
  • I can still use PySSC and ResourceTools, seemingly, without issue through reticulate (though this does negate some of the convenience of the PySAM module)

Original Issue

I'm attempting to use reticulate within R to interface with NREL's SAM library via PySAM (nrel-pysam on pypi); however, I cannot interface with any of the compute modules, resulting in an error that says simply:

Exception: Unknown code s5wu 64

Though the exact code changes each time I run it, making me think it has something to do with RAM addressing.

Here's an example of what I've tried, using AlmaLinux 9.1 (a clean, fresh install), which comes with python version 3.9:

## install R
sudo dnf install python3-pip epel-release
sudo dnf config-manager --set-enabled crb
sudo dnf install R

## set up python dependencies
python -m venv env
source env/bin/activate
pip install nrel-pysam
## Python example, for reference
import PySAM.Pvwattsv8 as pv
pv.new()
## executes with no problem
## within R
install.packages("reticulate")
library(reticulate)
use_virtualenv("~/env")
pv <- import("PySAM.Pvwattsv8")
pvwatts_model <- pv$new()

Error in py_call_impl(callable, call_args$unnamed, call_args$named) : 
  Exception: Unknown code Rb8s 32

a full traceback yields something that looks like

3: stop(structure(list(message = "Exception: Unknown code Rb8s 32\n", 
       call = NULL, cppstack = structure(list(file = "", line = -1L, 
           stack = c("/home/vagrant/R/x86_64-redhat-linux-gnu-library/4.3/reticulate/libs/reticulate.so(+0x1d688) [0x7f6027827688]", 
           "/home/vagrant/R/x86_64-redhat-linux-gnu-library/4.3/reticulate/libs/reticulate.so(+0x11685) [0x7f602781b685]", 
           "/home/vagrant/R/x86_64-redhat-linux-gnu-library/4.3/reticulate/libs/reticulate.so(+0x1be24) [0x7f6027825e24]", 
           "/home/vagrant/R/x86_64-redhat-linux-gnu-library/4.3/reticulate/libs/reticulate.so(_reticulate_py_call_impl+0xda) [0x7f602782f94a]", 
           "/usr/lib64/R/lib/libR.so(+0xf7cde) [0x7f603f1dbcde]", 
           "/usr/lib64/R/lib/libR.so(+0x13c49e) [0x7f603f22049e]", 
           "/usr/lib64/R/lib/libR.so(Rf_eval+0x178) [0x7f603f207838]", 
           "/usr/lib64/R/lib/libR.so(+0x12267e) [0x7f603f20667e]", 
           "/usr/lib64/R/lib/libR.so(Rf_applyClosure+0x268) [0x7f603f207588]", 
           "/usr/lib64/R/lib/libR.so(+0x13fc7c) [0x7f603f223c7c]", 
           "/usr/lib64/R/lib/libR.so(Rf_eval+0x178) [0x7f603f207838]", 
           "/usr/lib64/R/lib/libR.so(+0x12267e) [0x7f603f20667e]", 
           "/usr/lib64/R/lib/libR.so(Rf_applyClosure+0x268) [0x7f603f207588]", 
           "/usr/lib64/R/lib/libR.so(Rf_eval+0x2a5) [0x7f603f207965]", 
           "/usr/lib64/R/lib/libR.so(Rf_ReplIteration+0x322) [0x7f603f2646f2]", 
           "/usr/lib64/R/lib/libR.so(+0x180ab0) [0x7f603f264ab0]", 
           "/usr/lib64/R/lib/libR.so(run_Rmainloop+0x49) [0x7f603f264b69]", 
           "/usr/lib64/R/bin/exec/R(main+0x1f) [0x561e47aa10af]", 
           "/lib64/libc.so.6(+0x3feb0) [0x7f603ef12eb0]", "/lib64/libc.so.6(__libc_start_main+0x80) [0x7f603ef12f60]", 
           "/usr/lib64/R/bin/exec/R(_start+0x25) [0x561e47aa10e5]"
           )), class = "Rcpp_stack_trace")), class = c("Rcpp::exception", 
   "C++Error", "error", "condition")))
2: py_call_impl(callable, dots$args, dots$keywords)
1: pv$new()

I have attempted to do more or less the following on a variety of OSes (Fedora 38, Ubuntu 20.04, AlmaLinux 9.1 to name a fiew) with a variety of python versions (3.8 - 3.11), I've tried both the CRAN version of reticulate and the current (as of 2023-05-08) main branch version on Github, I've installed nrel-pysam with pip and with conda (not having both at the same time of course), have only ever seen this error message. Here's a sample session info:

> sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: AlmaLinux 9.1 (Lime Lynx)

Matrix products: default
BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP;  LAPACK version 3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reticulate_1.28-9000

loaded via a namespace (and not attached):
[1] compiler_4.3.0 Matrix_1.5-4   cli_3.6.1      Rcpp_1.0.10    grid_4.3.0    
[6] jsonlite_1.8.4 rlang_1.1.1    png_0.1-8      lattice_0.21-8

Happy to include any/all other information as necessary.

@janinefreeman
Copy link
Collaborator

Hi! Thanks for your issue report. Unfortunately we don't have the bandwidth to investigate this issue at the moment. Have you had a chance to investigate whether the issue is your version of Linux, or the interaction with reticulate?

@minimenchmuncher
Copy link
Author

minimenchmuncher commented May 31, 2023

Consistent across:

  • Versions of linux (Alma 9.1, Ubuntu 20.04, Fedora 38 tested)
  • Versions of python, probably (3.9 and 3.11 tested)
  • Possibly versions of reticulate, 1.28 (current CRAN as of 2023-05-31) and 1.28.9000 (current on Github as of 2023-05-31)
    Tested with Windows, but it works fine on windows.
    Not tested across versions of R, just 4.3.0.
    Not tested on Mac or other OSes.

It's definitely an issue with interacting with reticulate as keeping everything in python works consistently well.
I'm wondering if it's just an issue with a build configuration or something like that; I don't know what other logic would really be OS dependent.

It's also, I think, limited to an issue with loading compute modules. I can load PySSC and the ResourceTools classes just fine.

I'll note really quickly that since there's no R interface for the SSC library, without needing to do a ton of C++ programming, I think interacting with the SSC this way is an R programmer's best bet.

@janinefreeman
Copy link
Collaborator

Thanks for the additional detail! @sjanzou , can you think of anything else that would be OS specific to try?

@sjanzou
Copy link
Collaborator

sjanzou commented Jun 8, 2023

Without actually installing and duplicating the issue, building on the discussion at: rstudio/reticulate#1369

I would look at how the PySAM_TECH_ATTR() macro in pysam/src/PySAM_utils.h plays with the R new operator and garbage collection
image

The new_error() function mentioed is a cpython function defined by
image

Hope this helps to debug...

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

No branches or pull requests

3 participants