I am attempting to use the Python interop capabilities in DWSIM on Linux. I have followed danwbr's advice elsewhere regarding known working OS/DWSIM version combinations.
(here I just copied the contents of sys.path. I had previously passed less expansive PYTHONPATHs to DWSIM but encountered import errors, so I just threw everything at it.)
I have Cantera installed from the relevant Ubuntu PPA.
This seems to have obtained the most progress so far, however when I try to run a flowsheet with a Python unit operation (e.g. any of the Cantera interop examples) I get the following in the console:
[30/12/2021 3:57:59 PM] Errors occurred during the calculation of the flowsheet, please read the following messages for more details. [30/12/2021 3:57:59 PM] Attempted to access a missing member.
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet (System.Object o, System.Type objType, System.String name, System.Object[] args, System.String[] paramnames, System.Boolean[] CopyBack) [0x000bb] in <4db44276fe2442e2b0c7756aa8b4da57>:0
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet (System.Object Instance, System.Type Type, System.String MemberName, System.Object[] Arguments, System.String[] ArgumentNames, System.Type[] TypeArguments, System.Boolean[] CopyBack) [0x00001] in <4db44276fe2442e2b0c7756aa8b4da57>:0
at DWSIM.UnitOperations.UnitOperations.CustomUO.Calculate (System.Object args) [0x00bbe] in <7ac97081153f4b1f90ffaf1c18224695>:0
At this point I'm not sure if this is the result of a misconfiguration on my part, or is due to a bug in DWSIM. I can cut down the Python script to a trivial example (e.g. a = 1) and get the same error.
Any help that the community can provide in diagnosing and/or resolving this issue is appreciated.
Kind regards,
-r
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've tried DWSIM 7.2 and Python seems to work in the minimal case, in the Cantera Interop example (and other Cantera examples) I get the following:
'numpy.float64' value cannot be converted to System.Double in method Void .ctor(Double)
I was able to track this down to the casts in lines 83–88 of the Python unit operation in Cantera Interop.dwxmz, and I was able to solve this by casting the output variables to float, e.g.:
I'm not sure if this is a problem with DWSIM, Python.NET, or Cantera/NumPy. At any rate the simulation runs fine with these changes, and so hopefully it will work with our production code (fingers crossed). However I thought you might like to know.
Versions are:
Numpy 1.22.1
Cantera 2.6.0a4
Both from PyPI
Running on Python 3.8 on Ubuntu 20.04
Thank you very much for your help, I really appreciate it.
-r
Last edit: rterrett 2022-01-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am attempting to use the Python interop capabilities in DWSIM on Linux. I have followed danwbr's advice elsewhere regarding known working OS/DWSIM version combinations.
DWSIM version: 7.1.2 (the Ubuntu .deb)
OS: Ubuntu 20.04.2 x86_64
Python: 3.8.10
PYTHONPATH: '/usr/lib/python38.zip:/usr/lib/python3.8:/usr/lib/python3.8/lib-dynload:/home/rterrett/.local/lib/python3.8/site-packages:/usr/local/lib/python3.8/dist-packages:/usr/lib/python3/dist-packages'
(here I just copied the contents of sys.path. I had previously passed less expansive PYTHONPATHs to DWSIM but encountered import errors, so I just threw everything at it.)
PYTHONNET_PYDLL: '/usr/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.so'
DWSIM Python interpreter: Python.NET
I have Cantera installed from the relevant Ubuntu PPA.
This seems to have obtained the most progress so far, however when I try to run a flowsheet with a Python unit operation (e.g. any of the Cantera interop examples) I get the following in the console:
At this point I'm not sure if this is the result of a misconfiguration on my part, or is due to a bug in DWSIM. I can cut down the Python script to a trivial example (e.g. a = 1) and get the same error.
Any help that the community can provide in diagnosing and/or resolving this issue is appreciated.
Kind regards,
-r
This is probably an issue with mono... try these commands so we can discover the code line where the error is being raised:
then paste the error message here again.
Regards
Daniel
Last edit: Daniel Medeiros 2021-12-30
Hi,
Hopefully I'm doing this right. Attempted to run the Cantera interop example:
Thanks for your attention to this.
Regards,
-r
Yes you did:
C:\Users\Daniel\source\repos\DanWBR\dwsim\DWSIM.UnitOperations\UnitOperations\PythonScriptUO.vb:347
Last edit: Daniel Medeiros 2021-12-30
This will need a code change from my part. It will work in the next release.
Thanks
Daniel
Hi, thanks for checking this out.
Regards,
-r
Hi,
I've tried DWSIM 7.2 and Python seems to work in the minimal case, in the Cantera Interop example (and other Cantera examples) I get the following:
'numpy.float64' value cannot be converted to System.Double in method Void .ctor(Double)
I was able to track this down to the casts in lines 83–88 of the Python unit operation in Cantera Interop.dwxmz, and I was able to solve this by casting the output variables to float, e.g.:
oms1.Phases[0].Compounds['Methane'].MoleFraction = System.Nullable[System.Double](outCH4)
to:
oms1.Phases[0].Compounds['Methane'].MoleFraction = System.Nullable[System.Double](float(outCH4))
I'm not sure if this is a problem with DWSIM, Python.NET, or Cantera/NumPy. At any rate the simulation runs fine with these changes, and so hopefully it will work with our production code (fingers crossed). However I thought you might like to know.
Versions are:
Numpy 1.22.1
Cantera 2.6.0a4
Both from PyPI
Running on Python 3.8 on Ubuntu 20.04
Thank you very much for your help, I really appreciate it.
-r
Last edit: rterrett 2022-01-16