Quantcast

Calling Julia code from Python

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Calling Julia code from Python

Alexei Serdiuk
Hi,

I'm new to Julia and, unfortunately, I'm almost zero to Python. 
I need to call Julia code from Python. This code must do some operations and then return it back to Python.

I have an example for calling Java:
def solve_it(input_data):


   
# Writes the inputData to a temporay file


    tmp_file_name
= 'tmp.data'
    tmp_file
= open(tmp_file_name, 'w')
    tmp_file
.write(input_data)
    tmp_file
.close()


   
# Runs the command: java Solver -file=tmp.data


    process
= Popen(['java', 'Solver', '-file=' + tmp_file_name], stdout=PIPE)
   
(stdout, stderr) = process.communicate()


   
# removes the temporay file
    os
.remove(tmp_file_name)


   
return stdout.strip()


Would you please help me to create this code for Julia?
Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling Julia code from Python

Steven G. Johnson


On Wednesday, November 2, 2016 at 2:43:27 PM UTC-4, Alexei Serdiuk wrote:
I'm new to Julia and, unfortunately, I'm almost zero to Python. 

An unfortunate combination — better to learn one programming language before you deal with inter-language calling.
 
I need to call Julia code from Python. This code must do some operations and then return it back to Python.

Google "pyjulia"
 
I have an example for calling Java:

That code is calling Java by piping the input and output through files and popen.  You can do the exact same thing with Julia too, of course, but pyjulia is far more efficient: it calls Julia as a library, within the same process, and can even pass large arrays without making copies. 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling Julia code from Python

Jeffrey Sarnoff
Alexi,

While you may want it to be otherwise, Steven is right.  There have been a few programming languages that were designed to be useful with very little instruction.  Julia, Python, Java, and most other modern languages are not that way.  And while it would be great if there really were a forthcoming interlingua .. there is not, not today anyway.  The best advice any of us could give you is to revisit the reason that you find a need to do this that way, and find an alternative way to satisfy that expectation.  No reasonable teacher or manager would expect you to make that happen without much more experience.  And once you have the experience, you would probably still want to choose a different way to work this.

with some simpatico


On Wednesday, November 2, 2016 at 6:21:20 PM UTC-4, Steven G. Johnson wrote:


On Wednesday, November 2, 2016 at 2:43:27 PM UTC-4, Alexei Serdiuk wrote:
I'm new to Julia and, unfortunately, I'm almost zero to Python. 

An unfortunate combination — better to learn one programming language before you deal with inter-language calling.
 
I need to call Julia code from Python. This code must do some operations and then return it back to Python.

Google "pyjulia"
 
I have an example for calling Java:

That code is calling Java by piping the input and output through files and popen.  You can do the exact same thing with Julia too, of course, but pyjulia is far more efficient: it calls Julia as a library, within the same process, and can even pass large arrays without making copies. 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling Julia code from Python

Harish Kumar
In reply to this post by Alexei Serdiuk
Use pyjulia package. Convert your data set to list of list and pass to Julia

On Wednesday, November 2, 2016 at 1:43:27 PM UTC-5, Alexei Serdiuk wrote:
Hi,

I'm new to Julia and, unfortunately, I'm almost zero to Python. 
I need to call Julia code from Python. This code must do some operations and then return it back to Python.

I have an example for calling Java:
def solve_it(input_data):


   
# Writes the inputData to a temporay file


    tmp_file_name
= 'tmp.data'
    tmp_file
= open(tmp_file_name, 'w')
    tmp_file
.write(input_data)
    tmp_file
.close()


   
# Runs the command: java Solver -file=tmp.data


    process
= Popen(['java', 'Solver', '-file=' + tmp_file_name], stdout=PIPE)
   
(stdout, stderr) = process.communicate()


   
# removes the temporay file
    os
.remove(tmp_file_name)


   
return stdout.strip()


Would you please help me to create this code for Julia?
Thanks.
Loading...