0

call TOUGH in jupyter notebook and PyTOUGH

Hi All,

I am using PyTOUGH to automate TOUGH simulation. However, when I try to call TOUGH in Jupyter notebook with this command 

subprocess.call(["path_to_my_tough3_executable(tough3-eos1)", "horiz1D.dat"])

I got the error below

WindowsError: [Error 193] %1 is not a valid Win32 application

If I run the model from the Ubuntu terminal, it will run successfully. Does any one have any idea what is causing this error? 

Thanks,

Haiyan

15 replies

null
    • kenny
    • 10 mths ago
    • Reported - view

    The system clearly indicated that the executable you used is not a Window application. You mentioned that you can run it under Ubuntu terminal which means the executable is compiled under Linux system. You need recompiled it under Windows system. 

    • Haiyan_Zhou
    • 10 mths ago
    • Reported - view

    Thanks for your reply Kenny. You are right that my TOUGH3 is compiled through Ubuntu which is installed in Windows system. I thought this would allow me to call it through Python.

    • Haiyan_Zhou
    • 10 mths ago
    • Reported - view

    In order to compile TOUGH under Windows system. Do I follow the instruction "readme_cygwin.pdf"?

    Thanks,

    Haiyan

    • kenny
    • 10 mths ago
    • Reported - view

    You need to compile the code with Visual Studio or "make" command under DOS command line. you can find introduction in the readme file in V1.1. 

    • Haiyan_Zhou
    • 10 mths ago
    • Reported - view

    Thanks Kenny.

    I have one more question. There are "PC_executables' in the installation files. I am wondering what is the difference between these existing executables and the recompiles ones? I tried one of them and it ran well.

    • kenny
    • 10 mths ago
    • Reported - view

    Should be the same. You can use them.

    • Haiyan_Zhou
    • 10 mths ago
    • Reported - view

    I tried the eos1 executable (tough3_v1.1/PC_executables/tough3_eos1_pc.exe) and it worked. However, 'tough3_eos7c_pc.exe' seems not working. The simulation stopped after reading the input file (please see attached OUTPUT). I tested the input file by running it with the Ubuntu compiled executable and it ran well. Any idea what is going wrong?

    Thanks,

    Haiyan

    • yqzhang
    • 10 mths ago
    • Reported - view

    I did not look at your output file.

    But I have a quick guess: you probably either used a wrong input file, or did not delete the MESHA, MESHB in your directory so you are using the wrong MESH. Check what files are in the directory and see if they are what you expect.

    • Haiyan_Zhou
    • 10 mths ago
    • Reported - view

    Hi Yingqi,

    Thanks for your reply. I did remove all other files and only GENER, INFILE and INCON are included in the folder. The end of the OUTPUT file looks like below

    ------------------------------------------------------------------------------------------------
     PER(1) = *** scale factor (optional) for internally generated  permeability modifiers.
            = 0: (defaults to PER(1) = 1): permeability modifiers are generated as random numbers in the interval (0, 1).
            > 0: permeability modifiers are generated as random numbers in the interval (0, PER(1)).

     PER(2) = *** shift (optional) for internal or external permeability modifiers.
            = 0: (default) no shift is applied to permeability modifiers.
            > 0: permeability modifiers are shifted according to m' = m - PER(2). All m' < 0 are set equal to zero.

     


     

    • Keurfon_Luu
    • 10 mths ago
    • Reported - view

    If you want to run TOUGH from Ubuntu Terminal within a Windows shell (e.g., cmd.exe), you can prepend "bash -c" to your Linux command, for instance:

    bash -c '/path/to/tough3-install/bin/tough3-eos1 INFILE OUTPUT'

    That command works with subprocess as well.

    Note that the next update of toughio will include such function.

      • Haiyan_Zhou
      • 10 mths ago
      • Reported - view

      Keurfon Luu Thanks for your reply. To clarify, my executable (eos7c in this case) is compiled through Ubuntu installed in a Windows system. Now I want to call the executable in Jupyter notebook through subprocess.

      I tried the subprocess command as below

      popen = subprocess.Popen([bash -c 'my_path_to/tough3-eos7c'], stdout=subprocess.PIPE)

      It returned the error "invalid syntax". 

      Can you please provide more detail about the command?

      Thanks,

      Haiyan
       

      • Keurfon_Luu
      • 10 mths ago
      • Reported - view

      Haiyan Zhou Try passing your command as a string (instead of a list) and set shell=True:

      subprocess.run('bash -c "/path/to/tough3-eos7c"', shell=True)

      You can also check the code here: toughio/_run.py at devel · keurfonluu/toughio · GitHub

    • Haiyan_Zhou
    • 10 mths ago
    • Reported - view

    I replaced subprocess.run with subprocess.call (I am using Anaconda2). But still it doesn't work. I got output of '1' without detailed error message. Do I need Anaconda3 to run this?

    Thanks,

      • Keurfon_Luu
      • 10 mths ago
      • Reported - view

      Haiyan Zhou You also need to pass your input file in the argument. Basically, subprocess first argument is the command you would type in a terminal. First, try the command in cmd.exe, 

      bash -c "/path/to/tough3-eos7c my_input_file"
      
      • Haiyan_Zhou
      • 10 mths ago
      • Reported - view

      Keurfon Luu My input file name is the default 'INFILE' and I thus don't define the input file name in the command. 

Content aside

  • 10 mths agoLast active
  • 15Replies
  • 92Views
  • 4 Following