Compare commits

...

12 Commits

Author SHA1 Message Date
Samer Afach f1def0d923 Update setup.py 2018-10-18 10:21:10 +02:00
Samer Afach f08f376108 Update README.md 2017-09-05 09:27:11 +02:00
Samer Afach 6853fcac4b Update README.md 2017-09-05 09:24:17 +02:00
Samer Afach 35747ff6ff Added LICENSE to MANIFEST.in 2017-09-02 22:01:45 +02:00
Samer Afach 20f257a368 Updated licensing 2017-09-02 21:57:32 +02:00
Samer Afach 0bbadd8a40 Updated README.md 2017-09-02 21:14:30 +02:00
Samer Afach 787b1498dc Added bash prefix to get_resources.sh call to make it work without making it executable 2017-01-14 19:06:02 +01:00
Samer Afach 7a07d2c8c8 Fix README.md heads 2017-01-14 12:33:01 +01:00
Samer Afach d5225ddc0a Modified README.md 2017-01-14 12:27:32 +01:00
Samer Afach 0729aae8a6 Moved to version 0.2.1 2017-01-14 11:05:47 +01:00
Samer Afach 86acf5f287 Removed asking about optimization to support pip 9.0+, which has a non-verbose mode. 2017-01-13 18:04:49 +01:00
Samer Afach 47d1516fa2 More flushes 2017-01-13 17:51:53 +01:00
7 changed files with 74 additions and 36 deletions

13
LICENSE.txt Normal file
View File

@ -0,0 +1,13 @@
This license is the license that determines the terms of using any version of Spintrum up to this one, unless otherwise stated in newer versions.
Spintrum is dual-licensed. You can choose one of the following options:
1. Use Spintrum with the GNU General Public License version 3 (GPLv3) (more information here: https://www.gnu.org/licenses/gpl-3.0.en.html), with an additional clause:
- In case you use Spintrum to produce any work (publication, software, machine, derivative software of any kind, etc...), you are obliged to acknowledge that Spintrum was used in that product.
In case this clause conflicts with other clauses in the GPLv3 license, this clause overwrites any other conflicting terms in the GPLv3 license.
2. As a commercial product: You can contact the authors of Spintrum and describe your requirements for purchasing Spintrum commercially, in which case you receive support and have the option request additional features.
For questions regarding licensing of Spintrum, please contact Samer Afach: [samer [[at]] afach.de].

View File

@ -3,3 +3,4 @@ recursive-include src *
recursive-include spintrum/examples *
include CMakeLists.txt
include get_version.py
include LICENSE.txt

View File

@ -1,5 +1,5 @@
default:
./get_resources.sh
bash ./get_resources.sh
mkdir -p build
cd build && cmake .. && make
@echo "\033[0;37;44mYou can now copy the directory \033[0;37;40mspintrum\033[0;37;44m to your Python installation.\033[0m"

View File

@ -1,15 +1,20 @@
# Spintrum
A high-performance library for spin simulations, written by Samer Afach
A high-performance library for spin simulations, written by Samer Afach as part of the Budker Group in University of Mainz
####purpose
#### purpose
Spintrum creates an interface between a high-performance and low-level language (C/C++) and an easy to use and high level language (Python).
##Installation
The library depends primarily on very good C/C++ programming to get fast result. No fancy physics is used in the library (so far).
Spintrum is supported only on Linux/Unix systems, and is primarily tested on Debian. For explanation, look at the FAQ below. If you'd like to compile Spintrum on operating systems other than debian, your efforts to do it will be minimal.
#### How does it work?
#####Prerequisites
As you will notice, the installation has two parts. The first one is building spintrum, which builds the shared library `libspintrum.so` and puts it in the package directory of Python, and the second part is installing that package into Python, which you can do if you wish. It is not mandatory.
## Installation
Spintrum is supported only on Linux/Unix systems, and is primarily tested on Debian (Jessie and Stretch). For explanation, look at the FAQ below. If you'd like to compile Spintrum on operating systems other than Debian, your efforts to do it will be minimal, assuming you are not trying to do it on Windows.
##### Prerequisites
- Linux/Unix (preferably Debian)
- OpenBLAS (read below)
- Polymath (read below)
@ -17,49 +22,64 @@ Spintrum is supported only on Linux/Unix systems, and is primarily tested on Deb
- Python 3.4+
- g++ 4.8+
#####In Python, the following libraries are required
##### In Python, the following libraries are required
- numpy
- scipy
- mpmath
- matplotlib
- matplotlib (for the examples only)
- scipy (for the examples only)
#####Do I need to compile OpenBLAS?
##### Do I need to compile OpenBLAS?
This depends on the performance you're trying to achieve. OpenBLAS, when compiled, creates binaries that are processor-specific, in order to achieve the best possible performance. In order to exploit this feature, it's recommended that you compile OpenBLAS.
Don't panic, as you don't have to do this yourself from scratch. The script `get_openblas.sh` should do this for you. It clones the OpenBLAS repository, and changes the optimization level of the compiler settings, and does the compilation. Run it using `sh get_openblas.sh`.
The installer automatically compiles OpenBLAS for you. If you would not like to have OpenBLAS compiled for you, then use the `Makefile` by running `make`. It will ask whether you want to have OpenBLAS compiled for you. Then, you're free to use the directory `spintrum` independently as a package, or copy it yourself to your Python installation. You have to have OpenBLAS installed on your system to have this work (either compiled for you or installed by your system); otherwise spintrum compilation will fail.
#####What optimization level should I take for OpenBLAS?
The default optimization level for OpenBLAS is `-O2`, which is fair. The script `get_openblas.sh` changes all optimization flags by default to `-Ofast`. This is an extreme exaggeration, and may cause [problems](http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html). I recommend using O2 for tests, and going to Ofast once everything is prepared. Please read [the link](http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html) that explains what these optimization flags mean. Then, edit the file `set_openblas_optimization.py`, and change the variable `target_optimization` to the desired optimization level.
#### How to build?
#####What if I don't want to compile OpenBLAS?
The compilation script in the directory Spintrum expects a compiled version of OpenBLAS, either in the default directory that the script `get_openblas.sh` downloads and installs to, or an installed version of OpenBLAS in the operating system. Keep in mind that the default OpenBLAS in the Linux operating systems are not generally optimized for your processor.
In case you choose to build this manually, follow the following steps:
#####Do I need Polymath?
Definitely! Polymath is a C++ interface to BLAS. It was also written by Spintrum team to separate the Maths library from the programming. Use the script `get_polymath.sh` to clone Polymath.
- Clone the repository to some directory
- Go to that directory with your terminal
- Call `make` there.
#####How to install?
In the directory `Spintrum`, there's a `Makefile` that will do everything for you. Simply run the command `make` in that directory, and then if everything runs correctly, and no error messages are issued, run `make install` as root/superuser to install spintrum on your Python installation.
At that point you will get a directory called `spintrum`, which is the Python package that you can use or copy.
#####How to install missing prerequisites on Debian?
Remember that the required software must be installed beforehand.
##### Do I need Polymath?
Definitely! Polymath is a simple C++ interface to BLAS. It was also written by the Spintrum team to separate the Maths library from the programming of Spintrum. The installer will get Polymath for you automatically from its repository.
##### How to install?
There are two ways:
- Use `pip` to do the installation for you with the command:
```sh
# pip3 install git+https://git.afach.de/samerafach/Spintrum
```
Note: The `#` means that these commands have to be executed as root. Don't literally type that `#` in the terminal. This command will install some of the dependencies for you, too.
- Or, you can use Spintrum as an independent package, by cloning the repository `https://git.afach.de/samerafach/Spintrum` yourself, and running `make` to build.
##### How to install missing prerequisites on Debian?
Simply run the following in the terminal (as superuser/root):
```sh
# apt-get install build-essential cmake g++ gcc python3
# pip3 install numpy scipy mpmath matplotlib
# apt-get install build-essential cmake g++ gcc gfortran python3 python3-pip
```
Note: The `#` means that these commands have to be executed as root. Don't literally type that `#` in the terminal.
On Redhat versions of linux, find the equivalent package names and use `yum` or `dnf` to install the same dependencies.
#####Testing whether it works
After a successful installation, simply try the examples in the `examples` directory. They should all work, assuming you have
##### Testing whether it works
After a successful installation, simply try the examples in the `examples` directory. They should all work, assuming you have everything installed correctly. The dependencies of the examples are different than Spintrum itself. For example, the examples use Matplotlib, which plots signals and spectra. You have to install this yourself. On Debian, you can `sudo apt-get install python3-matplotlib` to do that. Also for fitting scripts, the package `scipy` is used, which you can install using `sudo pip3 install scipy`.
#####Caveat about Jupyter
##### Caveat about Jupyter
Spintrum works fine on Jupyter, except that the `stdout` and `stderr` output cannot be seen on Jupyter notebooks for technical reasons. So, if there's a message from the low-level C/C++, it won't be seen. Although unlikely, but in case you have an error and you can't figure out the reason, try running the script in terminal, and see whether the C/C++ interface is reporting an error.
##FAQ
## FAQ
- **Q:** Why is spintrum not supported on Windows?
- **A:** Ignoring that Windows is way slower than Linux for calculations; Spintrum uses the well-known high-performance linear algebra library OpenBLAS. And since Python 3.5+ is compiled on Visual Studio 2015, and since Spintrum uses ctypes, which is the shared-library interface of Python, binary compatibility has to be achieved between Python and the compiled Spintrum library. On the other hand, OpenBLAS does not support compilation on Visual Studio with 64-bit (it supports only 32-bit), meaning that only small spin systems will be properly supported, since memory of 4+ GB cannot be used, which is not worth the effort, as too many changes have to be done to make Spintrum compatible with Windows. In the worst case, use a VMWare Workstation on your Windows Machine, and you'll get the best performance.
- **A:** Ignoring that Windows is way slower than Linux for calculations; Spintrum uses the well-known high-performance linear algebra library OpenBLAS. And since Python 3.5+ is compiled on Visual Studio 2015, and since Spintrum uses ctypes, which is the shared-library interface of Python, binary compatibility has to be achieved between Python and the compiled Spintrum library. On the other hand, OpenBLAS does not support compilation on Visual Studio with 64-bit (it supports only 32-bit), meaning that only small spin systems will be properly supported, since memory of 4+ GB cannot be used, which is not worth the effort, as too many changes have to be done to make Spintrum compatible with Windows. In the worst case, use a VMWare Workstation Virtual Machine on your Windows Machine, and you'll get the best performance.

View File

@ -130,6 +130,7 @@ def ask_openblas_optimization_level():
print("5) Skip compiling OpenBLAS and assume it exists in the system")
print(question_color_start + "Please enter the option number: " + color_end)
sys.stdout.flush()
sys.stderr.flush()
option_chosen = input()
if option_chosen.replace(" ", "") == '1':
return "-O2"
@ -159,6 +160,7 @@ def ask_spintrum_optimization_level():
print("5) -Ofast")
print(question_color_start + "Please enter the option number: " + color_end)
sys.stdout.flush()
sys.stderr.flush()
option_chosen = input("")
if option_chosen.replace(" ", "") == '1':
return "-g"
@ -189,7 +191,8 @@ def get_openblas():
openblas_full_path_install = os.path.join(start_working_dir, openblas_dir_install)
openblas_git = "https://github.com/xianyi/OpenBLAS.git"
openblas_target_optimization = ask_openblas_optimization_level()
# openblas_target_optimization = ask_openblas_optimization_level()
openblas_target_optimization = "-Ofast"
if openblas_target_optimization != "SKIPOPENBLAS":
clone_git_repository(openblas_full_path, openblas_git)
if openblas_target_optimization != "":
@ -243,7 +246,8 @@ class DependenciesBuilder(_build):
clone_git_repository(polymath_full_path, polymath_git)
############## build spintrum
spintrum_optimization_target = ask_spintrum_optimization_level()
# spintrum_optimization_target = ask_spintrum_optimization_level()
spintrum_optimization_target = "-Ofast"
print("Building Spintrum extension...")
err_code = subprocess.call(["cmake . -DPythonInstallation=1 -DOptimizationLevel=" + spintrum_optimization_target], shell=True)
deal_with_error_code(err_code, "CMaking spintrum")
@ -258,7 +262,7 @@ setup(name='spintrum',
url='http://www.afach.de/',
author='Samer Afach',
author_email='samer@afach.de',
license='MPL',
license='Dual',
packages=['spintrum'],
package_data={'spintrum': [lib_file] + recursive_glob("examples")},
install_requires=['numpy', 'mpmath'],

View File

@ -1 +1 @@
__version__ = "0.2.0"
__version__ = "0.2.2"

View File

@ -19,8 +19,8 @@ const char* get_version()
void print_software_info()
{
std::cout<<"Spintrum version "<<get_version()<<". ";
std::cout<<"This software is provided under the MPL license. "
"For more information, contact Samer Afach: samer@afach.de."<<std::endl<<std::endl;
std::cout<<"This software is provided under a license that should have been delivered with its package in the file LICENSE.txt."
"For more information, contact Samer Afach: samer [[at]] afach.de."<<std::endl<<std::endl;
}
/**