Jump to content
qchen

How to import third party Python module in Flux

Recommended Posts

Hi,

 

I want to use a 3rd party Python module (numpy, which I successfully installed in Python 2.7) in Flux. When I tried ' import numpy' in command prompt in Flux the error comes as

 

Can not execute the following command :
import numpy

Problem to import the module : numpy
Enter sys.path to see if this module is accessible from your jython session
 

I guess my problem is the 3rd party module is not installed in C:\Altair\Flux_12.3\Third_party\python. So how can I install and use 3rd party Python modules in Flux?

 

Kind regards,

 

Chen

Share this post


Link to post
Share on other sites
2 hours ago, Flux support said:

You are welcome. For your information this will be available in Flux 2018.1,which will be available soon.

Best regards.

 

That's great!

 

Actually I (and many other Flux users I believe) find out there is little information about using Python to manipulate Flux, which is a very powerful way to make more use of Flux. If the Flux development group can provide more material/tutorials on this subject in the future, it's going to be very helpful for Flux users, especially for those who already have some knowledge of Python. 

 

Kind regards,

 

Chen

Share this post


Link to post
Share on other sites

Hi, 

 

I definitely agree with qchen regarding the doc :-)

I have a similar question:

I'm trying to import one of my scripts (imprtScrpt.py) in another script (mainScrpt.py). The imported script only contains functions.

The only solution that I've found until now is to call "executeBatchSpy('imprtScrpt.py')" in mainScrpt. When I simply try "import imprtScrpt", mainScrpt exits without any message.

 

Am I doing something wrong?

 

Thank you very much in advance for your help!

 

PS: until now, I've been ok with importing by using executeBatchSpy, but my script is starting to get quite big and I'd like to use imports to use profiling tools (such as doxy).

Louis Carlioz likes this

Share this post


Link to post
Share on other sites
On 1/22/2019 at 11:33 AM, Romain B said:

I'm trying to import one of my scripts (imprtScrpt.py) in another script (mainScrpt.py). The imported script only contains functions.

The only solution that I've found until now is to call "executeBatchSpy('imprtScrpt.py')" in mainScrpt. When I simply try "import imprtScrpt", mainScrpt exits without any message.

 

I would like to get an answer to the same question as well.

Share this post


Link to post
Share on other sites

Hi,

the link in previous discussion with the file "how to use Numpy in flux" seem to do not work anymore. Can you upload the document again?

Thank you.

 

Share this post


Link to post
Share on other sites
On ‎3‎/‎24‎/‎2020 at 3:01 PM, Abdessamed said:

Hi, it seems the link doesn't work yet.

Could you fix it?

Thanks

Share this post


Link to post
Share on other sites

The link work fine just it is available in Flux 2020.

How to Experiment with NumPy in Flux?

 

Introduction

NumPy is a Python module widely used in scientific computing area and could improve the capacity of what Flux users could achieve when they write PyFlux scripts.

However, NumPy is a native C-Python module whereas PyFlux scripts are executed by Jython, a Java Python interpreter, which is not able to execute C Python modules thus preventing NumPy usage with Flux.

Nowadays a third-party project named JyNI (Jython Native Interface) provides an experimental solution to execute native C Python with the Jython interpreter, starting with Jython 2.7.1

Since Flux 2018.1 release, Flux has been upgraded to use Jython 2.7.1 and it becomes possible to use the JyNI library to experiment with native C Python modules like NumPy.

Disclaimer

The JyNI library is a third-party library which is still in alpha version and NumPy support with Jython remains experimental. This means that Altair is not responsible for maintaining or fixing bugs related to NumPy integration with JyNI and Jython.

Besides, usage of NumPy with Flux has not been qualified in the current release and nothing has been made to allow a smooth and seamless integration of NumPy with Flux. On the contrary there are known limitations and issues: See the Troubleshooting section for more details.

Prerequisite

Using NumPy with Flux requires the users to download the following third-party libraries:

Step-by-step

Follow the steps below to install and configure NumPy for Flux:
  1. Ensure that no other CPython or NumPy module is already installed on the machine
  2. Install CPython 2.7.1
  3. Create a UserDLL directory to store the additional DLLs that will be required to use NumPy with Flux. For example: %INSTALLFLUX%\Third_party\jython-2.7.1\userdll
  4. Create a UserLib directory to store the additional Python module required to use NumPy. For example: %INSTALLFLUX%\Third_party\jython-2.7.1\userlib
  5. Install JyNI
    1. Copy JyNI.jar into: %INSTALLFLUX%\Third_party\jython-2.7.1\javalib
    2. Extract the JyNI.dll folder from the platform-specific archive into your UserDLL directory. Be careful to copy the JyNI.dll folder ifself (not only its content) inside the UserDLL directory
  6. Install NumPy
    1. Unzip the numpy-13.3.3-cp27-xxx.whl archive into your UserLib folder
    2. Look for the NumPy DLL inside: <UserLib>/numpy/core

      and copy it to your UserDLL folder

      The name of the DLL to copy depends on the platform-specific archive you downloaded. For example for windows 64 it is named:

      libopenblas_v0.2.20_mingwpy.dll

  7. Starts Flux Supervisor
  8. Configure the Flux Supervisor options to use your UserDLL and UserLib folders for all Flux modules (2D, 3D, Skew, PEEC)
    1. Open the Options dialog by clicking on the Options button in the bottom left
      experiment1.png
    2. In the dialog’s navigation tree select the Access Paths > Python node
    3. Enter the User Python scripts directory by typing the path to your UserLib folder
    4. Enter the User libraries directory by typing the path to your UserDLL folder
    5. Apply the changes and close the dialog by clicking OK
  9. Start Flux from the Supervisor
  10. In Flux, test you can use NumPy functions
    1. In the PyFlux shell enter the following Python code to define a 3x5 matrix and print it in the console:
      experiment2.png
    2. Execute the code by clicking on the red arrow on the left of the PyFlux shell

      You should see the following output in the Flux console:

      [[ 0 1 2 3 4]

      [ 5 6 7 8 9]

      [10 11 12 13 14]]

Troubleshooting

  • Flux does not start any more after I configured NumPy for Flux
    • What should I do?

      Look at Flux Supervisor Options and ensure that you have configured the User libraries directory for the module (2D,3D, Skew, PEEC) you are trying to use, even if you do not want to use NumPy for this specific module.

    • Why do I have to do this?

      After you have applied step 5a and copied the JyNI.jar in

      %INSTALLFLUX%\Third_party\jython-2.7.1\javalib

      then this jar is loaded automatically whenever you start Flux regardless of the module you choose. Because this jar requires access to the JyNI.dll then you must configure the User libraries directory for all modules otherwise the jar will fail to be loaded and Flux won’t start.

  • Flux Server does not start any more after I configured NumPy
    • What should I do?

      To fix Flux Server, you need to remove the JyNI.jar from the directory:

      %INSTALLFLUX%\Third_party\jython-2.7.1\javalib

      But then you won’t be able to use NumPy in Flux any more. This is a known limitation in this release and it means that currently you must choose between using NumPy or using Flux Server, but you cannot have both at the same time.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...