Importing Python data to Julia

464 views
Skip to first unread message

Corbin Foucart

unread,
Oct 18, 2016, 4:42:51 PM10/18/16
to julia-users
Suppose that I have a large Python code; I would like to use Julia to operate on the python workspace variables at certain locations in the code. What occurs to me is to either:

1) write out all python workspace data to file, read data into julia, operate, save, read back into python (seems bad)
2) Call Julia code directly from python (I don't want to perform some trivial computation as in the examples I've found, I want to operate on the lists of numpy arrays)

Is there an efficient or documented way to do this?

Cedric St-Jean

unread,
Oct 18, 2016, 4:56:14 PM10/18/16
to julia-users
Could you provide a more concrete example of what you're trying to do?

cdm

unread,
Oct 18, 2016, 5:11:48 PM10/18/16
to julia-users
were the examples you found related to use of PyJulia ... ?

Steven G. Johnson

unread,
Oct 18, 2016, 7:50:03 PM10/18/16
to julia-users


On Tuesday, October 18, 2016 at 4:42:51 PM UTC-4, Corbin Foucart wrote:
2) Call Julia code directly from python (I don't want to perform some trivial computation as in the examples I've found, I want to operate on the lists of numpy arrays)

pyjulia can do this. 

Corbin Foucart

unread,
Oct 18, 2016, 8:46:16 PM10/18/16
to julia-users
Yes, I am modifying a finite element code written in python. I would like to perform the operator assembly in Julia rather than python. This will require parsing the finite element data in numpy format. I would like to implement an iterative linear solver on the the global linear system, and such a solver would be much faster in Julia as well. 

Corbin Foucart

unread,
Oct 18, 2016, 8:48:01 PM10/18/16
to julia-users
Yes, they were. Is there documentation for pyjulia? I have not found any other than their Readme file...

Christoph Ortner

unread,
Oct 19, 2016, 1:57:53 AM10/19/16
to julia-users
a collaborator of mine is using pyjulia in a similar way - implement reasonably fast interatomic potentials in Julia, but use all the tools available in Python for model setup etc. 

In case it helps, you can look at 
as an example.

Corbin Foucart

unread,
Oct 25, 2016, 12:05:47 AM10/25/16
to julia-users
How? If you don't mind my asking. It doesn't seem that documentation exists... Suppose in a python script, I have:

[python imports]
[pyjulia initialization]
j = julia.Julia()

randMat = np.random.rand(3, 3)
# what should I put here to pass randMat to julia?
result = j.eval("inv(julia_randmat)") 

# ^^^ is this how I would move the result back to python?

Christoph Ortner

unread,
Oct 25, 2016, 6:36:25 AM10/25/16
to julia-users
I haven't tried, but I think it should be 

result = j.inv(randMat)

Corbin Foucart

unread,
Oct 25, 2016, 10:04:01 AM10/25/16
to julia-users
That worked; thanks! 

Steven G. Johnson

unread,
Oct 25, 2016, 9:26:02 PM10/25/16
to julia-users
Don't evaluate Julia code as strings. Just call Julia functions directly.

j.inv(randMat)

should work

Reply all
Reply to author
Forward
0 new messages