ochubar / Radia

3D Magnetostatics Computer Code
Other
34 stars 19 forks source link

How to install Radia in Python as a package in windows 10? #7

Open loveinthebone opened 4 years ago

loveinthebone commented 4 years ago

Hi,

I would really like to use Radia in Python as I don't have access to Mathematica. I didn't find Radia with "pip install". I also tried to download the whole project, cd to the C:\Radia\Radia-master\cpp\py folder, then run "python setup.py install", got this commend line error: C:\Radia\Radia-master\cpp\py>python setup.py install running install running bdist_egg running egg_info writing Radia_Python_Interface.egg-info\PKG-INFO writing dependency_links to Radia_Python_Interface.egg-info\dependency_links.txt writing top-level names to Radia_Python_Interface.egg-info\top_level.txt reading manifest file 'Radia_Python_Interface.egg-info\SOURCES.txt' writing manifest file 'Radia_Python_Interface.egg-info\SOURCES.txt' installing library code to build\bdist.win32\egg running install_lib running build_ext building 'radia' extension C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMAJOR_VERSION=1 -DMINOR_VERSION=0 -IC:\Radia\Radia-master\cpp\src\lib -IC:\Radia\Radia-master\cpp\src\ext\auxparse -IC:\Radia\Radia-master\cpp\src\core -IC:\Users\szhou\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\szhou\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /EHsc /TpC:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp /Fobuild\temp.win32-3.8\Release\Radia\Radia-master\cpp\src\clients\python\radpy.obj radpy.cpp c:\radia\radia-master\cpp\src\clients\python\pyparse.h(592): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(346): note: see declaration of 'strncpy' c:\radia\radia-master\cpp\src\clients\python\pyparse.h(665): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(346): note: see declaration of 'strncpy' C:\Radia\Radia-master\cpp\src\ext\auxparse\auxparse.h(424): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\ext\auxparse\auxparse.h(426): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\ext\auxparse\auxparse.h(427): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(31): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(31): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(48): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(51): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(55): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(56): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(57): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(78): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(81): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(85): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(86): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(87): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(105): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(106): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(107): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(109): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(90): note: see declaration of 'strcat' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(281): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(537): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(1028): warning C4244: 'initializing': conversion from 'int64' to 'unsigned int', possible loss of data C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(1073): warning C4244: 'initializing': conversion from 'int64' to 'unsigned int', possible loss of data C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(2762): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(2766): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(119): note: see declaration of 'strcpy' C:\Radia\Radia-master\cpp\src\clients\python\radpy.cpp(3075): warning C4800: 'char': forcing value to bool 'true' or 'false' (performance warning) C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Radia\Radia-master\cpp\gcc /LIBPATH:C:\Radia\Radia-master\ext_lib /LIBPATH:C:\Users\szhou\AppData\Local\Programs\Python\Python38-32\libs /LIBPATH:C:\Users\szhou\AppData\Local\Programs\Python\Python38-32\PCbuild\win32 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86" radia.lib m.lib fftw.lib /EXPORT:PyInit_radia build\temp.win32-3.8\Release\Radia\Radia-master\cpp\src\clients\python\radpy.obj /OUT:build\lib.win32-3.8\radia.cp38-win32.pyd /IMPLIB:build\temp.win32-3.8\Release\Radia\Radia-master\cpp\src\clients\python\radia.cp38-win32.lib LINK : fatal error LNK1181: cannot open input file 'radia.lib' error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\link.exe' failed with exit status 1181

I didn't run the Makefile file in the "C:\Radia\Radia-master\cpp\py" folder, is it the problem? I am sorry that I don't have any software design background. A short description of what I should do before I can use the examples in the folder "C:\Radia\Radia-master\env\radia_python" in windows is much appreciated.

Bests, Kingson

ochubar commented 4 years ago

On Linux, try to run from the main Radia directory (can be "Radia-master" in you case): "make all" or "make all MODE=mpi"

On Windows, try to use the pre-compiled "radia.pyd" for Python 3.6 or 2.7 64 bit. Just install one of these Py versions, and execute some examples e.g. as: python RADIA_Example03.py from the directory ../env/radia_python. You may need to rename some files. e.g. "copy radia_py2_7_x64.pyd radia.pyd". And/or you can use MS Visual C++ projects from ../cpp/vc to build shared library (.pyd file) for another version of Python.

We'll make it pip-installable in the future, after finishing series of tests.

loveinthebone commented 4 years ago

Hi Oleg,

Thank you for your reply! I did what you suggested. Installed Python 2.7 64 bit (I had Python 3.8 installed in my PC), renamed "radia_py2_7_x64.pyd" to "radia.pyd", run the "RADIA_Example01.py" example in Python 2.7, and got this error: File "c:/Radia/Radia-master/env/radia_python/RADIA_Example01.py", line 8, in import radia as rad ImportError: DLL load failed: The specified module could not be found.

I searched online, this error seems to suggest the .pyd file may depend on some additional libraries called DLLs that is not in the same folder or in the system.PATH. I guess this issue is difficult to solve for me as the DLLs are not in the folder c:/Radia/Radia-master/env/radia_python

I understand that you want to publish the pip-installable version after fully tested it. However, I really would like to use Radia to do some magnetic force simulation following some positive comments about Radia from literature. Could you send me a beta version, say a Wheel package to me? So that I can directly pip install wheel_package, and directly use the module?

In the mean time, I will install the MS visual C++, and learn to use the second method you mentioned.

Thanks again, Kingson

bnash commented 4 years ago

Hello Kingson,

Another option you may consider for running Radia is to use the RadiaSoft Jupyter server, which is freely available at https://jupyter.radiasoft.org. Radia is already installed when you log in, and you may thus use it via the Python interface. We have been translating the Python examples into Jupyter notebooks, which give many of the same interactive capabilities that Mathematica provides. We are also developing 3-D interactive graphics capabilities which are accessible via Jupyter notebooks.

The Jupyter notebooks we are developing are available in this repository: https://github.com/radiasoft/Radia-Examples To access a GitHub repository on Jupyter, you may start a unix terminal session (click on the plus icon at the top left, below the menus and select Terminal). In the terminal, you would type git clone https://github.com/radiasoft/Radia-Examples.git

Have a look at the Radia_Ex05-widget.ipynb notebook which allows solving and visualization of the Example 5 dipole.

Let me know if this works and I'm glad to provide further assistance. Regards, Boaz

loveinthebone commented 4 years ago

Hi Boaz,

Your reply made my day! Your solution works perfectly! I recommend everyone who is unable or don't want to dig into the technical detail inside Radia try your solution!

Best regards, Kingson

mahu21 commented 1 year ago

Hi Boaz,

Your reply made my day! Your solution works perfectly! I recommend everyone who is unable or don't want to dig into the technical detail inside Radia try your solution!

Best regards, Kingson

Hi Kingson. Which solution worked for you? The Git Clone, or the RadiaSoft? For Git Clone still the radia Module is needed, isn't it? As for the Radiasoft, my access to Jupyterhub is still pending...

mahu21 commented 1 year ago

On Linux, try to run from the main Radia directory (can be "Radia-master" in you case): "make all" or "make all MODE=mpi"

On Windows, try to use the pre-compiled "radia.pyd" for Python 3.6 or 2.7 64 bit. Just install one of these Py versions, and execute some examples e.g. as: python RADIA_Example03.py from the directory ../env/radia_python. You may need to rename some files. e.g. "copy radia_py2_7_x64.pyd radia.pyd". And/or you can use MS Visual C++ projects from ../cpp/vc to build shared library (.pyd file) for another version of Python.

We'll make it pip-installable in the future, after finishing series of tests.

Hello Oleg, I wanted to ask, if Radia Module already can be installed for python?

Iamdonesearching commented 4 months ago

Hello Oleg, I am very interested in the Python version, but no matter what I try, I am unable to install the radia module. Can you tell me how to do it? Is it possible to have a pip-installable version? Thank you in advance. I am very excited to be able to use radia on python. Kind regards, Maxime

robnagler commented 4 months ago

@Iamdonesearching here is a simplified version of the script we use to install Radia for us for Sirepo Radia:

#!/bin/bash
set -eou pipefail
git clone https://github.com/ochubar/Radia
cd Radia
find . -name \*.so -o -name \*.a -o -name \*.pyd -exec rm {} \;
rm -rf ext_lib
perl -pi - cpp/py/setup.py <<'EOF'
        s/\bfftw/sfftw/;
        s/mpi_cxx/mpi/;
        s{/usr/lib/openmpi/lib}{/usr/lib64/mpich/lib}g;
        s{/usr/lib/openmpi/include}{/usr/include/mpich-x86_64}g;
EOF
perl -pi -e '
        s/-lfftw/-lsfftw/;
        s/\bcc\b/mpicc/;
        s/\bc\+\+/mpicxx/;
        # The MODE flag hardwires includes incorrectly
        s/^(LIBCFLAGS\s*=)/$1 -D_WITH_MPI /;
' cpp/gcc/Makefile
patch cpp/src/clients/python/pyparse.h <<'EOF'
@@ -17,7 +17,7 @@
 //#include <cstring>

 using namespace std;
-
+#define PY_SSIZE_T_CLEAN
 //Without the following Python.h will enforce usage of python**_d.lib in dbug mode, which may not be always existing
 //NOTE: to make it compilable with VC2013 (VC12), that blcock had to be moved down and placed after the previous includes
 #if defined(_DEBUG)
EOF
cd cpp/gcc
make "-j$(codes_num_cores)" lib
cd ../py
MODE=mpi python setup.py build_ext
install -m 644 "$(find . -name radia*.so)" $(python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')

I extracted the code into this comment, but did not test it. The script should exit at the first error if there is one. LMK if you have questions. Switching to a pip-installable Radia is quite a bit of work, unfortunately.

ochubar commented 4 months ago

Hello Maxime,

Thanks for your interest to Radia. Please try the following:

install Python 3.12 64 bit (~most recent Py) on your Windows 10, add scipy and matplotlib; download this file from GitHub: https://github.com/ochubar/Radia/blob/master/env/radia_python/radia_py3_12_x64.pyd copy it to your "radia_python" folder (you should have it after downloading all Rudia stuff from GitHub); rename radia_py3_12_x64.pyd to radia.pyd; * try running RADIA_Example01.pyhttps://github.com/ochubar/Radia/blob/master/env/radia_python/RADIA_Example01.py inside radia_python, and other examples.

Let us know if this helped. We are working on making Radia "pip install"-able.

O.Chubar BNL / NSLS-II


From: Rob Nagler @.> Sent: Friday, June 14, 2024 11:31 AM To: ochubar/Radia @.> Cc: Tchoubar, Oleg @.>; Comment @.> Subject: Re: [ochubar/Radia] How to install Radia in Python as a package in windows 10? (#7)

@Iamdonesearchinghttps://github.com/Iamdonesearching here is a simplified version of the scripthttps://github.com/radiasoft/download/blob/bb114a8ded4f6355f33175f808bb7fce3b5e15a3/installers/rpm-code/codes/radia.sh we use to install Radia for us for Sirepo Radiahttps://urldefense.com/v3/__https://www.sirepo.com/radia__;!!P4SdNyxKAPE!G8E8b360PBcEKV30nMlJUYtOeNhwcygAvtxfKcDd_wzyK4WzcTqZRFFyw17ZBmcZGpWzBaj8r9_YeD4fLSOJrFk$:

!/bin/bash

set -eou pipefail git clone https://github.com/ochubar/Radia cd Radia find . -name *.so -o -name *.a -o -name *.pyd -exec rm {} \; rm -rf ext_lib perl -pi - cpp/py/setup.py <<'EOF' s/\bfftw/sfftw/; s/mpi_cxx/mpi/; s{/usr/lib/openmpi/lib}{/usr/lib64/mpich/lib}g; s{/usr/lib/openmpi/include}{/usr/include/mpich-x86_64}g; EOF perl -pi -e ' s/-lfftw/-lsfftw/; s/\bcc\b/mpicc/; s/\bc++/mpicxx/;

The MODE flag hardwires includes incorrectly

    s/^(LIBCFLAGS\s*=)/$1 -D_WITH_MPI /;

' cpp/gcc/Makefile patch cpp/src/clients/python/pyparse.h <<'EOF' @@ -17,7 +17,7 @@ //#include

using namespace std;

+#define PY_SSIZE_T_CLEAN //Without the following Python.h will enforce usage of python**_d.lib in dbug mode, which may not be always existing //NOTE: to make it compilable with VC2013 (VC12), that blcock had to be moved down and placed after the previous includes

if defined(_DEBUG)

EOF cd cpp/gcc make "-j$(codes_num_cores)" lib cd ../py MODE=mpi python setup.py build_ext install -m 644 "$(find . -name radia*.so)" $(python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')

I extracted the code into this comment, but did not test it. The script should exit at the first error if there is one. LMK if you have questions. Switching to a pip-installable Radia is quite a bit of work, unfortunately.

— Reply to this email directly, view it on GitHubhttps://github.com/ochubar/Radia/issues/7#issuecomment-2168277994, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAXFEGGNF43EPA6Q4TRKPZTZHMEEJAVCNFSM6AAAAABJKMEMUCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRYGI3TOOJZGQ. You are receiving this because you commented.Message ID: @.***>

Iamdonesearching commented 4 months ago

@ochubar @robnagler Dear Oleg, Dear Robnagler,

Thank you very much for your help. I managed to run all the examples and I am now able to import Radia into my Python environment. I am excited to start working with Radia!

Thanks again for your help.

Best regards, Maxime