diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..d96baae0a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: Build and Test + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: 3.12 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y libblas-dev liblapack-dev gfortran pkg-config + + - name: Install Python dependencies + run: | + pip install meson ninja meson-python numpy scipy ase pytest + + - name: Setup build directory + run: meson setup builddir + + - name: Compile + run: meson compile -C builddir + + +# - name: Install package +# run: meson install -C builddir + +# - name: Run tests +# run: meson test -C builddir diff --git a/.github/workflows/python-testsuite.yml b/.github/workflows/python-testsuite.yml index cd0bbb82f..742df2820 100644 --- a/.github/workflows/python-testsuite.yml +++ b/.github/workflows/python-testsuite.yml @@ -51,12 +51,13 @@ jobs: run: | sudo apt-get update sudo apt-get install git gfortran libblas-dev liblapack-dev - git clone https://github.com/mesonepigreco/CellConstructor.git + git clone https://github.com/SSCHAcode/CellConstructor.git + pip install meson meson-python ninja cd CellConstructor - python setup.py install --user + pip install --no-build-isolation . cd .. - python setup.py install --user + pip install --no-build-isolation . # Install julia requirements python -c 'import julia; julia.install()' diff --git a/README.md b/README.md index eaf1ebfbc..6507cce88 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,11 @@ See more info on the webpage: ## Easy installation through Anaconda -The SSCHA code comes as a python library, with computationally intense part speedup with C, Fortran and Julia. The easiest way to install is through Anaconda ([how to install anaconda](https://www.anaconda.com/download)) +The SSCHA code comes as a python library, with computationally intense part speedup with C, Fortran and Julia. The easiest way to install is through Anaconda ([how to install anaconda](https://www.anaconda.com/download)) ``` -conda create -n sscha -c conda-forge python=3.10 gfortran=11 libblas lapack openmpi julia openmpi-mpicc pip=23 numpy=1.26 scipy=1.10 spglib=2.2 setuptools=64 +conda create -n sscha -c conda-forge python=3.12 gfortran=11 libblas lapack openmpi julia openmpi-mpicc pip=23 numpy=1.26 scipy=1.10 spglib=2.2 conda activate sscha pip install ase julia mpi4py pip install cellconstructor python-sscha tdscha @@ -27,7 +27,7 @@ If you want the julia speedup, see the section on Manual installation to preconf ## Video lessons from the 2023 School are available -The full recordings, both of theoretical lectures, tutorials and Hands-on sessions can be found +The full recordings, both of theoretical lectures, tutorials and Hands-on sessions can be found in our youtube channel [SSCHAcode](https://www.youtube.com/@SSCHAcode>) This is the safest and best way to install the SSCHA. The first line creates a new pristine python environment with all the required libraries to compile the source code. The second line activates the newly installed environment. Then, the thrid command installs the additional dependencies, the last line compiles and install the SSCHA code. @@ -47,7 +47,7 @@ python -c 'import julia; julia.install()' ``` -## Installing without Anaconda +## Installing without Anaconda If you do not have anaconda to handle your dependencies you need to manually compile the code. @@ -76,7 +76,7 @@ The SSCHA code is a collection of 3 python packages: CellConstructor, python-ssc - [CellConstructor](https://github.com/SSCHAcode/CellConstructor>): utility to manage phonon dispersions, atomic structures and crystal symmetries - [sscha](https://github.com/SSCHAcode/python-sscha>) : This repository, relax with anharmonicity and compute static linear response properties. -- [tdscha]() : Compute the dynamical linear response (Raman and IR, spectral functions) +- [tdscha]() : Compute the dynamical linear response (Raman and IR, spectral functions) More details about installations are in the official website [www.sscha.eu](https://sscha.eu/download>) @@ -89,7 +89,7 @@ First make sure you have anaconda installed [(install anaconda)](https://www.ana The following commands are sufficient to install the full sscha suite and its dependencies. ``` -conda create -n sscha -c conda-forge python=3.10 gfortran=11 libblas lapack openmpi julia openmpi-mpicc pip=23 numpy=1.26 scipy=1.10 spglib=2.2 setuptools=64 +conda create -n sscha -c conda-forge python=3.12 gfortran=11 libblas lapack openmpi julia openmpi-mpicc pip=23 numpy=1.26 scipy=1.10 spglib=2.2 conda activate sscha pip install ase julia mpi4py pip install cellconstructor python-sscha tdscha @@ -175,3 +175,80 @@ For example For the development version of the code, subtitute the pip call with the python setup.py install. +## Compiling with Meson + +To compile and install SSCHA with Meson, follow these typical steps: + +### 1. Change to the Source Directory + +First, open a terminal and navigate to the root directory of the project source code. This is where the `meson.build` file is located. + +```bash +cd /path/to/source/root/python-sscha +``` + + +### 2. Configure the Build Directory + +Create and configure a build directory by running: + +```bash +meson setup builddir +``` + +or if you are in a conda env (the best option for a local installation): +```bash +meson setup builddir --prefix=$CONDA_PREFIX +``` + +if you want to use Intel MKL: +```bash +setup builddir -Duse_mkl=true +``` + +This command sets up a separate build directory (`builddir`) where all compiled files and build artifacts will be placed, keeping the source directory clean. After this, change into the build directory: + +```bash +cd builddir +``` + + +### 3. Compile the Project + +Once inside the build directory, compile the project using: + +```bash +meson compile +``` + +This will compile the source code according to the configuration from the previous step. + +### 4. Run Tests (Optional) + +The project includes tests, you need to install pytest to work. You can run them with: + +```bash +meson test +``` + +This step helps verify that the build works correctly. + +### 5. Install the Project (Optional) + +To install the compiled binaries, libraries, and other files system-wide (or to a custom location), run: + +```bash +meson install +``` + +or + +```bash +sudo meson install +``` + +You may need superuser privileges (hence `sudo`) to install to system directories. + +*** + +Following these steps will help you successfully compile, test, and install SSCHA with Meson as their build system. diff --git a/UserGuide/install.rst b/UserGuide/install.rst index c01d36d36..1415ad610 100644 --- a/UserGuide/install.rst +++ b/UserGuide/install.rst @@ -68,7 +68,7 @@ For python, we strongly recommend using the anaconda distribution, that already The numpy, scipy and matplotlib are python packages. These are usually provided with a new installation of python distributions like anaconda. Lapack and Blas are needed for compiling the FORTRAN code (together with a FORTRAN compiler like gfortran). -In many Linux distributions like ubuntu they can be installed as +In many Linux distributions like ubuntu they can be installed as .. code-block:: console @@ -76,7 +76,7 @@ In many Linux distributions like ubuntu they can be installed as -Note that this specific command may change in time. +Note that this specific command may change in time. Together with these mandatory requirements (otherwise, the code will not compile correctly or raise an exception at the startup), we @@ -90,7 +90,7 @@ If these packages are available, they will enable the automatic cluster/local ca To install all the python dependencies (and recommended) automatically, you may just run: .. code-block:: console - + pip install -r requirements.txt @@ -102,8 +102,8 @@ Installation from pip The easiest way to install python-sscha (and CellConstructor) is through the python package manager: .. code-block:: console - - pip install python-sscha + + pip install python-sscha @@ -116,43 +116,121 @@ Installation from source ------------------------ Once all the dependences of the codes are satisfied, you can unzip the source code downloaded from the website. -Then run, inside the directory that contains the setup.py script, the following command: +Then run, inside the directory that contains the meson.build script, the following command: .. code-block:: console - python setup.py install + pip install . As for the pip installation, you may append the --user option to install the package only for the user (without requiring administrator powers). +An "editable" install is highly recommended for developers. It allows you to modify the source code and have the changes reflected immediately without needing to reinstall. +.. code-block:: console + + pip install -e . + Install with Intel FORTRAN compiler ----------------------------------- -The setup.py script works automatically with the GNU FORTRAN compiler. However, due to some differences in linking lapack, -to use the intel compiler you need to edit a bit the setup.py script: +Meson works automatically with several FORTRAN compilers, including Intel FORTRAN. However, due to some differences in linking lapack, +to use the intel compiler you need to: + +Ensure MKL is installed in your Conda environment: +.. code-block:: console + + conda install mkl mkl-devel + +You can pass Meson options through pip's \--config-settings flag. +.. code-block:: console + + pip install . --config-settings=--setup-args=-Duse_mkl=true -In this case, you need to delete the lapack linking from the -setup.py and include the -mkl as linker option. -Note that you must force to use the same liker compiler as the one used for the compilation. +Or for an editable install: +.. code-block:: console + pip install -e . --config-settings=--setup-args=-Duse_mkl=true Install with a specific compiler path ------------------------------------- -This can be achieved by specifying the environment variables on which setup.py relies: +Method 1: Using Environment Variables (Recommended for most cases) +------------------------------------------------------------------ + +Meson automatically detects compilers using standard environment variables. You can set these variables before running the installation command. This is the simplest way to specify a compiler for a single build. + +The key variables are: + + CC: Specifies the C compiler executable. -1. CC (C compiler) -2. FC (Fortran compiler) -3. LDSHARED (linking) + CXX: Specifies the C++ compiler executable. -If we want to use a custom compiler in /path/to/fcompiler we may run the setup as: + FC: Specifies the Fortran compiler executable. + +Step-by-Step Instructions + +1. Open your terminal. All commands must be run in the same session, as environment variables are typically not permanent. +2. Set the environment variables to point to your desired compilers. + +Example for C (using a specific gcc): .. code-block:: console + export CC=/path/to/my/custom/gcc - FC=/path/to/fcompiler LDSHARED=/path/to/fcompiler python setup.py install +Example for Fortran (using a specific gfortran): +.. code-block:: console + export FC=/path/to/my/custom/gfortran +Example for C++ (if the project needed it): -A specific setup.py script is provided to install it easily in FOSS clusters. +.. code-block:: console + export CXX=/path/to/my/custom/g++ +3. Combine them as needed. For this project, you will likely need to set CC and FC. + +# Example using compilers from a specific toolchain +.. code-block:: console + export CC=/usr/local/bin/gcc-11 + export FC=/usr/local/bin/gfortran-11 + +4. Run the pip installation. With the variables set, run pip install from the project's root directory. pip will pass the environment variables down to Meson. + +.. code-block:: console + # Ensure you are in the project's root directory (where pyproject.toml is) + pip install . + +The build process will now use the compilers you specified instead of the system defaults. + +Method 2: Using a Meson Cross File (Advanced & Reproducible) +------------------------------------------------------------ + +For a more permanent or reproducible setup (e.g., in CI/CD pipelines or complex environments), a Meson "cross file" is the best practice. This file explicitly defines the toolchain. +Step-by-Step Instructions + +1. Create a cross file. In your project's root directory, create a file named native-toolchain.ini (the name can be anything). + +2. Edit the file to specify the paths to your compilers in the [binaries] section. + +Example native-toolchain.ini: + +.. code-block:: console + # native-toolchain.ini + # Defines the compilers to use for the build. + + [binaries] + c = '/path/to/my/custom/gcc' + fortran = '/path/to/my/custom/gfortran' + + # If you also needed C++, you would add: + # cpp = '/path/to/my/custom/g++' + +Note: The keys are c, cpp, and fortran. + +3. Run the pip installation with meson-args. You can instruct pip to pass configuration settings to meson-python, which in turn passes them to Meson. We use this to specify our cross file. + +.. code-block:: console + # The --native-file option tells Meson which toolchain to use. + pip install . --config-settings=meson-args="--native-file=native-toolchain.ini" +This method is more explicit and less prone to errors from shell configurations. It ensures that anyone building the project can easily use the exact same toolchain by sharing the native-toolchain.ini file. diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..c64fc29ca --- /dev/null +++ b/meson.build @@ -0,0 +1,259 @@ +project('python-sscha', + ['c','fortran'], + version : '1.5.0', + license: 'GPL', + meson_version: '>= 1.1.0', # <- set min version of meson. + default_options : [ + 'warning_level=1', + 'buildtype=release', + 'fortran_args=-O2', + 'fortran_args=-cpp' + ]) + + # --- System and Python Dependencies --- + # Imports the Meson Python module to handle extensions and Python installation. + # --- Opciones de compilación --- + use_mkl = get_option('use_mkl') + + # --- System and Python Dependencies --- + # Find the necessary installations + py = import('python').find_installation(pure: false) + py_dep = py.dependency() + fc = meson.get_compiler('fortran') + + # Additional dependencies + + # --- BLAS/LAPACK Dependencies --- + # Meson will attempt to automatically detect LAPACK and BLAS. + # You don't need 'lapack_opt' as in numpy.distutils. + # If detection fails, you can pass configuration options to Meson + # (e.g., -Dblas_args='-L/path/to/blas -lblas'). + openblas_dep = dependency('openblas', required: false) + if use_mkl + mkl_dep = dependency('mkl', required: true) + blas_dep = mkl_dep + lapack_dep = mkl_dep + else + lapack_dep = dependency('lapack', required: true) + blas_dep = dependency('blas', required: true) + endif + + # Look for the OpenMP library if it is needed for parallelization. + openmp_dep = dependency('openmp', required: true) + + # --- MPI Detection --- + # This overrides the logic in os.environ["MPICC"] and os.popen("%s -show" % mpicc). + # Meson has a built-in MPI module. + mpi_args = [] + mpi_link_args = [] + mpi_compile_args = [] + has_mpi = false + + # Attempts to find the MPI dependency. + # You can specify a specific MPI compiler with the 'mpi_compiler' parameter + # or, if you want, a specific Fortran compiler with 'mpi_fortran_compiler'. + # For OpenMPI, IntelMPI, MPICH, etc., Meson usually finds it automatically. + #mpi_dep = dependency('mpi', required: false, language: ['c', 'fortran']) + mpi_dep = dependency('mpi', required: false) + + if mpi_dep.found() + message('MPI environment detected correctly.') + has_mpi = true + # Meson handles adding appropriate flags. We just add the define. + # If you need specific MPI flags beyond what Meson adds automatically, + # you can get them via mpi_dep.get_compile_args() and mpi_dep.get_link_args() + # and add them to extra_compile_args/extra_link_args. + mpi_compile_args += ['-D_MPI'] + else + # Here you can add warning logic if MPI is not found. + # Meson prints a warning if required: true and it is not found. + # For required: false, you can print your own warning. + warning('No MPI compiler found, please ensure MPI is installed and configured.') + warning('If you wish to activate MPI acceleration, consider setting MPICC environment variable or providing Meson with appropriate flags.') + endif + # Find the quadmath library, if available + quadmath_dep = fc.find_library('quadmath', required: false) + + # --- NUMPY CONFIGURATION --- + # Gets the path to the NumPy and f2py header directories using the Python command + incdir_numpy = run_command(py, + ['-c', 'import numpy; print(numpy.get_include())'], + check : true + ).stdout().strip() + + # f2py also requires the fortranobject.h header + incdir_f2py = run_command(py, + ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], + check : true + ).stdout().strip() + + inc_np = include_directories(incdir_numpy, incdir_f2py) + np_dep = declare_dependency(include_directories: inc_np) + + inc_f2py = include_directories(incdir_f2py) + fortranobject_c = incdir_f2py / 'fortranobject.c' + + # --- END OF NUMPY CONFIGURATION --- + if openblas_dep.found() + message('openblas environment detected correctly.') + list_dep = [py_dep, mpi_dep, quadmath_dep, openblas_dep, lapack_dep, blas_dep] + else + warning('No openblas found.') + list_dep = [py_dep, mpi_dep, quadmath_dep, lapack_dep, blas_dep] + endif + +# --- Common Flags --- +common_fortran_flags = ['-cpp', '-fopenmp'] +common_link_flags = ['-fopenmp'] # For OpenMP + +# --- SCHAModules Module (Fortran) --- +# This compiles and links your Fortran module with the Python, LAPACK, BLAS, and MPI dependencies +# Note: The Fortran extension will generate a .so or .pyd file that Python can import. + +# --- SCHAModules extension --- + +schamodules_sources = [ + 'SCHAModules/module_stochastic.f90', + 'SCHAModules/module_new_thermodynamic.f90', + 'SCHAModules/module_anharmonic.f90', + 'SCHAModules/get_stress_tensor.f90', + 'SCHAModules/get_gradient_supercell.f90', + 'SCHAModules/get_upsilon_matrix.f90', + 'SCHAModules/multiply_lambda_tensor.f90', + 'SCHAModules/cell_force.f90', + 'SCHAModules/get_gradient_supercell_fast.f90', + 'SCHAModules/get_g.f90', + 'SCHAModules/get_emat.f90', + 'SCHAModules/get_v3.f90', + 'SCHAModules/get_odd_straight.f90', + 'SCHAModules/get_cmat.f90', + 'SCHAModules/get_v4.f90', + 'SCHAModules/get_odd_straight_with_v4.f90' + # ,'SCHAModules/module_polarization.f90' +] +## Generate the C wrapper with f2py using a custom target +f2py_SCHAModules_target = custom_target('SCHAModules-f2py-wrapper', + input: schamodules_sources, + output: ['SCHAModulesmodule.c','SCHAModules-f2pywrappers.f','SCHAModules-f2pywrappers2.f90'], +# command: [py.full_path(), '-m', 'numpy.f2py', '--backend', 'meson', +# '--dep', 'mpi', '--quiet', '-c', '@INPUT0@', '-m', 'SCHAModules'], + command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'SCHAModules', '--lower'], + install: false +) +py.extension_module('SCHAModules', + [ + schamodules_sources, + f2py_SCHAModules_target, fortranobject_c], + include_directories: inc_np, + dependencies: list_dep, + install: true +) + +# --- Module odd_HP (C) --- +# Uncomment and adapt if you want to include this module. +# This would be done similarly to the Fortran module. +# odd_hp_sources = files( +# 'CModules/odd_corr_module.c', +# 'CModules/LanczosFunctions.c' +# ) +# py_mod_odd_hp = python.extension_module( +# 'sscha_HP_odd', # Make sure this is the desired import name +# odd_hp_sources, +# dependencies : [py_dep, mpi_dep], # assumes it only depends on Python and MPI +# c_args : py2_flag + mpi_compile_args + ['-O3'], # Extra compile args for C +# link_args : mpi_link_args # Extra link args for C +# ) + + +# --- Installing Python Packages --- +# The 'Modules' directory will be installed as the 'sscha' package. +#python.install_sources( +# 'Modules/', # Path to your Python package directory +# The sources in this directory will be copied. +# You can also use install_dir: python.get_install_dir() / 'sscha' +# If you want to install it in a specific subdirectory of site-packages. +# By default, Meson-Python will install it correctly. +# subdir: 'sscha' +#) +# Define la ruta de la librería +#lib_dir = 'Modules' +#lib_name = 'Calculator.py' +#lib_path = python.find_sources(lib_dir, lib_name) + +# Instala la librería en el sitio de paquetes de Python +#python.install_sources( +# ['Modules/Calculator.py'], +# pure: true, +# subdir: 'sscha' +#) + +# install_subdir('Modules', install_dir : join_paths(get_option('prefix'), 'share', 'python-sscha', 'Modules')) +# install_subdir('Modules', install_dir : 'share', strip_directory : false) <-- Not the best option +# install_subdir('Modules', install_dir : py.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries + +py.install_sources([ + 'Modules/__init__.py', + 'Modules/AdvancedCalculations.py', + 'Modules/aiida_ensemble.py', + 'Modules/Calculator.py', + 'Modules/Cluster.py', + 'Modules/Dynamical.py', + 'Modules/Ensemble.py', +# 'Modules/fourier_gradient.jl', + 'Modules/LocalCluster.py', + 'Modules/Minimizer.py', + 'Modules/Optimizer.py', + 'Modules/Parallel.py', + 'Modules/Relax.py', + 'Modules/SchaMinimizer.py', + 'Modules/Tools.py', + 'Modules/Utilities.py' + ], + subdir: 'sscha', +) + +# --- Installing Scripts --- +# Meson is great for installing scripts and making them executable. +# Scripts will be installed in the `bin` directory of the Python environment (e.g., venv/bin/). + +py.install_sources([ + 'scripts/sscha.x', + 'scripts/cluster_check.x', + 'scripts/plot_frequencies.py', + 'scripts/sscha-plot-data.py', + 'scripts/static-vc-relax.pyx', + 'scripts/read_incomplete_ensemble.py' +]) + +# --- Copy package data (e.g. *.jl) --- +# This emulates package_data={"": ["*.jl"]} +# Create a 'sscha' subdirectory within the Python installation directory +# and copy the .jl files there. +install_data( + ['Modules/fourier_gradient.jl'], # List the .jl files you need + install_dir : py.get_install_dir() / 'sscha' +) +# If there are many .jl files in multiple subdirectories, +# you would need to use 'install_subdir' or list them all explicitly. +# For a more general `package_data` approach for non-Python files, +# it is often recommended to use the `package_data` from `pyproject.toml` or +# an `sdist` that includes those files and then the `wheel` packages them. +# Meson focuses more on building and compiling. + +# You can use configure_file to generate files if needed, +# for example for dynamic versions or generated data. +# configure_file(input: 'src/my_template.py.in', +# output: 'my_module/version.py', +# configuration: conf) + + +# Set the tests by pytest. +pytest_exe = find_program('pytest', required: false) + +if pytest_exe.found() + test('pytest', pytest_exe, + args : ['-v', '-m', 'not release', 'tests'], + workdir : meson.project_source_root()) +else + message('pytest not found; pytest tests are skipped.') +endif diff --git a/meson.build.sscha b/meson.build.sscha new file mode 100644 index 000000000..a7c1fa0dc --- /dev/null +++ b/meson.build.sscha @@ -0,0 +1,73 @@ +project('sscha', + ['c', 'fortran'], + version : '0.1', + meson_version: '>= 1.1.0', + default_options : [ + 'warning_level=1', + 'buildtype=release' + ]) +fc = meson.get_compiler('fortran') + +py = import('python').find_installation(pure: false) +py_dep = py.dependency() + +incdir_numpy = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], + check : true +).stdout().strip() + +incdir_f2py = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'], + check : true +).stdout().strip() + +inc_np = include_directories(incdir_numpy) +np_dep = declare_dependency(include_directories: inc_np) + +incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' +inc_f2py = include_directories(incdir_f2py) +fortranobject_c = incdir_f2py / 'fortranobject.c' + +inc_np = include_directories(incdir_numpy, incdir_f2py) +# gh-25000 +quadmath_dep = fc.find_library('quadmath', required: false) + + + + +py.extension_module('sscha', + [ + '''module_stochastic.f90''', + '''module_new_thermodynamic.f90''', + '''module_anharmonic.f90''', + '''get_stress_tensor.f90''', + '''get_gradient_supercell.f90''', + '''get_upsilon_matrix.f90''', + '''multiply_lambda_tensor.f90''', + '''cell_force.f90''', + '''get_gradient_supercell_fast.f90''', + '''get_g.f90''', + '''get_emat.f90''', + '''get_v3.f90''', + '''get_odd_straight.f90''', + '''get_cmat.f90''', + '''get_v4.f90''', + '''get_odd_straight_with_v4.f90''', + '''sschamodule.c''', + '''sscha-f2pywrappers2.f90''', + '''sscha-f2pywrappers.f''', + fortranobject_c + ], + include_directories: [ + inc_np, + + ], + dependencies : [ + py_dep, + quadmath_dep, + dependency('mpi'), + + + ], + + install : true) diff --git a/meson.options b/meson.options new file mode 100644 index 000000000..d6853da87 --- /dev/null +++ b/meson.options @@ -0,0 +1,3 @@ +# meson.options +option('use_mkl', type: 'boolean', value: false, + description: 'Use Intel Math Kernel Library (MKL) for BLAS/LAPACK') diff --git a/setup.py b/old_setup.py similarity index 100% rename from setup.py rename to old_setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..cc8953a7b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,39 @@ +[build-system] +requires = ["meson-python>=0.13.0", "meson>=1.1.0", "numpy>=1.20.0", "cellconstructor","meson-python"] +build-backend = "mesonpy" + +[project] +name = "python-sscha" +version = "1.5.0" +description = "Python implementation of the sscha code" +authors = [{name = "Lorenzo Monacelli"}] # Put here email +readme = "README.md" +license = {file = "LICENSE.txt"} +requires-python = ">=3.8,<=3.12" # Updated to specify Python 3.8 to 3.12 +dependencies = [ + "numpy", + "ase", + "scipy", + "cellconstructor", + "spglib", + "matplotlib", + # mpi4py y pypar are optional and are handled at runtime/configuration +] +# If you have scripts that you want to be installed and executable +# entries = { scripts = ["scripts/sscha", "scripts/cluster_check.x", ...] } +# However, Meson is better at handling scripts like install_data + +[project.urls] +Homepage = "https://sscha.eu/" +Repository = "https://github.com/SSCHAcode/python-sscha" +# Documentation = "https://documentacion.readthedocs.io/" +Issues = "https://github.com/SSCHAcode/python-sscha/issues" + +# --- Meson-python specific configuration (Optional but useful) --- +[tool.meson-python] +# Here you can pass options to Meson that control the build process. +# For example, to enable debugging or specify a different installation path. +# By default, meson-python takes care of using the virtual environment if it exists. + +# build-args = ["-Dbuildtype=debug"] # Uncomment for a debug build +# setup-args = ["--prefix=/opt/python-sscha"] # For a non-standard installation diff --git a/python-sscha Installation Guide.md b/python-sscha Installation Guide.md new file mode 100644 index 000000000..d43b6c3aa --- /dev/null +++ b/python-sscha Installation Guide.md @@ -0,0 +1,130 @@ +# python-sscha Installation Guide + +This guide provides step-by-step instructions to compile and install the *sscha* library. The project uses the Meson build system to compile C and Fortran extensions for Python. + +## Recommended Installation: Conda / Mamba + +The easiest and most reproducible way to install *python-sscha* is by using a Conda environment. We strongly recommend using *micromamba* or *mamba* as they are significantly faster. This method installs all the required compilers, libraries, and Python packages inside an isolated environment, avoiding the need to modify your base system. + +### Step 1: Create and Activate the Environment + +1. Install Conda/Mamba. If you don't have it, we recommend installing *micromamba*. + +2. Create the environment. Open your terminal and run the following command. It will create a new environment named *sscha* with all the necessary dependencies, including *CellConstructor*. + +```bash +micromamba create -n sscha python=3.12 gfortran libblas lapack openmpi openmpi-mpicc pkg-config pip numpy scipy spglib=2.2 cellconstructor matplotlib ase +``` + +* Python Version: We use Python 3.12. Newer versions are not yet supported due to a dependency constraint from *spglib <= 2.2*. + +* pkg-config: This package is essential. Meson requires it to correctly detect the BLAS and LAPACK libraries provided by Conda. + +3. Activate the environment. You must activate the environment before proceeding. + +```bash +micromamba activate sscha +``` + +### Step 2: Clone the Repository (if not done) + +If you don't have the source code locally, clone it from the repository. + +```bash +git clone https://github.com/SSCHAcode/python-sscha.git +cd python-sscha +``` + +### Step 3: Install python-sscha + +With the environment active, install the package using *pip*. *pip* will automatically use Meson to compile and install the project. + +```bash +pip install . +``` + +The installation is now complete! You can verify it by running the tests or importing the modules in Python. + +## Advanced Installation: Manual Configuration + +This section is for users who cannot use Conda or need to configure the build with specific compilers or options. + +### Prerequisites + +* A C and Fortran compiler. + +* Python 3.12 and pip. + +* Ninja and Meson: *pip install meson ninja*. + +* System libraries for BLAS, LAPACK, and MPI. + +* All Python dependencies, including CellConstructor, must be installed in your environment. + +### Method 1: Using Environment Variables + +You can specify compilers by setting the *CC* (C compiler) and *FC* (Fortran compiler) environment variables before running *pip*. + +```bash +# Example using compilers from a specific toolchain +export CC=/usr/local/bin/gcc-11 +export FC=/usr/local/bin/gfortran-11 + +# Install the project +pip install . +``` + +### Method 2: Using a Meson Cross File + +For a reproducible setup, define your compilers in a file (e.g., *native-toolchain.ini*). + +Example *native-toolchain.ini*: + +```bash +[binaries] +c = '/path/to/my/custom/gcc' +fortran = '/path/to/my/custom/gfortran' +``` + +Then, install by passing this file to Meson via *pip*: + +```bash +pip install . --config-settings=meson-args="--native-file=native-toolchain.ini" +``` + +## Build Options + +You can pass options to Meson to customize the build. + +* Create a debug build: + +```bash +pip install . --config-settings=meson-args="-Dbuildtype=debug" +``` + +* Enable Intel MKL (requires MKL to be installed and findable by your system): + +```bash +pip install . --config-settings=meson-args="-Duse_mkl=true" +``` + +* Combine multiple options: + +```bash +pip install . --config-settings=meson-args="-Dbuildtype=debug,-Duse_mkl=true" +``` + +## Reconfiguring a Build + +If you need to change build options, it is best to perform a clean installation. + +```bash +# 1. Uninstall the package +pip uninstall python-sscha + +# 2. (Optional but recommended) Remove the build directory +rm -rf build/ + +# 3. Reinstall with the new options +pip install . --config-settings=meson-args="-Dnew_option=value" +``` diff --git a/requirements2.txt b/requirements2.txt index 590aa382a..6307d01ff 100644 --- a/requirements2.txt +++ b/requirements2.txt @@ -3,3 +3,4 @@ numpy scipy ase==3.16.0 spglib<=2.2 +cellconstructor diff --git a/scripts/sscha b/scripts/sscha.x similarity index 100% rename from scripts/sscha rename to scripts/sscha.x