From d74e29e9931fd4a509528e724b26380434ab8b4c Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 09:54:28 +0200 Subject: [PATCH 001/106] Setting the Meson compiler (test) --- meson.build | 173 +++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 27 ++++++++ 2 files changed, 200 insertions(+) create mode 100644 meson.build create mode 100644 pyproject.toml diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..2b297106 --- /dev/null +++ b/meson.build @@ -0,0 +1,173 @@ +project('python-sscha', 'fortran', 'c', + version : '1.4.2', + license: 'GPL', +# Common compilation options for Fortran. +# -cpp is essential for the Fortran preprocessor. +# -O2 is a general optimization you had in setup.py. + default_options : ['warning_level=1','fortran_args=-cpp', 'fortran_args=-O2']) + + # --- System and Python Dependencies --- + # Imports the Meson Python module to handle extensions and Python installation. + python = import('python') + python_installation = python.find_installation() + numpy_incdir = run_command( + python_installation, '-c', 'import numpy; print(numpy.get_include())', + check: true + ).stdout().strip() + +# --- 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'). +lapack_dep = dependency('lapack', required : true) +blas_dep = dependency('blas', required : true) + +# 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']) + +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 + +# --- Python 2/3 Detection (not as relevant anymore, but translated) --- +# In Meson, this would be done based on the Python version Meson is using. +# Since Python 2 is EOL, this check is generally not needed. +# However, if you want to keep the flag: +py2_flag = [] +if py_dep.version().version_compare('<3.0') + message('Running on Python 2, adding the flag -D_PYTHON2') + py2_flag += ['-D_PYTHON2'] +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_sources = files( + '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' +) + +# Meson's `extension_module` function for Python handles much of the magic. +# 'SCHAModules' will be the name of the resulting Python module. +py_mod_schamodules = python.extension_module( + 'SCHAModules', + schamodules_sources, + # Make sure BLAS/LAPACK dependencies are linked correctly + dependencies : [py_dep, lapack_dep, blas_dep, mpi_dep], + # Fortran-specific flags + fortran_args : common_fortran_flags, + link_args : common_link_flags, + # Add -fPIC for Linux if needed (Meson usually handles this) + # This is the equivalent of extra_f90_compile_args and extra_link_args + # in setup.py for the Fortran module. + include_directories: include_directories(numpy_incdir), +) + +# --- 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' +) + +# --- 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/). +install_scripts = [ + 'scripts/sscha', + 'scripts/cluster_check.x', + 'scripts/plot_frequencies.py', + 'scripts/sscha-plot-data.py', + 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente + 'scripts/read_incomplete_ensemble.py' +] + +foreach s : install_scripts + install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin +endforeach + +# --- 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 : python.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) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..ff215508 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,27 @@ +[build-system] +requires = ["meson-python>=0.13.0", "meson>=1.0", "numpy", "setuptools"] +build-backend = "mesonpy" + +[project] +name = "python-sscha" +version = "1.4.2" +description = "Python implementation of the sscha code" +authors = [{name = "Lorenzo Monacelli", email = "your_email@example.com"}] # Put here email +readme = "README.md" +license = {file = "LICENSE.txt"} +requires-python = ">=3.8" # Ajusta según las versiones de Python que soportes +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://github.com/mesonepigreco/python-sscha" From 50d04d7d9757da1aa1217fa62ff6ad4cec1cfb06 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:00:03 +0200 Subject: [PATCH 002/106] Addibg missing FORTRAN code. --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index 2b297106..c295de2f 100644 --- a/meson.build +++ b/meson.build @@ -89,6 +89,8 @@ schamodules_sources = files( 'SCHAModules/get_odd_straight.f90', 'SCHAModules/get_cmat.f90', 'SCHAModules/get_v4.f90', + 'SCHAModules/cell_force.f90', + 'SCHAModules/module_polarization.f90', 'SCHAModules/get_odd_straight_with_v4.f90' ) From b29e4cfad2e92d9eebc355a72d95663420329041 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:03:53 +0200 Subject: [PATCH 003/106] Set the githib builder (just a copy of the CellConstructor one) --- .github/workflows/build.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..3c3a921a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,36 @@ +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.9 + + - 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 + + - name: Setup build directory + run: meson setup builddir + + - name: Compile + run: meson compile -C builddir + + - name: Run tests + run: meson test -C builddir + +# - name: Install package +# run: meson install -C builddir From 2375ba3b4655fa5c4f434d6ea6d16b8ce474bf6d Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:12:11 +0200 Subject: [PATCH 004/106] update --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ff215508..52c88a06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "mesonpy" name = "python-sscha" version = "1.4.2" description = "Python implementation of the sscha code" -authors = [{name = "Lorenzo Monacelli", email = "your_email@example.com"}] # Put here email +authors = [{name = "Lorenzo Monacelli"}] # Put here email readme = "README.md" license = {file = "LICENSE.txt"} requires-python = ">=3.8" # Ajusta según las versiones de Python que soportes From a15fb1d8edaab69778f4e565b65750e6f43f0d5f Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:17:02 +0200 Subject: [PATCH 005/106] Removing languages from mpi dependency call --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index c295de2f..47ef9577 100644 --- a/meson.build +++ b/meson.build @@ -38,7 +38,8 @@ has_mpi = false # 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, language: ['c', 'fortran']) +mpi_dep = dependency('mpi', required: false) if mpi_dep.found() message('MPI environment detected correctly.') From 447bf8260a4dc150391f7a4302ed3fd963684b4b Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:21:47 +0200 Subject: [PATCH 006/106] Removing python version flag as Meson do it automatically --- meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 47ef9577..776b097c 100644 --- a/meson.build +++ b/meson.build @@ -61,11 +61,11 @@ endif # In Meson, this would be done based on the Python version Meson is using. # Since Python 2 is EOL, this check is generally not needed. # However, if you want to keep the flag: -py2_flag = [] -if py_dep.version().version_compare('<3.0') - message('Running on Python 2, adding the flag -D_PYTHON2') - py2_flag += ['-D_PYTHON2'] -endif +#py2_flag = [] +#if py_dep.version().version_compare('<3.0') +# message('Running on Python 2, adding the flag -D_PYTHON2') +# py2_flag += ['-D_PYTHON2'] +#endif # --- Common Flags --- common_fortran_flags = ['-cpp', '-fopenmp'] From 8ee2ed2d39ad6af12f8584505557d3d8a78c4ed8 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:24:43 +0200 Subject: [PATCH 007/106] Removing another python dependency call --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 776b097c..fc60ba07 100644 --- a/meson.build +++ b/meson.build @@ -101,7 +101,7 @@ py_mod_schamodules = python.extension_module( 'SCHAModules', schamodules_sources, # Make sure BLAS/LAPACK dependencies are linked correctly - dependencies : [py_dep, lapack_dep, blas_dep, mpi_dep], + dependencies : [lapack_dep, blas_dep, mpi_dep], # Fortran-specific flags fortran_args : common_fortran_flags, link_args : common_link_flags, From bf917cdadf28175a038470c7ebf8bc4efe6c9463 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:30:33 +0200 Subject: [PATCH 008/106] Change from python.extension_module to the correct python_installation.extension_module --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index fc60ba07..c830f363 100644 --- a/meson.build +++ b/meson.build @@ -97,7 +97,7 @@ schamodules_sources = files( # Meson's `extension_module` function for Python handles much of the magic. # 'SCHAModules' will be the name of the resulting Python module. -py_mod_schamodules = python.extension_module( +py_mod_schamodules = python_installation.extension_module( 'SCHAModules', schamodules_sources, # Make sure BLAS/LAPACK dependencies are linked correctly From 886d32b24bc6bb0c464bc50a7e96db68674a5da6 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:40:25 +0200 Subject: [PATCH 009/106] Install 'Modules' in 'sscha' --- meson.build | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index c830f363..10ab9dfb 100644 --- a/meson.build +++ b/meson.build @@ -129,13 +129,32 @@ py_mod_schamodules = python_installation.extension_module( # --- Installing Python Packages --- # The 'Modules' directory will be installed as the 'sscha' package. -python.install_sources( - 'Modules/', # Path to your Python package directory +#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' +# subdir: 'sscha' +#) +install_data( + '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', + install_dir: python_installation.get_install_dir() / 'sscha', ) # --- Installing Scripts --- From d82b76a4b80c23c3b134090b9eb6fe013219aa84 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:44:39 +0200 Subject: [PATCH 010/106] Test the Julia script installation --- meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 10ab9dfb..d91cb1be 100644 --- a/meson.build +++ b/meson.build @@ -145,7 +145,7 @@ install_data( 'Modules/Cluster.py', 'Modules/Dynamical.py', 'Modules/Ensemble.py', - 'Modules/fourier_gradient.jl', +# 'Modules/fourier_gradient.jl', 'Modules/LocalCluster.py', 'Modules/Minimizer.py', 'Modules/Optimizer.py', @@ -179,7 +179,7 @@ endforeach # and copy the .jl files there. install_data( ['Modules/fourier_gradient.jl'], # List the .jl files you need - install_dir : python.get_install_dir() / 'sscha' + install_dir : python_installation.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. From f5a936a51d9aa3ba7cb6500acb4ef3de579b0ae3 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:50:48 +0200 Subject: [PATCH 011/106] Test install in bin --- meson.build | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index d91cb1be..5635605c 100644 --- a/meson.build +++ b/meson.build @@ -160,18 +160,27 @@ install_data( # --- 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/). -install_scripts = [ +#install_scripts = [ +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente +# 'scripts/read_incomplete_ensemble.py' +#] +install_data = ([ 'scripts/sscha', 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente - 'scripts/read_incomplete_ensemble.py' -] + 'scripts/read_incomplete_ensemble.py'], + install_dir: get_option('bindir') + ) -foreach s : install_scripts - install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin -endforeach +#foreach s : install_scripts +# install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin +#endforeach # --- Copy package data (e.g. *.jl) --- # This emulates package_data={"": ["*.jl"]} From d8bac70574fe121f879131e811c20185df7330ee Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:53:21 +0200 Subject: [PATCH 012/106] No [...]?? --- meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 5635605c..8b253e3d 100644 --- a/meson.build +++ b/meson.build @@ -168,13 +168,13 @@ install_data( # 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente # 'scripts/read_incomplete_ensemble.py' #] -install_data = ([ +install_data = ( 'scripts/sscha', 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente - 'scripts/read_incomplete_ensemble.py'], + 'scripts/read_incomplete_ensemble.py', install_dir: get_option('bindir') ) From 31f653d01b8cf20242993277aaa874f05d886366 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 10:57:02 +0200 Subject: [PATCH 013/106] quick-Fix --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 8b253e3d..94706c43 100644 --- a/meson.build +++ b/meson.build @@ -169,12 +169,14 @@ install_data( # 'scripts/read_incomplete_ensemble.py' #] install_data = ( + [ 'scripts/sscha', 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente - 'scripts/read_incomplete_ensemble.py', + 'scripts/read_incomplete_ensemble.py' + ], install_dir: get_option('bindir') ) From c59f88c3f63f413d92edf4559b5bb6c791c6cb14 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 11:04:14 +0200 Subject: [PATCH 014/106] "Meson will automatically install it to the standards-conforming location." --- meson.build | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 94706c43..662205ec 100644 --- a/meson.build +++ b/meson.build @@ -160,25 +160,25 @@ install_data( # --- 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/). -#install_scripts = [ -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente -# 'scripts/read_incomplete_ensemble.py' -#] -install_data = ( - [ +executable( 'scripts/sscha', 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente 'scripts/read_incomplete_ensemble.py' - ], - install_dir: get_option('bindir') - ) +, install : true) +#install_data = ( +# [ +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente +# 'scripts/read_incomplete_ensemble.py' +# ], +# install_dir: get_option('bindir') +# ) #foreach s : install_scripts # install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin From a8ae1107cd4ae036ae73aefba428919fa0fccbb9 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 11:07:56 +0200 Subject: [PATCH 015/106] Trying to evade the non compiler for '.pyx' by installing as data. --- meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 662205ec..5ec855bd 100644 --- a/meson.build +++ b/meson.build @@ -165,20 +165,20 @@ executable( 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente +# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente 'scripts/read_incomplete_ensemble.py' , install : true) -#install_data = ( +install_data = ( # [ # 'scripts/sscha', # 'scripts/cluster_check.x', # 'scripts/plot_frequencies.py', # 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente + 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente # 'scripts/read_incomplete_ensemble.py' # ], -# install_dir: get_option('bindir') -# ) + install_dir: get_option('bindir') + ) #foreach s : install_scripts # install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin From aea7ab26a233a996574ad37facb22c3aee17856b Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 11:11:01 +0200 Subject: [PATCH 016/106] Installing 'scripts/static-vc-relax.pyx' as data in the Meson default place, somewhere (fix this in the future) --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 5ec855bd..fefaca78 100644 --- a/meson.build +++ b/meson.build @@ -177,7 +177,7 @@ install_data = ( 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente # 'scripts/read_incomplete_ensemble.py' # ], - install_dir: get_option('bindir') +# install_dir: get_option('bindir') ) #foreach s : install_scripts From 322ae7d94792c058ec37fbd277621465d6197fce Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 11:13:09 +0200 Subject: [PATCH 017/106] Removing comma to fix error --- meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index fefaca78..2543d237 100644 --- a/meson.build +++ b/meson.build @@ -174,11 +174,11 @@ install_data = ( # 'scripts/cluster_check.x', # 'scripts/plot_frequencies.py', # 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente + 'scripts/static-vc-relax.pyx')#, # Si esto es un script ejecutable directamente # 'scripts/read_incomplete_ensemble.py' # ], # install_dir: get_option('bindir') - ) +# ) #foreach s : install_scripts # install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin From 2cece710bc86c3561363ffea3b1b3435bd424421 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 11:50:01 +0200 Subject: [PATCH 018/106] Test Meson 'executable' for python. --- meson.build | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 2543d237..b4fc1fdf 100644 --- a/meson.build +++ b/meson.build @@ -160,21 +160,21 @@ install_data( # --- 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/). -executable( - 'scripts/sscha', - 'scripts/cluster_check.x', - 'scripts/plot_frequencies.py', - 'scripts/sscha-plot-data.py', +#executable( +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', # 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente - 'scripts/read_incomplete_ensemble.py' -, install : true) -install_data = ( +# 'scripts/read_incomplete_ensemble.py' +#, install : true) +#install_data = ( # [ # 'scripts/sscha', # 'scripts/cluster_check.x', # 'scripts/plot_frequencies.py', # 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx')#, # Si esto es un script ejecutable directamente +# 'scripts/static-vc-relax.pyx')#, # Si esto es un script ejecutable directamente # 'scripts/read_incomplete_ensemble.py' # ], # install_dir: get_option('bindir') @@ -204,3 +204,26 @@ install_data( # configure_file(input: 'src/my_template.py.in', # output: 'my_module/version.py', # configuration: conf) + +# Define el intérprete de Python +python = find_program('python3') + +# Crea un array con los nombres de todos los scripts que quieres instalar +python_scripts = [ + 'scripts/sscha', + 'scripts/cluster_check.x', + 'scripts/plot_frequencies.py', + 'scripts/sscha-plot-data.py', + 'scripts/static-vc-relax.pyx', + 'scripts/read_incomplete_ensemble.py' +] + +# Itera sobre el array y crea un ejecutable para cada script +foreach script : python_scripts + executable( + '@0@'.format(fs.stem(script)), # Crea un nombre de ejecutable sin la extensión .py + python, + script, + install: true + ) +endforeach From fb2940ca93a944df73c16f1082b2e09b369f9dfa Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 11:57:03 +0200 Subject: [PATCH 019/106] Fix for older versions of Meson. --- meson.build | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index b4fc1fdf..c9a9b511 100644 --- a/meson.build +++ b/meson.build @@ -210,18 +210,18 @@ python = find_program('python3') # Crea un array con los nombres de todos los scripts que quieres instalar python_scripts = [ - 'scripts/sscha', - 'scripts/cluster_check.x', - 'scripts/plot_frequencies.py', - 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx', - 'scripts/read_incomplete_ensemble.py' + 'scripts/script1.py', + 'scripts/script2.py', + 'scripts/utility.py' ] # Itera sobre el array y crea un ejecutable para cada script foreach script : python_scripts + # Usa rpartition para separar la extensión + script_name_without_ext = script.split('/')[-1].rpartition('.')[0] + executable( - '@0@'.format(fs.stem(script)), # Crea un nombre de ejecutable sin la extensión .py + script_name_without_ext, python, script, install: true From c615eb94d568cb489ca0bcc2271f58a053869d9f Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 12:40:14 +0200 Subject: [PATCH 020/106] Set the executables scripts' list --- meson.build | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index c9a9b511..2c7aae86 100644 --- a/meson.build +++ b/meson.build @@ -210,9 +210,12 @@ python = find_program('python3') # Crea un array con los nombres de todos los scripts que quieres instalar python_scripts = [ - 'scripts/script1.py', - 'scripts/script2.py', - 'scripts/utility.py' + 'scripts/cluster_check.x', + 'scripts/plot_frequencies.py', + 'scripts/read_incomplete_ensemble.py', + 'scripts/sscha', + 'scripts/sscha-plot-data.py', + 'scripts/static-vc-relax.pyx' ] # Itera sobre el array y crea un ejecutable para cada script From bbce5ea9e4149b59d70e2b9d5b219d75e74ea298 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 8 Aug 2025 16:46:50 +0200 Subject: [PATCH 021/106] Trying to fix the installation --- meson.build | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 2c7aae86..24eb72ca 100644 --- a/meson.build +++ b/meson.build @@ -210,18 +210,22 @@ python = find_program('python3') # Crea un array con los nombres de todos los scripts que quieres instalar python_scripts = [ + 'scripts/sscha', 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', - 'scripts/read_incomplete_ensemble.py', - 'scripts/sscha', 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx' + 'scripts/static-vc-relax.pyx', + 'scripts/read_incomplete_ensemble.py' ] # Itera sobre el array y crea un ejecutable para cada script foreach script : python_scripts - # Usa rpartition para separar la extensión - script_name_without_ext = script.split('/')[-1].rpartition('.')[0] + # Obtiene el nombre del archivo de la ruta, por ejemplo 'cluster_check.x' + script_basename = script.split('/')[-1] + + # Divide el nombre por el punto y toma el primer elemento para quitar la extensión + # Si el nombre no tiene punto, esto lo maneja correctamente + script_name_without_ext = script_basename.split('.')[0] executable( script_name_without_ext, From 7d7683ad96cd9d3055c2ec45b7167e0320f336fc Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 18 Aug 2025 16:04:50 +0200 Subject: [PATCH 022/106] test --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index 24eb72ca..161dbad4 100644 --- a/meson.build +++ b/meson.build @@ -234,3 +234,4 @@ foreach script : python_scripts install: true ) endforeach +# executable('sscha','scripts/sscha',install: true) From f283d678a7de4dc28416b809cb8f1ffe1c0020f4 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 19 Aug 2025 13:51:39 +0200 Subject: [PATCH 023/106] I will try this individual way, will it work without splicity telling they are python scripts? --- meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/meson.build b/meson.build index 161dbad4..8772d533 100644 --- a/meson.build +++ b/meson.build @@ -235,3 +235,8 @@ foreach script : python_scripts ) endforeach # executable('sscha','scripts/sscha',install: true) +# executable('cluster_check','scripts/cluster_check.x',install: true) +# executable('plot_frequencies','scripts/plot_frequencies.py',install: true) +# executable('sscha-plot-data','scripts/sscha-plot-data.py',install: true) +# executable('static-vc-relax','scripts/static-vc-relax.pyx',install: true) +# executable('read_incomplete_ensemble','scripts/read_incomplete_ensemble.py',install: true) From d59b02caa66dc08af2ea43c286f852cd48c4b6e0 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 19 Aug 2025 13:58:11 +0200 Subject: [PATCH 024/106] Lets try the automatic way --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 8772d533..6a529484 100644 --- a/meson.build +++ b/meson.build @@ -229,7 +229,7 @@ foreach script : python_scripts executable( script_name_without_ext, - python, +# python, script, install: true ) From e1559a90a1ead68679ac38d1c08dcd9bf8d2b0b9 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 21 Aug 2025 12:03:21 +0200 Subject: [PATCH 025/106] Test with '.pyx' file outside of loop --- meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 6a529484..b219a940 100644 --- a/meson.build +++ b/meson.build @@ -214,7 +214,7 @@ python_scripts = [ 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx', +# 'scripts/static-vc-relax.pyx', 'scripts/read_incomplete_ensemble.py' ] @@ -238,5 +238,5 @@ endforeach # executable('cluster_check','scripts/cluster_check.x',install: true) # executable('plot_frequencies','scripts/plot_frequencies.py',install: true) # executable('sscha-plot-data','scripts/sscha-plot-data.py',install: true) -# executable('static-vc-relax','scripts/static-vc-relax.pyx',install: true) +executable('static-vc-relax','scripts/static-vc-relax.pyx', python, install: true) # executable('read_incomplete_ensemble','scripts/read_incomplete_ensemble.py',install: true) From 5d758cf52a8c70e8b000fd698e3e020e88460dcf Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 21 Aug 2025 17:13:42 +0200 Subject: [PATCH 026/106] Install '.pyx' as data (test) --- meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/meson.build b/meson.build index b219a940..a0c05d09 100644 --- a/meson.build +++ b/meson.build @@ -240,3 +240,8 @@ endforeach # executable('sscha-plot-data','scripts/sscha-plot-data.py',install: true) executable('static-vc-relax','scripts/static-vc-relax.pyx', python, install: true) # executable('read_incomplete_ensemble','scripts/read_incomplete_ensemble.py',install: true) +install_data([ + 'scripts/static-vc-relax.pyx' +], +install_dir: get_option('bindir') +) From 13c096f54e1d4e3cd0c8630af7430771175a52ca Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 21 Aug 2025 17:17:42 +0200 Subject: [PATCH 027/106] Just a test. Removed the python call in the executable install meson call --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index a0c05d09..182a4f6e 100644 --- a/meson.build +++ b/meson.build @@ -238,7 +238,7 @@ endforeach # executable('cluster_check','scripts/cluster_check.x',install: true) # executable('plot_frequencies','scripts/plot_frequencies.py',install: true) # executable('sscha-plot-data','scripts/sscha-plot-data.py',install: true) -executable('static-vc-relax','scripts/static-vc-relax.pyx', python, install: true) +# executable('static-vc-relax','scripts/static-vc-relax.pyx', install: true) # executable('read_incomplete_ensemble','scripts/read_incomplete_ensemble.py',install: true) install_data([ 'scripts/static-vc-relax.pyx' From 824d9e20e2958aa9e97f920a9313f49d095753bc Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 21 Aug 2025 17:20:30 +0200 Subject: [PATCH 028/106] Looks like Meson identifies the script languaje fron the extension. --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 182a4f6e..df46fa60 100644 --- a/meson.build +++ b/meson.build @@ -210,7 +210,7 @@ python = find_program('python3') # Crea un array con los nombres de todos los scripts que quieres instalar python_scripts = [ - 'scripts/sscha', +# 'scripts/sscha', 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', @@ -241,6 +241,7 @@ endforeach # executable('static-vc-relax','scripts/static-vc-relax.pyx', install: true) # executable('read_incomplete_ensemble','scripts/read_incomplete_ensemble.py',install: true) install_data([ + 'scripts/sscha', 'scripts/static-vc-relax.pyx' ], install_dir: get_option('bindir') From 7380b455ad87cb0c6fc6b2547ce7f7967bdbf6cd Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 21 Aug 2025 17:38:01 +0200 Subject: [PATCH 029/106] If this fails I'll put all into a data install method --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index df46fa60..257dd561 100644 --- a/meson.build +++ b/meson.build @@ -211,7 +211,7 @@ python = find_program('python3') # Crea un array con los nombres de todos los scripts que quieres instalar python_scripts = [ # 'scripts/sscha', - 'scripts/cluster_check.x', +# 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', # 'scripts/static-vc-relax.pyx', @@ -242,6 +242,7 @@ endforeach # executable('read_incomplete_ensemble','scripts/read_incomplete_ensemble.py',install: true) install_data([ 'scripts/sscha', + 'scripts/cluster_check.x', 'scripts/static-vc-relax.pyx' ], install_dir: get_option('bindir') From 9c34f4a8b9e971e56ffe0e8019bb4da9154df780 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 21 Aug 2025 17:42:56 +0200 Subject: [PATCH 030/106] So all goes into data install... --- meson.build | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 257dd561..174b5723 100644 --- a/meson.build +++ b/meson.build @@ -212,10 +212,10 @@ python = find_program('python3') python_scripts = [ # 'scripts/sscha', # 'scripts/cluster_check.x', - 'scripts/plot_frequencies.py', - 'scripts/sscha-plot-data.py', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', # 'scripts/static-vc-relax.pyx', - 'scripts/read_incomplete_ensemble.py' +# 'scripts/read_incomplete_ensemble.py' ] # Itera sobre el array y crea un ejecutable para cada script @@ -243,7 +243,10 @@ endforeach install_data([ 'scripts/sscha', 'scripts/cluster_check.x', - 'scripts/static-vc-relax.pyx' + 'scripts/plot_frequencies.py', + 'scripts/sscha-plot-data.py', + 'scripts/static-vc-relax.pyx', + 'scripts/read_incomplete_ensemble.py' ], install_dir: get_option('bindir') ) From 0648b389ec25aba52d762ff2d4fa04ee307f97e5 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 22 Aug 2025 11:10:59 +0200 Subject: [PATCH 031/106] Change order of FORTRAN compilation --- meson.build | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 174b5723..367b804c 100644 --- a/meson.build +++ b/meson.build @@ -75,7 +75,7 @@ common_link_flags = ['-fopenmp'] # For OpenMP # 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_sources = files( - 'SCHAModules/module_stochastic.f90', + /*'SCHAModules/module_stochastic.f90', 'SCHAModules/module_new_thermodynamic.f90', 'SCHAModules/module_anharmonic.f90', 'SCHAModules/get_stress_tensor.f90', @@ -92,7 +92,23 @@ schamodules_sources = files( 'SCHAModules/get_v4.f90', 'SCHAModules/cell_force.f90', 'SCHAModules/module_polarization.f90', - 'SCHAModules/get_odd_straight_with_v4.f90' + 'SCHAModules/get_odd_straight_with_v4.f90'*/ + "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" ) # Meson's `extension_module` function for Python handles much of the magic. From 65f8144034edf583d9384ecf34f3970f44532690 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 22 Aug 2025 11:44:50 +0200 Subject: [PATCH 032/106] Change "" to ''. --- meson.build | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/meson.build b/meson.build index 367b804c..12a4ecce 100644 --- a/meson.build +++ b/meson.build @@ -93,22 +93,22 @@ schamodules_sources = files( 'SCHAModules/cell_force.f90', 'SCHAModules/module_polarization.f90', 'SCHAModules/get_odd_straight_with_v4.f90'*/ - "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_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' ) # Meson's `extension_module` function for Python handles much of the magic. From 3a8146cb0dad751f7ea8e16cf8949734cb6b86dc Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 22 Aug 2025 12:01:07 +0200 Subject: [PATCH 033/106] How to compile with Meson --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eaf1ebfb..845ba036 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 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)) ``` @@ -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>) @@ -175,3 +175,64 @@ 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 +``` + +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) + +If the project includes tests, 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 +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. From ce5a01ca038c9845b0eafb3e7ef69bfc69075803 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 22 Aug 2025 12:07:38 +0200 Subject: [PATCH 034/106] Maybe 'module_polarization.f90' is not necesary? --- meson.build | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/meson.build b/meson.build index 12a4ecce..7af55b3c 100644 --- a/meson.build +++ b/meson.build @@ -75,24 +75,6 @@ common_link_flags = ['-fopenmp'] # For OpenMP # 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_sources = files( - /*'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/cell_force.f90', - 'SCHAModules/module_polarization.f90', - 'SCHAModules/get_odd_straight_with_v4.f90'*/ 'SCHAModules/module_stochastic.f90', 'SCHAModules/module_new_thermodynamic.f90', 'SCHAModules/module_anharmonic.f90', @@ -108,7 +90,8 @@ schamodules_sources = files( 'SCHAModules/get_odd_straight.f90', 'SCHAModules/get_cmat.f90', 'SCHAModules/get_v4.f90', - 'SCHAModules/get_odd_straight_with_v4.f90' + 'SCHAModules/get_odd_straight_with_v4.f90', + 'SCHAModules/module_polarization.f90' ) # Meson's `extension_module` function for Python handles much of the magic. From 409200c860955041252ac1cdf61dc5a997e0d500 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 22 Aug 2025 12:40:13 +0200 Subject: [PATCH 035/106] Set the CellConstructor dependencies --- meson.build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 7af55b3c..e055b5c7 100644 --- a/meson.build +++ b/meson.build @@ -23,6 +23,9 @@ project('python-sscha', 'fortran', 'c', lapack_dep = dependency('lapack', required : true) blas_dep = dependency('blas', required : true) +# SSCHA needs CellConstructor +CellConstructor_dep = dependency('CellConstructor', required : true) + # Look for the OpenMP library if it is needed for parallelization. openmp_dep = dependency('openmp', required: true) @@ -100,7 +103,7 @@ py_mod_schamodules = python_installation.extension_module( 'SCHAModules', schamodules_sources, # Make sure BLAS/LAPACK dependencies are linked correctly - dependencies : [lapack_dep, blas_dep, mpi_dep], + dependencies : [lapack_dep, blas_dep, mpi_dep, CellConstructor_dep], # Fortran-specific flags fortran_args : common_fortran_flags, link_args : common_link_flags, From 717ba1173c91b32b06e4e59d5beef5f537a582eb Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 22 Aug 2025 13:19:15 +0200 Subject: [PATCH 036/106] Just a test of the compilation --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index e055b5c7..acb31253 100644 --- a/meson.build +++ b/meson.build @@ -24,7 +24,7 @@ lapack_dep = dependency('lapack', required : true) blas_dep = dependency('blas', required : true) # SSCHA needs CellConstructor -CellConstructor_dep = dependency('CellConstructor', required : true) +CellConstructor_dep = dependency('cellconstructor', required : true) # Look for the OpenMP library if it is needed for parallelization. openmp_dep = dependency('openmp', required: true) From be9cf60a8c7a52c872d12d7ac85a4f6e0943f0b0 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Sat, 23 Aug 2025 12:00:40 +0200 Subject: [PATCH 037/106] Setting the pytest in Meson --- meson.build | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/meson.build b/meson.build index acb31253..0e2db75f 100644 --- a/meson.build +++ b/meson.build @@ -210,38 +210,6 @@ install_data( # Define el intérprete de Python python = find_program('python3') -# Crea un array con los nombres de todos los scripts que quieres instalar -python_scripts = [ -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', -# 'scripts/read_incomplete_ensemble.py' -] - -# Itera sobre el array y crea un ejecutable para cada script -foreach script : python_scripts - # Obtiene el nombre del archivo de la ruta, por ejemplo 'cluster_check.x' - script_basename = script.split('/')[-1] - - # Divide el nombre por el punto y toma el primer elemento para quitar la extensión - # Si el nombre no tiene punto, esto lo maneja correctamente - script_name_without_ext = script_basename.split('.')[0] - - executable( - script_name_without_ext, -# python, - script, - install: true - ) -endforeach -# executable('sscha','scripts/sscha',install: true) -# executable('cluster_check','scripts/cluster_check.x',install: true) -# executable('plot_frequencies','scripts/plot_frequencies.py',install: true) -# executable('sscha-plot-data','scripts/sscha-plot-data.py',install: true) -# executable('static-vc-relax','scripts/static-vc-relax.pyx', install: true) -# executable('read_incomplete_ensemble','scripts/read_incomplete_ensemble.py',install: true) install_data([ 'scripts/sscha', 'scripts/cluster_check.x', @@ -252,3 +220,4 @@ install_data([ ], install_dir: get_option('bindir') ) +test('pytest', find_program('pytest'), args : ['-v', '-m', 'not release', 'tests']) From 575e4c9e78fb9cba94c17909b9b04e86092fc03b Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Sat, 23 Aug 2025 15:34:49 +0200 Subject: [PATCH 038/106] Undo the CellConstructor bit, it doesn't work --- meson.build | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 0e2db75f..2a14051c 100644 --- a/meson.build +++ b/meson.build @@ -23,9 +23,6 @@ project('python-sscha', 'fortran', 'c', lapack_dep = dependency('lapack', required : true) blas_dep = dependency('blas', required : true) -# SSCHA needs CellConstructor -CellConstructor_dep = dependency('cellconstructor', required : true) - # Look for the OpenMP library if it is needed for parallelization. openmp_dep = dependency('openmp', required: true) @@ -103,7 +100,7 @@ py_mod_schamodules = python_installation.extension_module( 'SCHAModules', schamodules_sources, # Make sure BLAS/LAPACK dependencies are linked correctly - dependencies : [lapack_dep, blas_dep, mpi_dep, CellConstructor_dep], + dependencies : [lapack_dep, blas_dep, mpi_dep], # Fortran-specific flags fortran_args : common_fortran_flags, link_args : common_link_flags, From 3e1a87f95370282e95cd26f98352f8236b1591e3 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 1 Sep 2025 15:10:00 +0200 Subject: [PATCH 039/106] It needs pytest installed for the tests. --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 2a14051c..edcfa473 100644 --- a/meson.build +++ b/meson.build @@ -217,4 +217,6 @@ install_data([ ], install_dir: get_option('bindir') ) -test('pytest', find_program('pytest'), args : ['-v', '-m', 'not release', 'tests']) + +# Establece los test con pytest. (necesita tener pytest instalado) +# test('pytest', find_program('pytest'), args : ['-v', '-m', 'not release', 'tests']) From da4a9623780b2aaea738fff03b6eb411a74405cc Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 1 Sep 2025 15:21:21 +0200 Subject: [PATCH 040/106] Set the project urls --- pyproject.toml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 52c88a06..67158784 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,4 +24,16 @@ dependencies = [ # However, Meson is better at handling scripts like install_data [project.urls] -Homepage = "https://github.com/mesonepigreco/python-sscha" +Homepage = "https://sscha.eu/" +Repository = "https://github.com/mesonepigreco/python-sscha" +# Documentation = "https://documentacion.readthedocs.io/" +# Issues = "https://github.com/mesonepigreco/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/cellconstructor"] # For a non-standard installation From a2bc1d4b6da20d613b19d3f72f4a90478b6450b9 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 1 Sep 2025 15:23:35 +0200 Subject: [PATCH 041/106] Test the cellconstructor as requirement in the build-system. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 67158784..3cdbcc61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["meson-python>=0.13.0", "meson>=1.0", "numpy", "setuptools"] +requires = ["meson-python>=0.13.0", "meson>=1.0", "numpy", "cellconstructor", "setuptools"] build-backend = "mesonpy" [project] From dcf24fe1e127d688baca3056dbd1628262d996e8 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 1 Sep 2025 15:35:03 +0200 Subject: [PATCH 042/106] update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index b968921c..f76c46d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ scipy ase spglib<=2.2 julia +cellconstructor From 991096caeb2cb8b81c057c1aec8a99f080dd271f Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 2 Sep 2025 08:43:24 +0200 Subject: [PATCH 043/106] Added meson-python to implement the Python build system hooks --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3cdbcc61..1e245c78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["meson-python>=0.13.0", "meson>=1.0", "numpy", "cellconstructor", "setuptools"] +requires = ["meson-python>=0.13.0", "meson>=1.0", "numpy", "cellconstructor","meson-python", "setuptools"] build-backend = "mesonpy" [project] From 8c0b8d22d7dfa52a483b8aa7e2c0cb2f30d444f0 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 2 Sep 2025 08:56:02 +0200 Subject: [PATCH 044/106] Test python.install_sources() --- meson.build | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/meson.build b/meson.build index edcfa473..7d412869 100644 --- a/meson.build +++ b/meson.build @@ -136,6 +136,18 @@ py_mod_schamodules = python_installation.extension_module( # 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( + lib_path, + pure: true, + subdir: 'sscha' +) + install_data( 'Modules/__init__.py', 'Modules/AdvancedCalculations.py', From 79974cfdde407f3013085818abb071fd83c887ae Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 2 Sep 2025 09:02:00 +0200 Subject: [PATCH 045/106] Using a direct approach (test install python module) --- meson.build | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 7d412869..78b14889 100644 --- a/meson.build +++ b/meson.build @@ -137,13 +137,13 @@ py_mod_schamodules = python_installation.extension_module( # 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) +#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( - lib_path, + ['Modules/Calculator.py'], pure: true, subdir: 'sscha' ) From f98d35e7d1262ce0908a19900d5d4e349c47f422 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 2 Sep 2025 09:10:12 +0200 Subject: [PATCH 046/106] python.install_sources() do not work as this... --- meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 78b14889..ddaad1a7 100644 --- a/meson.build +++ b/meson.build @@ -142,11 +142,11 @@ py_mod_schamodules = python_installation.extension_module( #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' -) +#python.install_sources( +# ['Modules/Calculator.py'], +# pure: true, +# subdir: 'sscha' +#) install_data( 'Modules/__init__.py', From c2315c0f7d2d2f737506c09f1ca88f2b5959a436 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 2 Sep 2025 11:38:56 +0200 Subject: [PATCH 047/106] (test) I'll will not compile 'module_polarization.f90' --- meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index ddaad1a7..4cd71a76 100644 --- a/meson.build +++ b/meson.build @@ -90,8 +90,8 @@ schamodules_sources = files( 'SCHAModules/get_odd_straight.f90', 'SCHAModules/get_cmat.f90', 'SCHAModules/get_v4.f90', - 'SCHAModules/get_odd_straight_with_v4.f90', - 'SCHAModules/module_polarization.f90' + 'SCHAModules/get_odd_straight_with_v4.f90' + # ,'SCHAModules/module_polarization.f90' ) # Meson's `extension_module` function for Python handles much of the magic. From 226dbc29dd02a6691115382603ba5aa6b0968533 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 2 Sep 2025 13:26:03 +0200 Subject: [PATCH 048/106] Alternative to install_data(); install_subdir() will install all the scripts from a folder. Put as comment as there is a Julia script in the 'Modules' folder. --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index 4cd71a76..d2d862af 100644 --- a/meson.build +++ b/meson.build @@ -148,6 +148,8 @@ py_mod_schamodules = python_installation.extension_module( # subdir: 'sscha' #) +# install_subdir('Modules', install_dir : join_paths(get_option('prefix'), 'share', 'sscha', 'Modules')) + install_data( 'Modules/__init__.py', 'Modules/AdvancedCalculations.py', From e6a6aa5611f47c3c7b2736fa53e0fca723443a40 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 2 Sep 2025 14:01:39 +0200 Subject: [PATCH 049/106] .get_install_dir() gives the python installation place for libraries --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index d2d862af..36c48d3e 100644 --- a/meson.build +++ b/meson.build @@ -149,6 +149,8 @@ py_mod_schamodules = python_installation.extension_module( #) # install_subdir('Modules', install_dir : join_paths(get_option('prefix'), 'share', 'sscha', 'Modules')) +# install_subdir('Modules', install_dir : 'share', strip_directory : false) <-- Not the best option +# install_subdir('Modules', install_dir : python_installation.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries install_data( 'Modules/__init__.py', From 5603e93c8b5164eaf2ee4bb34af3f628a884bc04 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 3 Sep 2025 09:09:01 +0200 Subject: [PATCH 050/106] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 845ba036..c73696b9 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ For example For the development version of the code, subtitute the pip call with the python setup.py install. -### Compiling with Meson +## Compiling with Meson To compile and install SSCHA with Meson, follow these typical steps: @@ -215,7 +215,7 @@ This will compile the source code according to the configuration from the previo ### 4. Run Tests (Optional) -If the project includes tests, you can run them with: +The project includes tests, you need to install pytest and uncomment the last two lines of 'meson.build' to work. You can run them with: ```bash meson test From d9f7761037770cef0abd690f63a2ef0e947d8fee Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 3 Sep 2025 09:11:32 +0200 Subject: [PATCH 051/106] Update 'README.md' with instructions for running the tests. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c73696b9..689a754e 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ This will compile the source code according to the configuration from the previo ### 4. Run Tests (Optional) -The project includes tests, you need to install pytest and uncomment the last two lines of 'meson.build' to work. You can run them with: +The project includes tests, you need to install pytest and uncomment the last line of 'meson.build' to work. You can run them with: ```bash meson test From d4274f8b4af002836331906d9d6a05e329099cb6 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 3 Sep 2025 10:25:02 +0200 Subject: [PATCH 052/106] Automatic check for pytest --- meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/meson.build b/meson.build index 36c48d3e..e48183ed 100644 --- a/meson.build +++ b/meson.build @@ -236,3 +236,8 @@ install_dir: get_option('bindir') # Establece los test con pytest. (necesita tener pytest instalado) # test('pytest', find_program('pytest'), args : ['-v', '-m', 'not release', 'tests']) +pytest_exe = find_program('pytest', required: true) + +test('pytest', pytest_exe, + args : ['-v', '-m', 'not release', 'tests'], + workdir : meson.source_root()) From f68d23693e197d85759fdbfe41339e578679bfc7 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 3 Sep 2025 10:30:51 +0200 Subject: [PATCH 053/106] If no pytest installed, do no test. --- meson.build | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index e48183ed..2de7f48e 100644 --- a/meson.build +++ b/meson.build @@ -235,9 +235,12 @@ install_dir: get_option('bindir') ) # Establece los test con pytest. (necesita tener pytest instalado) -# test('pytest', find_program('pytest'), args : ['-v', '-m', 'not release', 'tests']) -pytest_exe = find_program('pytest', required: true) +pytest_exe = find_program('pytest', required: false) -test('pytest', pytest_exe, - args : ['-v', '-m', 'not release', 'tests'], - workdir : meson.source_root()) +if pytest_exe.found() + test('pytest', pytest_exe, + args : ['-v', '-m', 'not release', 'tests'], + workdir : meson.source_root()) +else + message('pytest no encontrado; se omiten tests con pytest.') +endif From c026bcb8183a6e64b9a54bd520e15c86055eda7d Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 3 Sep 2025 10:38:04 +0200 Subject: [PATCH 054/106] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 689a754e..a110eeae 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ This will compile the source code according to the configuration from the previo ### 4. Run Tests (Optional) -The project includes tests, you need to install pytest and uncomment the last line of 'meson.build' to work. You can run them with: +The project includes tests, you need to install pytest to work. You can run them with: ```bash meson test From f6e8432fcd5189c774b80d9ec52968375d3bb617 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 4 Sep 2025 08:15:27 +0200 Subject: [PATCH 055/106] (Commented) method for installing python sources by Meson. --- meson.build | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/meson.build b/meson.build index 2de7f48e..1def3ad6 100644 --- a/meson.build +++ b/meson.build @@ -233,6 +233,14 @@ install_data([ ], install_dir: get_option('bindir') ) +# python.install_sources(['scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx', +# 'scripts/read_incomplete_ensemble.py' +#]) + # Establece los test con pytest. (necesita tener pytest instalado) pytest_exe = find_program('pytest', required: false) From 921198c775952dc8ccc0f5e7b6f1752cd1684ac5 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 10:00:07 +0200 Subject: [PATCH 056/106] Test with pytest from Meson --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c3a921a..06615056 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: - name: Install Python dependencies run: | - pip install meson ninja meson-python numpy scipy ase + pip install meson ninja meson-python numpy scipy ase pytest - name: Setup build directory run: meson setup builddir From 43e8c9b7da3b4f394ad713a7d07d98a06dea603d Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 10:19:30 +0200 Subject: [PATCH 057/106] Maybe run the tests after install the scripts. --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 06615056..03de4fde 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,8 +29,8 @@ jobs: - name: Compile run: meson compile -C builddir + - name: Install package + run: meson install -C builddir + - name: Run tests run: meson test -C builddir - -# - name: Install package -# run: meson install -C builddir From a635bae547f52805fb62fc66efeeea0ee462c972 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 10:22:50 +0200 Subject: [PATCH 058/106] No install on github?? --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 03de4fde..54551a98 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,8 +29,8 @@ jobs: - name: Compile run: meson compile -C builddir - - name: Install package - run: meson install -C builddir +# - name: Install package +# run: meson install -C builddir - - name: Run tests - run: meson test -C builddir +# - name: Run tests +# run: meson test -C builddir From 524c141784c8d87d3d4928b142f15cb0e46e0958 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 11:54:39 +0200 Subject: [PATCH 059/106] Forcing the RPATH --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index 1def3ad6..c7dcdba9 100644 --- a/meson.build +++ b/meson.build @@ -108,6 +108,7 @@ py_mod_schamodules = python_installation.extension_module( # This is the equivalent of extra_f90_compile_args and extra_link_args # in setup.py for the Fortran module. include_directories: include_directories(numpy_incdir), + install_rpath: '$ORIGIN/..' ) # --- Module odd_HP (C) --- From 6386d5a3517fbe27dbedf359ab33a1edb7e06360 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 12:00:15 +0200 Subject: [PATCH 060/106] Automatic install RPATH --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index c7dcdba9..cf9a4fe6 100644 --- a/meson.build +++ b/meson.build @@ -108,7 +108,7 @@ py_mod_schamodules = python_installation.extension_module( # This is the equivalent of extra_f90_compile_args and extra_link_args # in setup.py for the Fortran module. include_directories: include_directories(numpy_incdir), - install_rpath: '$ORIGIN/..' + install_rpath: true, ) # --- Module odd_HP (C) --- From 799a08cebe3c137016669b347b4ea7729ec4a9f8 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 12:05:49 +0200 Subject: [PATCH 061/106] Fix typo --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index cf9a4fe6..d839614b 100644 --- a/meson.build +++ b/meson.build @@ -108,7 +108,7 @@ py_mod_schamodules = python_installation.extension_module( # This is the equivalent of extra_f90_compile_args and extra_link_args # in setup.py for the Fortran module. include_directories: include_directories(numpy_incdir), - install_rpath: true, + install_rpath: true ) # --- Module odd_HP (C) --- From ddb85a5904c3675e403371d64c1cdf6dc7aacb21 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 12:14:44 +0200 Subject: [PATCH 062/106] No boolean here --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index d839614b..c7dcdba9 100644 --- a/meson.build +++ b/meson.build @@ -108,7 +108,7 @@ py_mod_schamodules = python_installation.extension_module( # This is the equivalent of extra_f90_compile_args and extra_link_args # in setup.py for the Fortran module. include_directories: include_directories(numpy_incdir), - install_rpath: true + install_rpath: '$ORIGIN/..' ) # --- Module odd_HP (C) --- From c209900329fdd30f77709f6f87b86f32bb74f82c Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 12:20:25 +0200 Subject: [PATCH 063/106] WARNING: Project does not target a minimum version but uses feature deprecated since '0.56.0': meson.source_root. use meson.project_source_root() or meson.global_source_root() instead. --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index c7dcdba9..7191640c 100644 --- a/meson.build +++ b/meson.build @@ -249,7 +249,7 @@ pytest_exe = find_program('pytest', required: false) if pytest_exe.found() test('pytest', pytest_exe, args : ['-v', '-m', 'not release', 'tests'], - workdir : meson.source_root()) + workdir : meson.project_source_root()) else message('pytest no encontrado; se omiten tests con pytest.') endif From 081aeada0c1cdef14d9d462d5b74828461a5e8ed Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 13:52:03 +0200 Subject: [PATCH 064/106] Change installation dir from sscha to python-sscha --- meson.build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 7191640c..6d237781 100644 --- a/meson.build +++ b/meson.build @@ -149,7 +149,7 @@ py_mod_schamodules = python_installation.extension_module( # subdir: 'sscha' #) -# install_subdir('Modules', install_dir : join_paths(get_option('prefix'), 'share', 'sscha', 'Modules')) +# 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 : python_installation.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries @@ -170,7 +170,7 @@ install_data( 'Modules/SchaMinimizer.py', 'Modules/Tools.py', 'Modules/Utilities.py', - install_dir: python_installation.get_install_dir() / 'sscha', + install_dir: python_installation.get_install_dir() / 'python-sscha', ) # --- Installing Scripts --- @@ -206,7 +206,7 @@ install_data( # and copy the .jl files there. install_data( ['Modules/fourier_gradient.jl'], # List the .jl files you need - install_dir : python_installation.get_install_dir() / 'sscha' + install_dir : python_installation.get_install_dir() / 'python-sscha' ) # If there are many .jl files in multiple subdirectories, # you would need to use 'install_subdir' or list them all explicitly. From ab91b707692fe894895b8bda21714ff044d5e8ff Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 5 Sep 2025 14:06:30 +0200 Subject: [PATCH 065/106] Changed 'meson.build' to install python scripts. --- meson.build | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index 6d237781..4f0fc515 100644 --- a/meson.build +++ b/meson.build @@ -222,25 +222,26 @@ install_data( # configuration: conf) # Define el intérprete de Python -python = find_program('python3') +#python = find_program('python3') -install_data([ +#install_data([ +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx', +# 'scripts/read_incomplete_ensemble.py' +#], +#install_dir: get_option('bindir') +#) +python_installation.install_sources([ 'scripts/sscha', 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', 'scripts/static-vc-relax.pyx', 'scripts/read_incomplete_ensemble.py' -], -install_dir: get_option('bindir') -) -# python.install_sources(['scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', -# 'scripts/read_incomplete_ensemble.py' -#]) +]) # Establece los test con pytest. (necesita tener pytest instalado) From 2120282c94fa25ec95ff4736fdc0fd7b3ccfabe7 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 8 Sep 2025 09:17:37 +0200 Subject: [PATCH 066/106] Try with f2py C wrapper --- meson.build | 69 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 4f0fc515..53b8b7f5 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,13 @@ project('python-sscha', 'fortran', 'c', check: true ).stdout().strip() + # Find the fpm and f2py programs + fpm_exe = find_program('fpm', required: true) + f2py_exe = python.find_installation().find_program('f2py', required: true) + + # Define the build directory for fpm + fpm_build_dir = meson.build_root() / 'fpm_build' + # --- BLAS/LAPACK Dependencies --- # Meson will attempt to automatically detect LAPACK and BLAS. # You don't need 'lapack_opt' as in numpy.distutils. @@ -74,6 +81,19 @@ 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. + +# Use fpm to build and install your Fortran sources +run_command( + fpm_exe, + 'install', + '--flag', ['-g', '-fPIC', '-O2', '-fopenmp'], + '--prefix', fpm_build_dir, + check : true +) + + +# --- La extensión SCHAModules --- +# Estas son las fuentes de Fortran que serán procesadas por f2py schamodules_sources = files( 'SCHAModules/module_stochastic.f90', 'SCHAModules/module_new_thermodynamic.f90', @@ -94,22 +114,53 @@ schamodules_sources = files( # ,'SCHAModules/module_polarization.f90' ) +# Usa f2py para crear el wrapper de C +SCHAModules_wrapper = custom_target( + '_f2py_wrapper', + input: schamodules_sources, + output: 'schamodules-f2pywrappers.c', + command: [ + f2py_exe, + '-m', 'schamodules', # El nombre del módulo + '@INPUT@', + '--quiet', + '--lower' + ], + build_by_default: true +) +# Crea el módulo de extensión de Python +py_sschamodules_ext = python_installation.extension_module( + 'SCHAModules', # Nombre del módulo resultante + # Ahora pasamos el wrapper de C generado y la librería estática de fpm + symph_wrapper, + fpm_build_dir / 'lib' / 'libschamodules.a', + install: true, + include_directories: [ + include_directories(numpy_incdir), + fpm_build_dir / 'include' # Directorio de inclusión para módulos Fortran + ], + dependencies: [lapack_dep, blas_dep, mpi_dep], + link_args: ['-fopenmp'], + install_rpath: '$ORIGIN/..' +) + + # Meson's `extension_module` function for Python handles much of the magic. # 'SCHAModules' will be the name of the resulting Python module. -py_mod_schamodules = python_installation.extension_module( - 'SCHAModules', - schamodules_sources, +#py_mod_schamodules = python_installation.extension_module( +# 'SCHAModules', +# schamodules_sources, # Make sure BLAS/LAPACK dependencies are linked correctly - dependencies : [lapack_dep, blas_dep, mpi_dep], +# dependencies : [lapack_dep, blas_dep, mpi_dep], # Fortran-specific flags - fortran_args : common_fortran_flags, - link_args : common_link_flags, +# fortran_args : common_fortran_flags, +# link_args : common_link_flags, # Add -fPIC for Linux if needed (Meson usually handles this) # This is the equivalent of extra_f90_compile_args and extra_link_args # in setup.py for the Fortran module. - include_directories: include_directories(numpy_incdir), - install_rpath: '$ORIGIN/..' -) +# include_directories: include_directories(numpy_incdir), +# install_rpath: '$ORIGIN/..' +#) # --- Module odd_HP (C) --- # Uncomment and adapt if you want to include this module. From b76d76fa2eb4395ab16da82dfca48ad95d897e8c Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 8 Sep 2025 09:28:25 +0200 Subject: [PATCH 067/106] Added "Fortran Package Manager" into the pip install list --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 54551a98..9a4c7c90 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: - name: Install Python dependencies run: | - pip install meson ninja meson-python numpy scipy ase pytest + pip install meson ninja meson-python numpy scipy ase pytest fpm - name: Setup build directory run: meson setup builddir From d252d89a3e48aecf1bc15f98655429284009d40e Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 8 Sep 2025 09:41:13 +0200 Subject: [PATCH 068/106] Fix error --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 53b8b7f5..b9bf22a4 100644 --- a/meson.build +++ b/meson.build @@ -17,7 +17,7 @@ project('python-sscha', 'fortran', 'c', # Find the fpm and f2py programs fpm_exe = find_program('fpm', required: true) - f2py_exe = python.find_installation().find_program('f2py', required: true) + f2py_exe = python.find_program('f2py', required: true) # Define the build directory for fpm fpm_build_dir = meson.build_root() / 'fpm_build' From 68693b0cf4b59080fbf7d941a7e82b79748328e4 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 12 Sep 2025 11:02:12 +0200 Subject: [PATCH 069/106] Update 'meson.build' with all we learned fron cellconstructor --- meson.build | 41 +++++-- meson.build.old | 307 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 341 insertions(+), 7 deletions(-) create mode 100644 meson.build.old diff --git a/meson.build b/meson.build index b9bf22a4..b26e38e0 100644 --- a/meson.build +++ b/meson.build @@ -10,10 +10,35 @@ project('python-sscha', 'fortran', 'c', # Imports the Meson Python module to handle extensions and Python installation. python = import('python') python_installation = python.find_installation() + py_dep = dependency('python3', required: true) + + # Obtenemos la ruta principal de los headers de numpy numpy_incdir = run_command( python_installation, '-c', 'import numpy; print(numpy.get_include())', check: true ).stdout().strip() +# Obtenemos la ruta padre para incluir los headers de numpy anidados +numpy_parent_incdir = run_command( + python_installation, '-c', 'import os, numpy; print(os.path.dirname(numpy.get_include()))', + check: true +).stdout().strip() + +# Obtenemos la ruta específica para los headers de f2py +f2py_incdir = run_command( + python_installation, '-c', 'import os, numpy.f2py; print(os.path.join(os.path.dirname(numpy.f2py.__file__), "src"))', + check: true +).stdout().strip() + +# Creamos una lista de directorios de inclusión para usar en todas las extensiones +include_dirs = include_directories(numpy_incdir, numpy_parent_incdir, f2py_incdir, '.') + +# Obtenemos la ruta de la biblioteca de f2py para la vinculación +f2py_libdir = run_command( + python_installation, '-c', 'import os, numpy.f2py; print(os.path.join(os.path.dirname(os.path.dirname(numpy.f2py.__file__)), "core", "lib"))', + check: true +).stdout().strip() +# Obtenemos la ruta del directorio de bibliotecas de Python +py_libdir = python_installation.get_install_dir() / 'lib' # Find the fpm and f2py programs fpm_exe = find_program('fpm', required: true) @@ -132,15 +157,17 @@ SCHAModules_wrapper = custom_target( py_sschamodules_ext = python_installation.extension_module( 'SCHAModules', # Nombre del módulo resultante # Ahora pasamos el wrapper de C generado y la librería estática de fpm - symph_wrapper, - fpm_build_dir / 'lib' / 'libschamodules.a', + [symph_wrapper,schamodules_sources], + #fpm_build_dir / 'lib' / 'libschamodules.a', install: true, - include_directories: [ - include_directories(numpy_incdir), - fpm_build_dir / 'include' # Directorio de inclusión para módulos Fortran - ], - dependencies: [lapack_dep, blas_dep, mpi_dep], + include_directories: include_dirs, + #[ + # include_directories(numpy_incdir), + # fpm_build_dir / 'include' # Directorio de inclusión para módulos Fortran + #], + dependencies: [lapack_dep, blas_dep, mpi_dep, py_dep], link_args: ['-fopenmp'], + fortran_args: ['-cpp'], install_rpath: '$ORIGIN/..' ) diff --git a/meson.build.old b/meson.build.old new file mode 100644 index 00000000..b9bf22a4 --- /dev/null +++ b/meson.build.old @@ -0,0 +1,307 @@ +project('python-sscha', 'fortran', 'c', + version : '1.4.2', + license: 'GPL', +# Common compilation options for Fortran. +# -cpp is essential for the Fortran preprocessor. +# -O2 is a general optimization you had in setup.py. + default_options : ['warning_level=1','fortran_args=-cpp', 'fortran_args=-O2']) + + # --- System and Python Dependencies --- + # Imports the Meson Python module to handle extensions and Python installation. + python = import('python') + python_installation = python.find_installation() + numpy_incdir = run_command( + python_installation, '-c', 'import numpy; print(numpy.get_include())', + check: true + ).stdout().strip() + + # Find the fpm and f2py programs + fpm_exe = find_program('fpm', required: true) + f2py_exe = python.find_program('f2py', required: true) + + # Define the build directory for fpm + fpm_build_dir = meson.build_root() / 'fpm_build' + +# --- 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'). +lapack_dep = dependency('lapack', required : true) +blas_dep = dependency('blas', required : true) + +# 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 + +# --- Python 2/3 Detection (not as relevant anymore, but translated) --- +# In Meson, this would be done based on the Python version Meson is using. +# Since Python 2 is EOL, this check is generally not needed. +# However, if you want to keep the flag: +#py2_flag = [] +#if py_dep.version().version_compare('<3.0') +# message('Running on Python 2, adding the flag -D_PYTHON2') +# py2_flag += ['-D_PYTHON2'] +#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. + +# Use fpm to build and install your Fortran sources +run_command( + fpm_exe, + 'install', + '--flag', ['-g', '-fPIC', '-O2', '-fopenmp'], + '--prefix', fpm_build_dir, + check : true +) + + +# --- La extensión SCHAModules --- +# Estas son las fuentes de Fortran que serán procesadas por f2py +schamodules_sources = files( + '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' +) + +# Usa f2py para crear el wrapper de C +SCHAModules_wrapper = custom_target( + '_f2py_wrapper', + input: schamodules_sources, + output: 'schamodules-f2pywrappers.c', + command: [ + f2py_exe, + '-m', 'schamodules', # El nombre del módulo + '@INPUT@', + '--quiet', + '--lower' + ], + build_by_default: true +) +# Crea el módulo de extensión de Python +py_sschamodules_ext = python_installation.extension_module( + 'SCHAModules', # Nombre del módulo resultante + # Ahora pasamos el wrapper de C generado y la librería estática de fpm + symph_wrapper, + fpm_build_dir / 'lib' / 'libschamodules.a', + install: true, + include_directories: [ + include_directories(numpy_incdir), + fpm_build_dir / 'include' # Directorio de inclusión para módulos Fortran + ], + dependencies: [lapack_dep, blas_dep, mpi_dep], + link_args: ['-fopenmp'], + install_rpath: '$ORIGIN/..' +) + + +# Meson's `extension_module` function for Python handles much of the magic. +# 'SCHAModules' will be the name of the resulting Python module. +#py_mod_schamodules = python_installation.extension_module( +# 'SCHAModules', +# schamodules_sources, + # Make sure BLAS/LAPACK dependencies are linked correctly +# dependencies : [lapack_dep, blas_dep, mpi_dep], + # Fortran-specific flags +# fortran_args : common_fortran_flags, +# link_args : common_link_flags, + # Add -fPIC for Linux if needed (Meson usually handles this) + # This is the equivalent of extra_f90_compile_args and extra_link_args + # in setup.py for the Fortran module. +# include_directories: include_directories(numpy_incdir), +# install_rpath: '$ORIGIN/..' +#) + +# --- 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 : python_installation.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries + +install_data( + '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', + install_dir: python_installation.get_install_dir() / 'python-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/). +#executable( +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente +# 'scripts/read_incomplete_ensemble.py' +#, install : true) +#install_data = ( +# [ +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx')#, # Si esto es un script ejecutable directamente +# 'scripts/read_incomplete_ensemble.py' +# ], +# install_dir: get_option('bindir') +# ) + +#foreach s : install_scripts +# install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin +#endforeach + +# --- 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 : python_installation.get_install_dir() / 'python-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) + +# Define el intérprete de Python +#python = find_program('python3') + +#install_data([ +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx', +# 'scripts/read_incomplete_ensemble.py' +#], +#install_dir: get_option('bindir') +#) +python_installation.install_sources([ + 'scripts/sscha', + 'scripts/cluster_check.x', + 'scripts/plot_frequencies.py', + 'scripts/sscha-plot-data.py', + 'scripts/static-vc-relax.pyx', + 'scripts/read_incomplete_ensemble.py' +]) + + +# Establece los test con pytest. (necesita tener pytest instalado) +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 no encontrado; se omiten tests con pytest.') +endif From 062eb1a8fe230dd27c5715da55643c9bc4082f9f Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 12 Sep 2025 11:06:02 +0200 Subject: [PATCH 070/106] Fix f2py_exe --- meson.build | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index b26e38e0..a0057da7 100644 --- a/meson.build +++ b/meson.build @@ -41,8 +41,10 @@ f2py_libdir = run_command( py_libdir = python_installation.get_install_dir() / 'lib' # Find the fpm and f2py programs - fpm_exe = find_program('fpm', required: true) - f2py_exe = python.find_program('f2py', required: true) + #fpm_exe = find_program('fpm', required: true) + #f2py_exe = python.find_program('f2py', required: true) + f2py_exe = find_program('f2py', required: true) + # Define the build directory for fpm fpm_build_dir = meson.build_root() / 'fpm_build' From 993bcd4c11e3cf03946fd559164065c0af3fc433 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 12 Sep 2025 11:08:59 +0200 Subject: [PATCH 071/106] Fix unused fpm --- meson.build | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index a0057da7..31b69c71 100644 --- a/meson.build +++ b/meson.build @@ -110,13 +110,13 @@ common_link_flags = ['-fopenmp'] # For OpenMP # Note: The Fortran extension will generate a .so or .pyd file that Python can import. # Use fpm to build and install your Fortran sources -run_command( - fpm_exe, - 'install', - '--flag', ['-g', '-fPIC', '-O2', '-fopenmp'], - '--prefix', fpm_build_dir, - check : true -) +#run_command( +# fpm_exe, +# 'install', +# '--flag', ['-g', '-fPIC', '-O2', '-fopenmp'], +# '--prefix', fpm_build_dir, +# check : true +#) # --- La extensión SCHAModules --- From c8b17d225be4f2726d8506c89ad7a2bead4370f8 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 12 Sep 2025 11:15:56 +0200 Subject: [PATCH 072/106] QuickFix, solved naming error in call --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 31b69c71..3106ca5b 100644 --- a/meson.build +++ b/meson.build @@ -159,7 +159,7 @@ SCHAModules_wrapper = custom_target( py_sschamodules_ext = python_installation.extension_module( 'SCHAModules', # Nombre del módulo resultante # Ahora pasamos el wrapper de C generado y la librería estática de fpm - [symph_wrapper,schamodules_sources], + [SCHAModules_wrapper,schamodules_sources], #fpm_build_dir / 'lib' / 'libschamodules.a', install: true, include_directories: include_dirs, From b1a6da730cbdaa7afbc52f86f1678f96820e677a Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 12 Sep 2025 11:24:38 +0200 Subject: [PATCH 073/106] Fix naming conventions --- meson.build | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 3106ca5b..04a03075 100644 --- a/meson.build +++ b/meson.build @@ -47,7 +47,7 @@ py_libdir = python_installation.get_install_dir() / 'lib' # Define the build directory for fpm - fpm_build_dir = meson.build_root() / 'fpm_build' + #fpm_build_dir = meson.build_root() / 'fpm_build' # --- BLAS/LAPACK Dependencies --- # Meson will attempt to automatically detect LAPACK and BLAS. @@ -143,9 +143,10 @@ schamodules_sources = files( # Usa f2py para crear el wrapper de C SCHAModules_wrapper = custom_target( - '_f2py_wrapper', + 'schamodules_f2py_wrapper', input: schamodules_sources, - output: 'schamodules-f2pywrappers.c', + output: 'schamodulesmodule.c', + #output: 'schamodules-f2pywrappers.c', command: [ f2py_exe, '-m', 'schamodules', # El nombre del módulo From 085ae836a526ca73e0acbf1e2904f3e6efe9bfd8 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 17 Sep 2025 13:44:41 +0200 Subject: [PATCH 074/106] Update with all we learned from CellConstructor --- meson.build | 323 ++++++++++++++++----------------------------- meson.build.old2 | 337 +++++++++++++++++++++++++++++++++++++++++++++++ meson.options | 3 + 3 files changed, 457 insertions(+), 206 deletions(-) create mode 100644 meson.build.old2 create mode 100644 meson.options diff --git a/meson.build b/meson.build index 04a03075..ef1fd815 100644 --- a/meson.build +++ b/meson.build @@ -1,105 +1,104 @@ -project('python-sscha', 'fortran', 'c', +project('python-sscha', + ['c','fortran'], version : '1.4.2', license: 'GPL', -# Common compilation options for Fortran. -# -cpp is essential for the Fortran preprocessor. -# -O2 is a general optimization you had in setup.py. - default_options : ['warning_level=1','fortran_args=-cpp', 'fortran_args=-O2']) + 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. - python = import('python') - python_installation = python.find_installation() - py_dep = dependency('python3', required: true) - - # Obtenemos la ruta principal de los headers de numpy - numpy_incdir = run_command( - python_installation, '-c', 'import numpy; print(numpy.get_include())', - check: true + # --- Opciones de compilación --- + use_mkl = get_option('use_mkl') + + # --- System and Python Dependencies --- + # Encuentra las instalaciones necesarias + py = import('python').find_installation(pure: false) + py_dep = py.dependency() + fc = meson.get_compiler('fortran') + + # Dependencias adicionales + + # --- 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 + # Busca la librería quadmath, si está disponible + quadmath_dep = fc.find_library('quadmath', required: false) + + # --- CONFIGURACIÓN DE NUMPY --- + # Obtiene la ruta de los directorios de cabecera de NumPy y f2py usando el comando de Python + incdir_numpy = run_command(py, + ['-c', 'import numpy; print(numpy.get_include())'], + check : true ).stdout().strip() -# Obtenemos la ruta padre para incluir los headers de numpy anidados -numpy_parent_incdir = run_command( - python_installation, '-c', 'import os, numpy; print(os.path.dirname(numpy.get_include()))', - check: true -).stdout().strip() - -# Obtenemos la ruta específica para los headers de f2py -f2py_incdir = run_command( - python_installation, '-c', 'import os, numpy.f2py; print(os.path.join(os.path.dirname(numpy.f2py.__file__), "src"))', - check: true -).stdout().strip() - -# Creamos una lista de directorios de inclusión para usar en todas las extensiones -include_dirs = include_directories(numpy_incdir, numpy_parent_incdir, f2py_incdir, '.') - -# Obtenemos la ruta de la biblioteca de f2py para la vinculación -f2py_libdir = run_command( - python_installation, '-c', 'import os, numpy.f2py; print(os.path.join(os.path.dirname(os.path.dirname(numpy.f2py.__file__)), "core", "lib"))', - check: true -).stdout().strip() -# Obtenemos la ruta del directorio de bibliotecas de Python -py_libdir = python_installation.get_install_dir() / 'lib' - - # Find the fpm and f2py programs - #fpm_exe = find_program('fpm', required: true) - #f2py_exe = python.find_program('f2py', required: true) - f2py_exe = find_program('f2py', required: true) - - - # Define the build directory for fpm - #fpm_build_dir = meson.build_root() / 'fpm_build' - -# --- 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'). -lapack_dep = dependency('lapack', required : true) -blas_dep = dependency('blas', required : true) - -# 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 -# --- Python 2/3 Detection (not as relevant anymore, but translated) --- -# In Meson, this would be done based on the Python version Meson is using. -# Since Python 2 is EOL, this check is generally not needed. -# However, if you want to keep the flag: -#py2_flag = [] -#if py_dep.version().version_compare('<3.0') -# message('Running on Python 2, adding the flag -D_PYTHON2') -# py2_flag += ['-D_PYTHON2'] -#endif + # f2py también requiere la cabecera fortranobject.h + 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) + + # --- FIN DE LA CONFIGURACIÓN DE NUMPY --- + #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'] @@ -109,19 +108,9 @@ common_link_flags = ['-fopenmp'] # For OpenMP # 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. -# Use fpm to build and install your Fortran sources -#run_command( -# fpm_exe, -# 'install', -# '--flag', ['-g', '-fPIC', '-O2', '-fopenmp'], -# '--prefix', fpm_build_dir, -# check : true -#) - - # --- La extensión SCHAModules --- -# Estas son las fuentes de Fortran que serán procesadas por f2py -schamodules_sources = files( + +schamodules_sources = [ 'SCHAModules/module_stochastic.f90', 'SCHAModules/module_new_thermodynamic.f90', 'SCHAModules/module_anharmonic.f90', @@ -139,59 +128,17 @@ schamodules_sources = files( 'SCHAModules/get_v4.f90', 'SCHAModules/get_odd_straight_with_v4.f90' # ,'SCHAModules/module_polarization.f90' +] + +py.extension_module('SCHAModules', + schamodules_sources, +# f2py_c_source, # <- Cambio aplicado +# c_args: ['-DF2PY_SETUP_RUN'], # <--- Solucinar "_npy_f2py_ARRAY_API" + include_directories: inc_np, + dependencies: list_dep, + install: true ) -# Usa f2py para crear el wrapper de C -SCHAModules_wrapper = custom_target( - 'schamodules_f2py_wrapper', - input: schamodules_sources, - output: 'schamodulesmodule.c', - #output: 'schamodules-f2pywrappers.c', - command: [ - f2py_exe, - '-m', 'schamodules', # El nombre del módulo - '@INPUT@', - '--quiet', - '--lower' - ], - build_by_default: true -) -# Crea el módulo de extensión de Python -py_sschamodules_ext = python_installation.extension_module( - 'SCHAModules', # Nombre del módulo resultante - # Ahora pasamos el wrapper de C generado y la librería estática de fpm - [SCHAModules_wrapper,schamodules_sources], - #fpm_build_dir / 'lib' / 'libschamodules.a', - install: true, - include_directories: include_dirs, - #[ - # include_directories(numpy_incdir), - # fpm_build_dir / 'include' # Directorio de inclusión para módulos Fortran - #], - dependencies: [lapack_dep, blas_dep, mpi_dep, py_dep], - link_args: ['-fopenmp'], - fortran_args: ['-cpp'], - install_rpath: '$ORIGIN/..' -) - - -# Meson's `extension_module` function for Python handles much of the magic. -# 'SCHAModules' will be the name of the resulting Python module. -#py_mod_schamodules = python_installation.extension_module( -# 'SCHAModules', -# schamodules_sources, - # Make sure BLAS/LAPACK dependencies are linked correctly -# dependencies : [lapack_dep, blas_dep, mpi_dep], - # Fortran-specific flags -# fortran_args : common_fortran_flags, -# link_args : common_link_flags, - # Add -fPIC for Linux if needed (Meson usually handles this) - # This is the equivalent of extra_f90_compile_args and extra_link_args - # in setup.py for the Fortran module. -# include_directories: include_directories(numpy_incdir), -# install_rpath: '$ORIGIN/..' -#) - # --- Module odd_HP (C) --- # Uncomment and adapt if you want to include this module. # This would be done similarly to the Fortran module. @@ -232,7 +179,7 @@ py_sschamodules_ext = python_installation.extension_module( # 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 : python_installation.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries +# install_subdir('Modules', install_dir : py.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries install_data( 'Modules/__init__.py', @@ -251,35 +198,21 @@ install_data( 'Modules/SchaMinimizer.py', 'Modules/Tools.py', 'Modules/Utilities.py', - install_dir: python_installation.get_install_dir() / 'python-sscha', + install_dir: py.get_install_dir() / 'python-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/). -#executable( -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente -# 'scripts/read_incomplete_ensemble.py' -#, install : true) -#install_data = ( -# [ -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx')#, # Si esto es un script ejecutable directamente -# 'scripts/read_incomplete_ensemble.py' -# ], -# install_dir: get_option('bindir') -# ) - -#foreach s : install_scripts -# install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin -#endforeach + +py.install_sources([ + 'scripts/sscha', + '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"]} @@ -287,7 +220,7 @@ install_data( # and copy the .jl files there. install_data( ['Modules/fourier_gradient.jl'], # List the .jl files you need - install_dir : python_installation.get_install_dir() / 'python-sscha' + install_dir : py.get_install_dir() / 'python-sscha' ) # If there are many .jl files in multiple subdirectories, # you would need to use 'install_subdir' or list them all explicitly. @@ -302,28 +235,6 @@ install_data( # output: 'my_module/version.py', # configuration: conf) -# Define el intérprete de Python -#python = find_program('python3') - -#install_data([ -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', -# 'scripts/read_incomplete_ensemble.py' -#], -#install_dir: get_option('bindir') -#) -python_installation.install_sources([ - 'scripts/sscha', - 'scripts/cluster_check.x', - 'scripts/plot_frequencies.py', - 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx', - 'scripts/read_incomplete_ensemble.py' -]) - # Establece los test con pytest. (necesita tener pytest instalado) pytest_exe = find_program('pytest', required: false) diff --git a/meson.build.old2 b/meson.build.old2 new file mode 100644 index 00000000..04a03075 --- /dev/null +++ b/meson.build.old2 @@ -0,0 +1,337 @@ +project('python-sscha', 'fortran', 'c', + version : '1.4.2', + license: 'GPL', +# Common compilation options for Fortran. +# -cpp is essential for the Fortran preprocessor. +# -O2 is a general optimization you had in setup.py. + default_options : ['warning_level=1','fortran_args=-cpp', 'fortran_args=-O2']) + + # --- System and Python Dependencies --- + # Imports the Meson Python module to handle extensions and Python installation. + python = import('python') + python_installation = python.find_installation() + py_dep = dependency('python3', required: true) + + # Obtenemos la ruta principal de los headers de numpy + numpy_incdir = run_command( + python_installation, '-c', 'import numpy; print(numpy.get_include())', + check: true + ).stdout().strip() +# Obtenemos la ruta padre para incluir los headers de numpy anidados +numpy_parent_incdir = run_command( + python_installation, '-c', 'import os, numpy; print(os.path.dirname(numpy.get_include()))', + check: true +).stdout().strip() + +# Obtenemos la ruta específica para los headers de f2py +f2py_incdir = run_command( + python_installation, '-c', 'import os, numpy.f2py; print(os.path.join(os.path.dirname(numpy.f2py.__file__), "src"))', + check: true +).stdout().strip() + +# Creamos una lista de directorios de inclusión para usar en todas las extensiones +include_dirs = include_directories(numpy_incdir, numpy_parent_incdir, f2py_incdir, '.') + +# Obtenemos la ruta de la biblioteca de f2py para la vinculación +f2py_libdir = run_command( + python_installation, '-c', 'import os, numpy.f2py; print(os.path.join(os.path.dirname(os.path.dirname(numpy.f2py.__file__)), "core", "lib"))', + check: true +).stdout().strip() +# Obtenemos la ruta del directorio de bibliotecas de Python +py_libdir = python_installation.get_install_dir() / 'lib' + + # Find the fpm and f2py programs + #fpm_exe = find_program('fpm', required: true) + #f2py_exe = python.find_program('f2py', required: true) + f2py_exe = find_program('f2py', required: true) + + + # Define the build directory for fpm + #fpm_build_dir = meson.build_root() / 'fpm_build' + +# --- 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'). +lapack_dep = dependency('lapack', required : true) +blas_dep = dependency('blas', required : true) + +# 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 + +# --- Python 2/3 Detection (not as relevant anymore, but translated) --- +# In Meson, this would be done based on the Python version Meson is using. +# Since Python 2 is EOL, this check is generally not needed. +# However, if you want to keep the flag: +#py2_flag = [] +#if py_dep.version().version_compare('<3.0') +# message('Running on Python 2, adding the flag -D_PYTHON2') +# py2_flag += ['-D_PYTHON2'] +#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. + +# Use fpm to build and install your Fortran sources +#run_command( +# fpm_exe, +# 'install', +# '--flag', ['-g', '-fPIC', '-O2', '-fopenmp'], +# '--prefix', fpm_build_dir, +# check : true +#) + + +# --- La extensión SCHAModules --- +# Estas son las fuentes de Fortran que serán procesadas por f2py +schamodules_sources = files( + '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' +) + +# Usa f2py para crear el wrapper de C +SCHAModules_wrapper = custom_target( + 'schamodules_f2py_wrapper', + input: schamodules_sources, + output: 'schamodulesmodule.c', + #output: 'schamodules-f2pywrappers.c', + command: [ + f2py_exe, + '-m', 'schamodules', # El nombre del módulo + '@INPUT@', + '--quiet', + '--lower' + ], + build_by_default: true +) +# Crea el módulo de extensión de Python +py_sschamodules_ext = python_installation.extension_module( + 'SCHAModules', # Nombre del módulo resultante + # Ahora pasamos el wrapper de C generado y la librería estática de fpm + [SCHAModules_wrapper,schamodules_sources], + #fpm_build_dir / 'lib' / 'libschamodules.a', + install: true, + include_directories: include_dirs, + #[ + # include_directories(numpy_incdir), + # fpm_build_dir / 'include' # Directorio de inclusión para módulos Fortran + #], + dependencies: [lapack_dep, blas_dep, mpi_dep, py_dep], + link_args: ['-fopenmp'], + fortran_args: ['-cpp'], + install_rpath: '$ORIGIN/..' +) + + +# Meson's `extension_module` function for Python handles much of the magic. +# 'SCHAModules' will be the name of the resulting Python module. +#py_mod_schamodules = python_installation.extension_module( +# 'SCHAModules', +# schamodules_sources, + # Make sure BLAS/LAPACK dependencies are linked correctly +# dependencies : [lapack_dep, blas_dep, mpi_dep], + # Fortran-specific flags +# fortran_args : common_fortran_flags, +# link_args : common_link_flags, + # Add -fPIC for Linux if needed (Meson usually handles this) + # This is the equivalent of extra_f90_compile_args and extra_link_args + # in setup.py for the Fortran module. +# include_directories: include_directories(numpy_incdir), +# install_rpath: '$ORIGIN/..' +#) + +# --- 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 : python_installation.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries + +install_data( + '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', + install_dir: python_installation.get_install_dir() / 'python-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/). +#executable( +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente +# 'scripts/read_incomplete_ensemble.py' +#, install : true) +#install_data = ( +# [ +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx')#, # Si esto es un script ejecutable directamente +# 'scripts/read_incomplete_ensemble.py' +# ], +# install_dir: get_option('bindir') +# ) + +#foreach s : install_scripts +# install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin +#endforeach + +# --- 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 : python_installation.get_install_dir() / 'python-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) + +# Define el intérprete de Python +#python = find_program('python3') + +#install_data([ +# 'scripts/sscha', +# 'scripts/cluster_check.x', +# 'scripts/plot_frequencies.py', +# 'scripts/sscha-plot-data.py', +# 'scripts/static-vc-relax.pyx', +# 'scripts/read_incomplete_ensemble.py' +#], +#install_dir: get_option('bindir') +#) +python_installation.install_sources([ + 'scripts/sscha', + 'scripts/cluster_check.x', + 'scripts/plot_frequencies.py', + 'scripts/sscha-plot-data.py', + 'scripts/static-vc-relax.pyx', + 'scripts/read_incomplete_ensemble.py' +]) + + +# Establece los test con pytest. (necesita tener pytest instalado) +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 no encontrado; se omiten tests con pytest.') +endif diff --git a/meson.options b/meson.options new file mode 100644 index 00000000..d6853da8 --- /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') From 724fecd1f88615b92bf5e4dc95cfc3f281ac84e4 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 17 Sep 2025 13:49:35 +0200 Subject: [PATCH 075/106] Fix bug --- meson.build | 3 --- 1 file changed, 3 deletions(-) diff --git a/meson.build b/meson.build index ef1fd815..43daf9d2 100644 --- a/meson.build +++ b/meson.build @@ -96,9 +96,6 @@ project('python-sscha', # warning('No openblas found.') list_dep = [py_dep, mpi_dep, quadmath_dep, lapack_dep, blas_dep] #endif ---------------- - - # --- Common Flags --- common_fortran_flags = ['-cpp', '-fopenmp'] From 5aaac30f04584753b5e3fcca7ddee9c62c901c81 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 17 Sep 2025 13:51:45 +0200 Subject: [PATCH 076/106] Removing unused fpm --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a4c7c90..54551a98 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: - name: Install Python dependencies run: | - pip install meson ninja meson-python numpy scipy ase pytest fpm + pip install meson ninja meson-python numpy scipy ase pytest - name: Setup build directory run: meson setup builddir From da1b85776d636020b1476785b21774c957c6400c Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 17 Sep 2025 13:58:04 +0200 Subject: [PATCH 077/106] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index a110eeae..d86f024f 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,16 @@ Create and configure a build directory by running: 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 @@ -227,6 +237,12 @@ This step helps verify that the build works correctly. 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 ``` From afb94069fd684387a04211bcc32c773f97b2404d Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 18 Sep 2025 09:38:33 +0200 Subject: [PATCH 078/106] The custom f2py wrapper may be necessary until meson is updated to a new version that includes full f2py integration. --- meson.build | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 43daf9d2..2de79153 100644 --- a/meson.build +++ b/meson.build @@ -126,9 +126,24 @@ schamodules_sources = [ '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: 'SCHAModules-f2py.c', +# command: [ +# py.full_path(), '-m', 'numpy.f2py', +# '--backend', 'meson', +# '--dep', 'mpi', +# '--quiet', +# '-c', +# '@INPUT0@', +# '-m', 'SCHAModules' +# ], +# install: false +#) py.extension_module('SCHAModules', schamodules_sources, + # f2py_SCHAModules_target, # f2py_c_source, # <- Cambio aplicado # c_args: ['-DF2PY_SETUP_RUN'], # <--- Solucinar "_npy_f2py_ARRAY_API" include_directories: inc_np, From 9147f7280b8c9f5bf64e6f6f97da8fcd3a16e48e Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 18 Sep 2025 10:07:38 +0200 Subject: [PATCH 079/106] Set the meson minimun version --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index 2de79153..39fe66cc 100644 --- a/meson.build +++ b/meson.build @@ -2,6 +2,7 @@ project('python-sscha', ['c','fortran'], version : '1.4.2', license: 'GPL', + meson_version: '>= 1.1.0', default_options : [ 'warning_level=1', 'buildtype=release', From 5b8bae310523d1cb6f75d92115f7a71ea29c6d41 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 18 Sep 2025 10:48:17 +0200 Subject: [PATCH 080/106] Group things up --- meson.build | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 39fe66cc..671665ca 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ project('python-sscha', ['c','fortran'], version : '1.4.2', license: 'GPL', - meson_version: '>= 1.1.0', + meson_version: '>= 1.1.0', # <- set min version of meson. default_options : [ 'warning_level=1', 'buildtype=release', @@ -130,7 +130,7 @@ schamodules_sources = [ ## Generate the C wrapper with f2py using a custom target #f2py_SCHAModules_target = custom_target('SCHAModules-f2py-wrapper', # input: schamodules_sources, -# output: 'SCHAModules-f2py.c', +# output: ['SCHAModules-f2py.c','SCHAModules-f2py-wrapper.f'], # command: [ # py.full_path(), '-m', 'numpy.f2py', # '--backend', 'meson', @@ -143,8 +143,9 @@ schamodules_sources = [ # install: false #) py.extension_module('SCHAModules', + # [ schamodules_sources, - # f2py_SCHAModules_target, + # f2py_SCHAModules_target], # f2py_c_source, # <- Cambio aplicado # c_args: ['-DF2PY_SETUP_RUN'], # <--- Solucinar "_npy_f2py_ARRAY_API" include_directories: inc_np, From 940d2a92b444db0ae88baf9b1a7c430f0e3e2f96 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 18 Sep 2025 11:48:29 +0200 Subject: [PATCH 081/106] For testing... --- meson.build | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index 671665ca..3267a911 100644 --- a/meson.build +++ b/meson.build @@ -130,16 +130,10 @@ schamodules_sources = [ ## Generate the C wrapper with f2py using a custom target #f2py_SCHAModules_target = custom_target('SCHAModules-f2py-wrapper', # input: schamodules_sources, -# output: ['SCHAModules-f2py.c','SCHAModules-f2py-wrapper.f'], -# command: [ -# py.full_path(), '-m', 'numpy.f2py', -# '--backend', 'meson', -# '--dep', 'mpi', -# '--quiet', -# '-c', -# '@INPUT0@', -# '-m', 'SCHAModules' -# ], +# output: ['SCHAModulesmodule.c','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', From c3db048bcea5f39acf8069fd68ceaee84049b13c Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Thu, 18 Sep 2025 11:49:11 +0200 Subject: [PATCH 082/106] Old method to compile the FORTRAN libraries with f2py. --- meson.build | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index 3267a911..22cc292d 100644 --- a/meson.build +++ b/meson.build @@ -128,18 +128,18 @@ schamodules_sources = [ # ,'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-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 -#) +f2py_SCHAModules_target = custom_target('SCHAModules-f2py-wrapper', + input: schamodules_sources, + output: ['SCHAModulesmodule.c','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], + f2py_SCHAModules_target], # f2py_c_source, # <- Cambio aplicado # c_args: ['-DF2PY_SETUP_RUN'], # <--- Solucinar "_npy_f2py_ARRAY_API" include_directories: inc_np, From 886db3a3a5fd5be31a059bccd6d9246d62f12ef5 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 19 Sep 2025 09:03:24 +0200 Subject: [PATCH 083/106] Removing temporal files --- meson.build.old | 307 ------------------------------------------ meson.build.old2 | 337 ----------------------------------------------- 2 files changed, 644 deletions(-) delete mode 100644 meson.build.old delete mode 100644 meson.build.old2 diff --git a/meson.build.old b/meson.build.old deleted file mode 100644 index b9bf22a4..00000000 --- a/meson.build.old +++ /dev/null @@ -1,307 +0,0 @@ -project('python-sscha', 'fortran', 'c', - version : '1.4.2', - license: 'GPL', -# Common compilation options for Fortran. -# -cpp is essential for the Fortran preprocessor. -# -O2 is a general optimization you had in setup.py. - default_options : ['warning_level=1','fortran_args=-cpp', 'fortran_args=-O2']) - - # --- System and Python Dependencies --- - # Imports the Meson Python module to handle extensions and Python installation. - python = import('python') - python_installation = python.find_installation() - numpy_incdir = run_command( - python_installation, '-c', 'import numpy; print(numpy.get_include())', - check: true - ).stdout().strip() - - # Find the fpm and f2py programs - fpm_exe = find_program('fpm', required: true) - f2py_exe = python.find_program('f2py', required: true) - - # Define the build directory for fpm - fpm_build_dir = meson.build_root() / 'fpm_build' - -# --- 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'). -lapack_dep = dependency('lapack', required : true) -blas_dep = dependency('blas', required : true) - -# 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 - -# --- Python 2/3 Detection (not as relevant anymore, but translated) --- -# In Meson, this would be done based on the Python version Meson is using. -# Since Python 2 is EOL, this check is generally not needed. -# However, if you want to keep the flag: -#py2_flag = [] -#if py_dep.version().version_compare('<3.0') -# message('Running on Python 2, adding the flag -D_PYTHON2') -# py2_flag += ['-D_PYTHON2'] -#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. - -# Use fpm to build and install your Fortran sources -run_command( - fpm_exe, - 'install', - '--flag', ['-g', '-fPIC', '-O2', '-fopenmp'], - '--prefix', fpm_build_dir, - check : true -) - - -# --- La extensión SCHAModules --- -# Estas son las fuentes de Fortran que serán procesadas por f2py -schamodules_sources = files( - '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' -) - -# Usa f2py para crear el wrapper de C -SCHAModules_wrapper = custom_target( - '_f2py_wrapper', - input: schamodules_sources, - output: 'schamodules-f2pywrappers.c', - command: [ - f2py_exe, - '-m', 'schamodules', # El nombre del módulo - '@INPUT@', - '--quiet', - '--lower' - ], - build_by_default: true -) -# Crea el módulo de extensión de Python -py_sschamodules_ext = python_installation.extension_module( - 'SCHAModules', # Nombre del módulo resultante - # Ahora pasamos el wrapper de C generado y la librería estática de fpm - symph_wrapper, - fpm_build_dir / 'lib' / 'libschamodules.a', - install: true, - include_directories: [ - include_directories(numpy_incdir), - fpm_build_dir / 'include' # Directorio de inclusión para módulos Fortran - ], - dependencies: [lapack_dep, blas_dep, mpi_dep], - link_args: ['-fopenmp'], - install_rpath: '$ORIGIN/..' -) - - -# Meson's `extension_module` function for Python handles much of the magic. -# 'SCHAModules' will be the name of the resulting Python module. -#py_mod_schamodules = python_installation.extension_module( -# 'SCHAModules', -# schamodules_sources, - # Make sure BLAS/LAPACK dependencies are linked correctly -# dependencies : [lapack_dep, blas_dep, mpi_dep], - # Fortran-specific flags -# fortran_args : common_fortran_flags, -# link_args : common_link_flags, - # Add -fPIC for Linux if needed (Meson usually handles this) - # This is the equivalent of extra_f90_compile_args and extra_link_args - # in setup.py for the Fortran module. -# include_directories: include_directories(numpy_incdir), -# install_rpath: '$ORIGIN/..' -#) - -# --- 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 : python_installation.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries - -install_data( - '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', - install_dir: python_installation.get_install_dir() / 'python-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/). -#executable( -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente -# 'scripts/read_incomplete_ensemble.py' -#, install : true) -#install_data = ( -# [ -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx')#, # Si esto es un script ejecutable directamente -# 'scripts/read_incomplete_ensemble.py' -# ], -# install_dir: get_option('bindir') -# ) - -#foreach s : install_scripts -# install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin -#endforeach - -# --- 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 : python_installation.get_install_dir() / 'python-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) - -# Define el intérprete de Python -#python = find_program('python3') - -#install_data([ -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', -# 'scripts/read_incomplete_ensemble.py' -#], -#install_dir: get_option('bindir') -#) -python_installation.install_sources([ - 'scripts/sscha', - 'scripts/cluster_check.x', - 'scripts/plot_frequencies.py', - 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx', - 'scripts/read_incomplete_ensemble.py' -]) - - -# Establece los test con pytest. (necesita tener pytest instalado) -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 no encontrado; se omiten tests con pytest.') -endif diff --git a/meson.build.old2 b/meson.build.old2 deleted file mode 100644 index 04a03075..00000000 --- a/meson.build.old2 +++ /dev/null @@ -1,337 +0,0 @@ -project('python-sscha', 'fortran', 'c', - version : '1.4.2', - license: 'GPL', -# Common compilation options for Fortran. -# -cpp is essential for the Fortran preprocessor. -# -O2 is a general optimization you had in setup.py. - default_options : ['warning_level=1','fortran_args=-cpp', 'fortran_args=-O2']) - - # --- System and Python Dependencies --- - # Imports the Meson Python module to handle extensions and Python installation. - python = import('python') - python_installation = python.find_installation() - py_dep = dependency('python3', required: true) - - # Obtenemos la ruta principal de los headers de numpy - numpy_incdir = run_command( - python_installation, '-c', 'import numpy; print(numpy.get_include())', - check: true - ).stdout().strip() -# Obtenemos la ruta padre para incluir los headers de numpy anidados -numpy_parent_incdir = run_command( - python_installation, '-c', 'import os, numpy; print(os.path.dirname(numpy.get_include()))', - check: true -).stdout().strip() - -# Obtenemos la ruta específica para los headers de f2py -f2py_incdir = run_command( - python_installation, '-c', 'import os, numpy.f2py; print(os.path.join(os.path.dirname(numpy.f2py.__file__), "src"))', - check: true -).stdout().strip() - -# Creamos una lista de directorios de inclusión para usar en todas las extensiones -include_dirs = include_directories(numpy_incdir, numpy_parent_incdir, f2py_incdir, '.') - -# Obtenemos la ruta de la biblioteca de f2py para la vinculación -f2py_libdir = run_command( - python_installation, '-c', 'import os, numpy.f2py; print(os.path.join(os.path.dirname(os.path.dirname(numpy.f2py.__file__)), "core", "lib"))', - check: true -).stdout().strip() -# Obtenemos la ruta del directorio de bibliotecas de Python -py_libdir = python_installation.get_install_dir() / 'lib' - - # Find the fpm and f2py programs - #fpm_exe = find_program('fpm', required: true) - #f2py_exe = python.find_program('f2py', required: true) - f2py_exe = find_program('f2py', required: true) - - - # Define the build directory for fpm - #fpm_build_dir = meson.build_root() / 'fpm_build' - -# --- 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'). -lapack_dep = dependency('lapack', required : true) -blas_dep = dependency('blas', required : true) - -# 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 - -# --- Python 2/3 Detection (not as relevant anymore, but translated) --- -# In Meson, this would be done based on the Python version Meson is using. -# Since Python 2 is EOL, this check is generally not needed. -# However, if you want to keep the flag: -#py2_flag = [] -#if py_dep.version().version_compare('<3.0') -# message('Running on Python 2, adding the flag -D_PYTHON2') -# py2_flag += ['-D_PYTHON2'] -#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. - -# Use fpm to build and install your Fortran sources -#run_command( -# fpm_exe, -# 'install', -# '--flag', ['-g', '-fPIC', '-O2', '-fopenmp'], -# '--prefix', fpm_build_dir, -# check : true -#) - - -# --- La extensión SCHAModules --- -# Estas son las fuentes de Fortran que serán procesadas por f2py -schamodules_sources = files( - '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' -) - -# Usa f2py para crear el wrapper de C -SCHAModules_wrapper = custom_target( - 'schamodules_f2py_wrapper', - input: schamodules_sources, - output: 'schamodulesmodule.c', - #output: 'schamodules-f2pywrappers.c', - command: [ - f2py_exe, - '-m', 'schamodules', # El nombre del módulo - '@INPUT@', - '--quiet', - '--lower' - ], - build_by_default: true -) -# Crea el módulo de extensión de Python -py_sschamodules_ext = python_installation.extension_module( - 'SCHAModules', # Nombre del módulo resultante - # Ahora pasamos el wrapper de C generado y la librería estática de fpm - [SCHAModules_wrapper,schamodules_sources], - #fpm_build_dir / 'lib' / 'libschamodules.a', - install: true, - include_directories: include_dirs, - #[ - # include_directories(numpy_incdir), - # fpm_build_dir / 'include' # Directorio de inclusión para módulos Fortran - #], - dependencies: [lapack_dep, blas_dep, mpi_dep, py_dep], - link_args: ['-fopenmp'], - fortran_args: ['-cpp'], - install_rpath: '$ORIGIN/..' -) - - -# Meson's `extension_module` function for Python handles much of the magic. -# 'SCHAModules' will be the name of the resulting Python module. -#py_mod_schamodules = python_installation.extension_module( -# 'SCHAModules', -# schamodules_sources, - # Make sure BLAS/LAPACK dependencies are linked correctly -# dependencies : [lapack_dep, blas_dep, mpi_dep], - # Fortran-specific flags -# fortran_args : common_fortran_flags, -# link_args : common_link_flags, - # Add -fPIC for Linux if needed (Meson usually handles this) - # This is the equivalent of extra_f90_compile_args and extra_link_args - # in setup.py for the Fortran module. -# include_directories: include_directories(numpy_incdir), -# install_rpath: '$ORIGIN/..' -#) - -# --- 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 : python_installation.get_install_dir()) <-- .get_install_dir() gives the python installation place for libraries - -install_data( - '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', - install_dir: python_installation.get_install_dir() / 'python-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/). -#executable( -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', # Si esto es un script ejecutable directamente -# 'scripts/read_incomplete_ensemble.py' -#, install : true) -#install_data = ( -# [ -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx')#, # Si esto es un script ejecutable directamente -# 'scripts/read_incomplete_ensemble.py' -# ], -# install_dir: get_option('bindir') -# ) - -#foreach s : install_scripts -# install_data(s, install_dir : python.get_install_subdir() / '..' / 'bin') # Installs in bin -#endforeach - -# --- 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 : python_installation.get_install_dir() / 'python-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) - -# Define el intérprete de Python -#python = find_program('python3') - -#install_data([ -# 'scripts/sscha', -# 'scripts/cluster_check.x', -# 'scripts/plot_frequencies.py', -# 'scripts/sscha-plot-data.py', -# 'scripts/static-vc-relax.pyx', -# 'scripts/read_incomplete_ensemble.py' -#], -#install_dir: get_option('bindir') -#) -python_installation.install_sources([ - 'scripts/sscha', - 'scripts/cluster_check.x', - 'scripts/plot_frequencies.py', - 'scripts/sscha-plot-data.py', - 'scripts/static-vc-relax.pyx', - 'scripts/read_incomplete_ensemble.py' -]) - - -# Establece los test con pytest. (necesita tener pytest instalado) -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 no encontrado; se omiten tests con pytest.') -endif From 9d5cc0723da88711d3c1bc78139460c559a51836 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 19 Sep 2025 13:23:13 +0200 Subject: [PATCH 084/106] Translation of comments into English --- meson.build | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/meson.build b/meson.build index 22cc292d..a78efb9e 100644 --- a/meson.build +++ b/meson.build @@ -16,12 +16,12 @@ project('python-sscha', use_mkl = get_option('use_mkl') # --- System and Python Dependencies --- - # Encuentra las instalaciones necesarias + # Find the necessary installations py = import('python').find_installation(pure: false) py_dep = py.dependency() fc = meson.get_compiler('fortran') - # Dependencias adicionales + # Additional dependencies # --- BLAS/LAPACK Dependencies --- # Meson will attempt to automatically detect LAPACK and BLAS. @@ -71,17 +71,17 @@ project('python-sscha', 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 - # Busca la librería quadmath, si está disponible + # Find the quadmath library, if available quadmath_dep = fc.find_library('quadmath', required: false) - # --- CONFIGURACIÓN DE NUMPY --- - # Obtiene la ruta de los directorios de cabecera de NumPy y f2py usando el comando de Python + # --- 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 también requiere la cabecera fortranobject.h + # f2py also requires the fortranobject.h header incdir_f2py = run_command(py, ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], check : true @@ -89,14 +89,14 @@ project('python-sscha', inc_np = include_directories(incdir_numpy, incdir_f2py) - # --- FIN DE LA CONFIGURACIÓN DE NUMPY --- - #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.') + # --- 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 + endif # --- Common Flags --- common_fortran_flags = ['-cpp', '-fopenmp'] @@ -106,7 +106,7 @@ common_link_flags = ['-fopenmp'] # For OpenMP # 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. -# --- La extensión SCHAModules --- +# --- SCHAModules extension --- schamodules_sources = [ 'SCHAModules/module_stochastic.f90', @@ -140,8 +140,6 @@ py.extension_module('SCHAModules', [ schamodules_sources, f2py_SCHAModules_target], -# f2py_c_source, # <- Cambio aplicado -# c_args: ['-DF2PY_SETUP_RUN'], # <--- Solucinar "_npy_f2py_ARRAY_API" include_directories: inc_np, dependencies: list_dep, install: true @@ -244,7 +242,7 @@ install_data( # configuration: conf) -# Establece los test con pytest. (necesita tener pytest instalado) +# Set the tests by pytest. pytest_exe = find_program('pytest', required: false) if pytest_exe.found() @@ -252,5 +250,5 @@ if pytest_exe.found() args : ['-v', '-m', 'not release', 'tests'], workdir : meson.project_source_root()) else - message('pytest no encontrado; se omiten tests con pytest.') + message('pytest not found; pytest tests are skipped.') endif From 99c7d2dc94812b87e8c5d42bd273be023fdcb6a4 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 19 Sep 2025 14:33:15 +0200 Subject: [PATCH 085/106] Update --- .github/workflows/python-testsuite.yml | 6 ++++-- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-testsuite.yml b/.github/workflows/python-testsuite.yml index cd0bbb82..4b064616 100644 --- a/.github/workflows/python-testsuite.yml +++ b/.github/workflows/python-testsuite.yml @@ -53,10 +53,12 @@ jobs: sudo apt-get install git gfortran libblas-dev liblapack-dev git clone https://github.com/mesonepigreco/CellConstructor.git cd CellConstructor - python setup.py install --user + # python setup.py install --user + pip install -e . cd .. - python setup.py install --user + # python setup.py install --user + pip install -e . # Install julia requirements python -c 'import julia; julia.install()' diff --git a/pyproject.toml b/pyproject.toml index 1e245c78..ec295199 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["meson-python>=0.13.0", "meson>=1.0", "numpy", "cellconstructor","meson-python", "setuptools"] +requires = ["meson-python>=0.13.0", "meson>=1.1.0", "numpy", "cellconstructor","meson-python", "numpy>=1.20.0"] build-backend = "mesonpy" [project] From 5317fb9b78e247ca3687a654ff240fe1e14b61fc Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 19 Sep 2025 14:48:40 +0200 Subject: [PATCH 086/106] Update with what we learned from CellConstructor --- .github/workflows/python-testsuite.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-testsuite.yml b/.github/workflows/python-testsuite.yml index 4b064616..55cb3a81 100644 --- a/.github/workflows/python-testsuite.yml +++ b/.github/workflows/python-testsuite.yml @@ -54,11 +54,11 @@ jobs: git clone https://github.com/mesonepigreco/CellConstructor.git cd CellConstructor # python setup.py install --user - pip install -e . + pip install . cd .. # python setup.py install --user - pip install -e . + pip install . # Install julia requirements python -c 'import julia; julia.install()' From bb85744c4eb12a2550de36d7a6a5dea1deeb4760 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 19 Sep 2025 15:06:10 +0200 Subject: [PATCH 087/106] Change from install_data to install_sources --- meson.build | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index a78efb9e..f5fe4cf6 100644 --- a/meson.build +++ b/meson.build @@ -187,7 +187,26 @@ py.extension_module('SCHAModules', # 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 -install_data( +#install_data( +# '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', +# install_dir: py.get_install_dir() / 'python-sscha', +#) +py.install_sources([ 'Modules/__init__.py', 'Modules/AdvancedCalculations.py', 'Modules/aiida_ensemble.py', @@ -203,8 +222,9 @@ install_data( 'Modules/Relax.py', 'Modules/SchaMinimizer.py', 'Modules/Tools.py', - 'Modules/Utilities.py', - install_dir: py.get_install_dir() / 'python-sscha', + 'Modules/Utilities.py' + ], + subdir: 'python-sscha', ) # --- Installing Scripts --- From f00f8a36b688987e2df28851a188e0c9d6f0e4ff Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 19 Sep 2025 16:15:06 +0200 Subject: [PATCH 088/106] Fix on the code to add 'fortranobject.c' --- meson.build | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index f5fe4cf6..4b454422 100644 --- a/meson.build +++ b/meson.build @@ -88,6 +88,10 @@ project('python-sscha', ).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() @@ -139,7 +143,7 @@ f2py_SCHAModules_target = custom_target('SCHAModules-f2py-wrapper', py.extension_module('SCHAModules', [ schamodules_sources, - f2py_SCHAModules_target], + f2py_SCHAModules_target, fortranobject_c], include_directories: inc_np, dependencies: list_dep, install: true From c20d8c60ba37f98bde51f1d2525a5553be87d082 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Fri, 19 Sep 2025 16:23:50 +0200 Subject: [PATCH 089/106] Removed duplicate --- .github/workflows/build.yml | 1 + pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 54551a98..95ec042d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,7 @@ jobs: - name: Compile run: meson compile -C builddir + # - name: Install package # run: meson install -C builddir diff --git a/pyproject.toml b/pyproject.toml index ec295199..5cc94707 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["meson-python>=0.13.0", "meson>=1.1.0", "numpy", "cellconstructor","meson-python", "numpy>=1.20.0"] +requires = ["meson-python>=0.13.0", "meson>=1.1.0", "numpy>=1.20.0", "cellconstructor","meson-python"] build-backend = "mesonpy" [project] From 0ad927fad64aadf2cafa14edbfe8bdd1e2960a2d Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Sat, 20 Sep 2025 09:43:28 +0200 Subject: [PATCH 090/106] Change name of sscha executable to sscha.x so it doesn't have the same name as the python library --- meson.build | 6 +++--- setup.py => old_setup.py | 0 scripts/{sscha => sscha.x} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename setup.py => old_setup.py (100%) rename scripts/{sscha => sscha.x} (100%) diff --git a/meson.build b/meson.build index 4b454422..a8b1a9c3 100644 --- a/meson.build +++ b/meson.build @@ -228,7 +228,7 @@ py.install_sources([ 'Modules/Tools.py', 'Modules/Utilities.py' ], - subdir: 'python-sscha', + subdir: 'sscha', ) # --- Installing Scripts --- @@ -236,7 +236,7 @@ py.install_sources([ # Scripts will be installed in the `bin` directory of the Python environment (e.g., venv/bin/). py.install_sources([ - 'scripts/sscha', + 'scripts/sscha.x', 'scripts/cluster_check.x', 'scripts/plot_frequencies.py', 'scripts/sscha-plot-data.py', @@ -250,7 +250,7 @@ py.install_sources([ # and copy the .jl files there. install_data( ['Modules/fourier_gradient.jl'], # List the .jl files you need - install_dir : py.get_install_dir() / 'python-sscha' + 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. diff --git a/setup.py b/old_setup.py similarity index 100% rename from setup.py rename to old_setup.py diff --git a/scripts/sscha b/scripts/sscha.x similarity index 100% rename from scripts/sscha rename to scripts/sscha.x From 042e9f77dd73c3aac71cd283136f79788d59ae24 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 22 Sep 2025 08:24:07 +0200 Subject: [PATCH 091/106] Adding "SCHAModules-f2pywrappers.f" --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index a8b1a9c3..034fce63 100644 --- a/meson.build +++ b/meson.build @@ -134,7 +134,7 @@ schamodules_sources = [ ## 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-f2pywrappers2.f90'], + 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'], From 037220acd7b07d5623999a76edd00f4441991a67 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 22 Sep 2025 08:39:37 +0200 Subject: [PATCH 092/106] Small update --- meson.build.sscha | 73 +++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 meson.build.sscha diff --git a/meson.build.sscha b/meson.build.sscha new file mode 100644 index 00000000..a7c1fa0d --- /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/pyproject.toml b/pyproject.toml index 5cc94707..29873044 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,4 +36,4 @@ Repository = "https://github.com/mesonepigreco/python-sscha" # 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/cellconstructor"] # For a non-standard installation +# setup-args = ["--prefix=/opt/python-sscha"] # For a non-standard installation From 78a88f2c6bc13b45ee6e0e4c56032ab75109e8ea Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 22 Sep 2025 09:25:26 +0200 Subject: [PATCH 093/106] Set the correct repository and issues links --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 29873044..cb44205f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,9 +25,9 @@ dependencies = [ [project.urls] Homepage = "https://sscha.eu/" -Repository = "https://github.com/mesonepigreco/python-sscha" +Repository = "https://github.com/SSCHAcode/python-sscha" # Documentation = "https://documentacion.readthedocs.io/" -# Issues = "https://github.com/mesonepigreco/python-sscha/issues" +Issues = "https://github.com/SSCHAcode/python-sscha/issues" # --- Meson-python specific configuration (Optional but useful) --- [tool.meson-python] From f36021dd7ec4b128ea1e1517698cc975830979f0 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 23 Sep 2025 09:19:46 +0200 Subject: [PATCH 094/106] Still needs more changes to show how to do things with Meson --- UserGuide/install.rst | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/UserGuide/install.rst b/UserGuide/install.rst index c01d36d3..a9240930 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,25 +116,40 @@ 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 the GNU FORTRAN compiler. 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 -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. + 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 + +Or for an editable install: +.. code-block:: + pip install -e . --config-settings=--setup-args=-Duse_mkl=true Install with a specific compiler path ------------------------------------- @@ -154,5 +169,3 @@ If we want to use a custom compiler in /path/to/fcompiler we may run the setup a A specific setup.py script is provided to install it easily in FOSS clusters. - - From 775c517b4f2dddc3e3bc347ef7a45d83b95abcd4 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 23 Sep 2025 11:37:03 +0200 Subject: [PATCH 095/106] Update install.rst with the 'Install with a specific compiler path' --- UserGuide/install.rst | 83 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 9 deletions(-) diff --git a/UserGuide/install.rst b/UserGuide/install.rst index a9240930..1415ad61 100644 --- a/UserGuide/install.rst +++ b/UserGuide/install.rst @@ -134,7 +134,7 @@ An "editable" install is highly recommended for developers. It allows you to mod Install with Intel FORTRAN compiler ----------------------------------- -Meson works automatically with the GNU FORTRAN compiler. However, due to some differences in linking lapack, +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: @@ -148,24 +148,89 @@ You can pass Meson options through pip's \--config-settings flag. pip install . --config-settings=--setup-args=-Duse_mkl=true Or for an editable install: -.. code-block:: +.. 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. + + CXX: Specifies the C++ compiler executable. + + 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 + +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): -1. CC (C compiler) -2. FC (Fortran compiler) -3. LDSHARED (linking) +.. 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 -If we want to use a custom compiler in /path/to/fcompiler we may run the setup as: +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). - FC=/path/to/fcompiler LDSHARED=/path/to/fcompiler python setup.py install +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" -A specific setup.py script is provided to install it easily in FOSS clusters. +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. From 146a746daf7b57a23d55738ce0dd78526bec4ff8 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Wed, 24 Sep 2025 11:01:03 +0200 Subject: [PATCH 096/106] Removing install_data() for installing the python modules, it is done bay install_sources() instead --- meson.build | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/meson.build b/meson.build index 034fce63..765948a6 100644 --- a/meson.build +++ b/meson.build @@ -191,25 +191,6 @@ py.extension_module('SCHAModules', # 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 -#install_data( -# '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', -# install_dir: py.get_install_dir() / 'python-sscha', -#) py.install_sources([ 'Modules/__init__.py', 'Modules/AdvancedCalculations.py', From b2c9e4aee16e2f33644215ef1a71e5699f37d135 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 29 Sep 2025 13:35:38 +0200 Subject: [PATCH 097/106] Update with the python=3.12 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d86f024f..3f670fa5 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The SSCHA code comes as a python library, with computationally intense part spee ``` -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 setuptools=64 conda activate sscha pip install ase julia mpi4py pip install cellconstructor python-sscha tdscha @@ -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 setuptools=64 conda activate sscha pip install ase julia mpi4py pip install cellconstructor python-sscha tdscha From e4d20bfd74b534edf064bbd77cb5a7e382000ec2 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 29 Sep 2025 14:29:39 +0200 Subject: [PATCH 098/106] Added the python_sscha Installation Guide. --- python-sscha Installation Guide.md | 130 +++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 python-sscha Installation Guide.md diff --git a/python-sscha Installation Guide.md b/python-sscha Installation Guide.md new file mode 100644 index 00000000..d43b6c3a --- /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" +``` From f4c4649108f583b6c9f1ad381ea31550c50572f0 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 29 Sep 2025 14:37:43 +0200 Subject: [PATCH 099/106] Set the CellConstructor needed as version >= 1.5.0 --- .github/workflows/python-testsuite.yml | 2 +- meson.build | 2 +- pyproject.toml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-testsuite.yml b/.github/workflows/python-testsuite.yml index 55cb3a81..919e19cd 100644 --- a/.github/workflows/python-testsuite.yml +++ b/.github/workflows/python-testsuite.yml @@ -51,7 +51,7 @@ 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 cd CellConstructor # python setup.py install --user pip install . diff --git a/meson.build b/meson.build index 765948a6..c64fc29c 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('python-sscha', ['c','fortran'], - version : '1.4.2', + version : '1.5.0', license: 'GPL', meson_version: '>= 1.1.0', # <- set min version of meson. default_options : [ diff --git a/pyproject.toml b/pyproject.toml index cb44205f..98281001 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["meson-python>=0.13.0", "meson>=1.1.0", "numpy>=1.20.0", "cellconstructor","meson-python"] +requires = ["meson-python>=0.13.0", "meson>=1.1.0", "numpy>=1.20.0", "cellconstructor>=1.5.0","meson-python"] build-backend = "mesonpy" [project] name = "python-sscha" -version = "1.4.2" +version = "1.5.0" description = "Python implementation of the sscha code" authors = [{name = "Lorenzo Monacelli"}] # Put here email readme = "README.md" From ee1965faa0bd953385a6c03910f14d6e0c4f16af Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 29 Sep 2025 14:41:50 +0200 Subject: [PATCH 100/106] Forgot to also change also the requirements.txt file. Maybe remove the setuptools later... --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f76c46d3..fceae34e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ scipy ase spglib<=2.2 julia -cellconstructor +cellconstructor>=1.5.0 From 0ebd175e294924aae1557db4018577e8bd2051c1 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Mon, 29 Sep 2025 14:59:58 +0200 Subject: [PATCH 101/106] Set required python version to >=3.12 --- .github/workflows/build.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 95ec042d..d96baae0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: 3.12 - name: Install system dependencies run: | diff --git a/pyproject.toml b/pyproject.toml index 98281001..957907e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ 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" # Ajusta según las versiones de Python que soportes +requires-python = ">=3.12" # Ajusta según las versiones de Python que soportes dependencies = [ "numpy", "ase", From dde3aec5070a37c21444f8b93565e798461fc07e Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 30 Sep 2025 08:53:16 +0200 Subject: [PATCH 102/106] Some fixed following 'mesonepigreco' comments. --- .github/workflows/python-testsuite.yml | 6 +++--- README.md | 4 ++-- pyproject.toml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python-testsuite.yml b/.github/workflows/python-testsuite.yml index 919e19cd..69246888 100644 --- a/.github/workflows/python-testsuite.yml +++ b/.github/workflows/python-testsuite.yml @@ -52,12 +52,12 @@ jobs: sudo apt-get update sudo apt-get install git gfortran libblas-dev liblapack-dev git clone https://github.com/SSCHAcode/CellConstructor.git + pip install meson meson-python ninja cd CellConstructor - # python setup.py install --user - pip install . + pip install --no-build-isolation . cd .. - # python setup.py install --user + # python setup.py install --use pip install . # Install julia requirements diff --git a/README.md b/README.md index 3f670fa5..6507cce8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The SSCHA code comes as a python library, with computationally intense part spee ``` -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 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 @@ -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.12 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 diff --git a/pyproject.toml b/pyproject.toml index 957907e8..1921767a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ description = "Python implementation of the sscha code" authors = [{name = "Lorenzo Monacelli"}] # Put here email readme = "README.md" license = {file = "LICENSE.txt"} -requires-python = ">=3.12" # Ajusta según las versiones de Python que soportes +requires-python = ">=3.8,<=3.12" # Updated to specify Python 3.8 to 3.12 dependencies = [ "numpy", "ase", From 577799b07b1a5589d2099cf2ae25f132b15e1b7e Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 30 Sep 2025 09:03:32 +0200 Subject: [PATCH 103/106] Test bay commenting cellconstructor in requirements to force use the cellconstructor from the "Install" part. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fceae34e..7761c664 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ scipy ase spglib<=2.2 julia -cellconstructor>=1.5.0 +# cellconstructor>=1.5.0 From d2b68f14d7be3f7356bc29771bbfce09e9d54b26 Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 30 Sep 2025 09:12:13 +0200 Subject: [PATCH 104/106] Lets see if this quickfix works. --- requirements.txt | 1 - requirements2.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7761c664..b968921c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,3 @@ scipy ase spglib<=2.2 julia -# cellconstructor>=1.5.0 diff --git a/requirements2.txt b/requirements2.txt index 590aa382..6307d01f 100644 --- a/requirements2.txt +++ b/requirements2.txt @@ -3,3 +3,4 @@ numpy scipy ase==3.16.0 spglib<=2.2 +cellconstructor From 3b59b3ca3abbe564f4506a920c7dd486ac741ade Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 30 Sep 2025 09:17:31 +0200 Subject: [PATCH 105/106] More changes in pyproject.toml to try to fix the "Python package" call in github --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1921767a..cc8953a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["meson-python>=0.13.0", "meson>=1.1.0", "numpy>=1.20.0", "cellconstructor>=1.5.0","meson-python"] +requires = ["meson-python>=0.13.0", "meson>=1.1.0", "numpy>=1.20.0", "cellconstructor","meson-python"] build-backend = "mesonpy" [project] From d48dd5f42ebbf543dc844f4092b9325399e530ab Mon Sep 17 00:00:00 2001 From: diegomartinez2 Date: Tue, 30 Sep 2025 09:29:39 +0200 Subject: [PATCH 106/106] Lets ignore the pip cellconstructor --- .github/workflows/python-testsuite.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/python-testsuite.yml b/.github/workflows/python-testsuite.yml index 69246888..742df282 100644 --- a/.github/workflows/python-testsuite.yml +++ b/.github/workflows/python-testsuite.yml @@ -57,8 +57,7 @@ jobs: pip install --no-build-isolation . cd .. - # python setup.py install --use - pip install . + pip install --no-build-isolation . # Install julia requirements python -c 'import julia; julia.install()'