Pytorch print(x) gives Illegal instruction (core dumped) - torch

I am using anaconda python2.7. I was able to install pytorch by using conda install pytorch from the installation guide at http://pytorch.org/
When I enter python and test the example
from __future__ import print_function
import torch
from torch.autograd import Variable
x = Variable(torch.ones(2, 2), requires_grad=True) ## works fine
print (x) ## broke here
x ## also broke, python can't give the values stored in x
I get the error Illegal instruction (core dumped) after the using the print(x).
I am able to do all the pytorch operation on x except for printing its value. At some point, I would have to look at the value in x. Does anybody have the same problem or know how to fix this?
Thanks.

Related

How can I successfully call python script in R using [reticulate] when having 'multiprocessing' module in python script?

I am trying to use reticulate package to call python script in R. Previously, it run successfully but this time, the python script includes the multiprocessing module, then I cannot run through. And in RStudio, it always stuck there.
Here is the tested python script, named test_multiprocessing.py.
# test_multiprocessing.py
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
with Pool(5) as p:
print(p.map(f, [1, 2, 3]))
I can run the above script in python, but in RStudio as below:
library(reticulate)
condaEnvName = 'myEnv'
reticulate::use_condaenv(condaEnvName, required = TRUE)
reticulate::source_python('./test_multiprocessing.py')
The R always stuck there.
Can you please guide me how can we successfully call the python script in R when using multiprocessing module in the python script like above one?
I am using Windows 10 OS.
Thanks.

Sympy Attribute Error: module 'sympy' has no attribute 'derive_by_array'

I keep receiving this error when trying to derive using sympy.
I have updated sympy using Anaconda Prompt and "conda update sympy" but it made no change when trying to use the derive_by_array function in jupyter-notebook. Perhaps the update isn't registering in jupyter?
What can I do to fix this issue?
Here is a general example of the code where I receive the error:
import sympy as sp
x= sp.symbols('x')
f = x**2
sp.derive_by_array(f,x)
After removing using Anaconda Prompt then installing a newer version of Anaconda, sympy started working.

Python/R ctypes library error: "OSError: lib/libRrefblas.so: undefined symbol: xerbla_"

Firstly, I'm a newbie R, AWS and python guy. So I'm trying to get a python script with embedded R code running in AWS Lambda using rpy2. I created a Lambda package on an EC2 instance following the instructions here (modified for using python 3.4). It seems that there is something funky happening with loading the R libs using ctypes, as per the following error received in the console:
OSError: lib/libRrefblas.so: undefined symbol: xerbla_
The test file (py_test.py) looks like this:
import os
import ctypes
for file in os.listdir('lib'):
if os.path.isfile(os.path.join('lib', file)):
ctypes.cdll.LoadLibrary(os.path.join('lib', file))
os.environ["R_HOME"] = os.getcwd()
os.environ["R_USER"] = os.path.join(os.getcwd(), 'rpy2')
os.environ["R_LIBS"] = os.path.join(os.getcwd(), 'library')
os.environ["LD_LIBRARY_PATH"] = os.path.join(os.getcwd(), 'lib')
import sys
sys.path.append(os.path.join(os.getcwd(),'rpy2'))
import rpy2
from rpy2 import robjects
def test_handler(event, context):
robjects.r('''
f <- function(r, verbose=FALSE) {
if (verbose) {
cat("I am calling f().\n")
}
2 * pi * r
}
print(f(3))
''')
test_handler(None,None)
I have lib/libRrefblas.so in my virtual environment. I have scoured google looking for answers but have come up empty. Any suggestions would be greatly appreciated!
If you can get the traceback, that could help, but I suspect the problem is that it's looking for xerbla_ in the wrong place. Is xerbla_ defined in the path to RLIBS? Maybe in libR.so?
Turns out the BLAS that ships with R is corrupt. Your best bet is to make sure that BLAS and Lapack are installed on the machine you are building R on and see if you can get it to build with those libraries instead.
So steps would be to uninstall R, then run
yum -y install lapack-devel.x86_64 lapack.x86_64
yum -y install blas -devel
yum -y install R.x86_64
Check to see if it has still installed with libRrefblas.so. If it has - try deleting that file and see if it will default to the system BLAS. If you get a error because it is still looking for libRrefblas.so
rm lib/libRrefblas.so
cp /usr/lib64/libblas.so.3 lib/
mv lib/libblas.so.3 lib/libRrefblas.so

ImportError: No module named 'fig_code'

I am using ipython notebook. I am using python 3.5 . I got No module named 'fig_code' error while running a program as written below.
#Code
from sklearn import neighbors, datasets
iris = datasets.load_iris()
X, y = iris.data, iris.target
knn = neighbors.KNeighborsClassifier(n_neighbors=5, weights='uniform')
knn.fit(X, y)
X_pred = [3, 5, 4, 2]
result = knn.predict([X_pred, ])
print(iris.target_names[result])
print(iris.target_names)
print(knn.predict_proba([X_pred, ]))
from fig_code import plot_iris_knn
plot_iris_knn()
The error I am getting is as follows
ImportError Traceback (most recent call last)
<ipython-input-3-e8dd8ed3c9cb> in <module>()
18 print(knn.predict_proba([X_pred, ]))
19
---> 20 from fig_code import plot_iris_knn
21 plot_iris_knn()
ImportError: No module named 'fig_code'
I tried to install fig_code by using 'pip install fig_code' but I am getting this error
"Could not find a version that satisfies the requirement fig_code (from versions: ) No matching distribution found for fig_code"
I have searched the error to resolve this issue but no use.
Can anyone help me resolve it?
Seems you are following 'fig_code' from Jake Vanderplas lecture from pyon2015 on sklearn.
Okay, coming straightway to your problem. go to the https://github.com/jakevdp/sklearn_pycon2015 and download/cloan it. In 'notebooks' you will find fig_code folder. save it in the folder where your script is ....Now you will able to call 'fig_code'....
fig_code refers to a folder supplementary to Jake VanderPlas's sklearn ipython notebooks.
Download the fig_code module from Github by typing the following command in Terminal:
svn checkout https://github.com/jakevdp/sklearn_pycon2015/trunk/notebooks/fig_code
A folder named 'fig_code' will appear in your home directory.
Move 'fig_code' to the folder where your script is.

In Ipython Qt Console sp.info doesn't print inside the console

I have installed IPython 1.1.0, in Ubuntu 12.04 from the source.
Similarly I have installed Numpy-1.8.0, Scipy-0.13.1, Matplotlib-1.3.1 from the source.
When I use the Ipython Qt COnsole the command sp.info(optimize.fmin) doesn't print the output in console but it prints it in the terminal (pylab). Is there anyway that it can print it in console too.
import numpy as np
import scipy as sp
from scipy import optimize
sp.info(optimize.fmin)
The output is like this in pylab
fmin(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None,
full_output=0, disp=1, retall=0, callback=None)
Minimize a function using the downhill simplex algorithm.
Parameters
----------
func : callable func(x,*args)
You can use IPython's ? syntax to get information about any object:
optimize.fmin?
That will work in all IPython environments.
However, scipy.info() and numpy.info() both work in the Qt console when I try them, whether or not I start it in pylab mode. I'm not sure why they don't for you.

Resources