Skip to content

Commit 9f96046

Browse files
Merge branch 'master' into cluster_computed_fix
2 parents 9268ce3 + 23c3797 commit 9f96046

File tree

12 files changed

+726
-28
lines changed

12 files changed

+726
-28
lines changed

.github/workflows/build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build and Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Setup Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: 3.12
16+
17+
- name: Install system dependencies
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install -y libblas-dev liblapack-dev gfortran pkg-config
21+
22+
- name: Install Python dependencies
23+
run: |
24+
pip install meson ninja meson-python numpy scipy ase pytest
25+
26+
- name: Setup build directory
27+
run: meson setup builddir
28+
29+
- name: Compile
30+
run: meson compile -C builddir
31+
32+
33+
# - name: Install package
34+
# run: meson install -C builddir
35+
36+
# - name: Run tests
37+
# run: meson test -C builddir

.github/workflows/python-testsuite.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ jobs:
5151
run: |
5252
sudo apt-get update
5353
sudo apt-get install git gfortran libblas-dev liblapack-dev
54-
git clone https://github.com/mesonepigreco/CellConstructor.git
54+
git clone https://github.com/SSCHAcode/CellConstructor.git
55+
pip install meson meson-python ninja
5556
cd CellConstructor
56-
python setup.py install --user
57+
pip install --no-build-isolation .
5758
cd ..
5859
59-
python setup.py install --user
60+
pip install --no-build-isolation .
6061
6162
# Install julia requirements
6263
python -c 'import julia; julia.install()'

README.md

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ See more info on the webpage:
88

99
## Easy installation through Anaconda
1010

11-
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))
11+
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))
1212

1313

1414
```
15-
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
15+
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
1616
conda activate sscha
1717
pip install ase julia mpi4py
1818
pip install cellconstructor python-sscha tdscha
@@ -27,7 +27,7 @@ If you want the julia speedup, see the section on Manual installation to preconf
2727

2828
## Video lessons from the 2023 School are available
2929

30-
The full recordings, both of theoretical lectures, tutorials and Hands-on sessions can be found
30+
The full recordings, both of theoretical lectures, tutorials and Hands-on sessions can be found
3131
in our youtube channel [SSCHAcode](https://www.youtube.com/@SSCHAcode>)
3232

3333
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()'
4747
```
4848

4949

50-
## Installing without Anaconda
50+
## Installing without Anaconda
5151

5252
If you do not have anaconda to handle your dependencies you need to manually compile the code.
5353

@@ -76,7 +76,7 @@ The SSCHA code is a collection of 3 python packages: CellConstructor, python-ssc
7676

7777
- [CellConstructor](https://github.com/SSCHAcode/CellConstructor>): utility to manage phonon dispersions, atomic structures and crystal symmetries
7878
- [sscha](https://github.com/SSCHAcode/python-sscha>) : This repository, relax with anharmonicity and compute static linear response properties.
79-
- [tdscha](<https://github.com/SSCHAcode/tdscha>) : Compute the dynamical linear response (Raman and IR, spectral functions)
79+
- [tdscha](<https://github.com/SSCHAcode/tdscha>) : Compute the dynamical linear response (Raman and IR, spectral functions)
8080

8181
More details about installations are in the official website [www.sscha.eu](https://sscha.eu/download>)
8282

@@ -89,7 +89,7 @@ First make sure you have anaconda installed [(install anaconda)](https://www.ana
8989
The following commands are sufficient to install the full sscha suite and its dependencies.
9090

9191
```
92-
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
92+
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
9393
conda activate sscha
9494
pip install ase julia mpi4py
9595
pip install cellconstructor python-sscha tdscha
@@ -175,3 +175,80 @@ For example
175175

176176
For the development version of the code, subtitute the pip call with the python setup.py install.
177177

178+
## Compiling with Meson
179+
180+
To compile and install SSCHA with Meson, follow these typical steps:
181+
182+
### 1. Change to the Source Directory
183+
184+
First, open a terminal and navigate to the root directory of the project source code. This is where the `meson.build` file is located.
185+
186+
```bash
187+
cd /path/to/source/root/python-sscha
188+
```
189+
190+
191+
### 2. Configure the Build Directory
192+
193+
Create and configure a build directory by running:
194+
195+
```bash
196+
meson setup builddir
197+
```
198+
199+
or if you are in a conda env (the best option for a local installation):
200+
```bash
201+
meson setup builddir --prefix=$CONDA_PREFIX
202+
```
203+
204+
if you want to use Intel MKL:
205+
```bash
206+
setup builddir -Duse_mkl=true
207+
```
208+
209+
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:
210+
211+
```bash
212+
cd builddir
213+
```
214+
215+
216+
### 3. Compile the Project
217+
218+
Once inside the build directory, compile the project using:
219+
220+
```bash
221+
meson compile
222+
```
223+
224+
This will compile the source code according to the configuration from the previous step.
225+
226+
### 4. Run Tests (Optional)
227+
228+
The project includes tests, you need to install pytest to work. You can run them with:
229+
230+
```bash
231+
meson test
232+
```
233+
234+
This step helps verify that the build works correctly.
235+
236+
### 5. Install the Project (Optional)
237+
238+
To install the compiled binaries, libraries, and other files system-wide (or to a custom location), run:
239+
240+
```bash
241+
meson install
242+
```
243+
244+
or
245+
246+
```bash
247+
sudo meson install
248+
```
249+
250+
You may need superuser privileges (hence `sudo`) to install to system directories.
251+
252+
***
253+
254+
Following these steps will help you successfully compile, test, and install SSCHA with Meson as their build system.

UserGuide/install.rst

Lines changed: 97 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ For python, we strongly recommend using the anaconda distribution, that already
6868

6969
The numpy, scipy and matplotlib are python packages. These are usually provided with a new installation
7070
of python distributions like anaconda. Lapack and Blas are needed for compiling the FORTRAN code (together with a FORTRAN compiler like gfortran).
71-
In many Linux distributions like ubuntu they can be installed as
71+
In many Linux distributions like ubuntu they can be installed as
7272

7373
.. code-block:: console
7474
7575
sudo apt-get install libblas-dev liblapack-dev liblapacke-dev gfortran
7676
7777
7878
79-
Note that this specific command may change in time.
79+
Note that this specific command may change in time.
8080

8181

8282
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
9090
To install all the python dependencies (and recommended) automatically, you may just run:
9191

9292
.. code-block:: console
93-
93+
9494
pip install -r requirements.txt
9595
9696
@@ -102,8 +102,8 @@ Installation from pip
102102
The easiest way to install python-sscha (and CellConstructor) is through the python package manager:
103103

104104
.. code-block:: console
105-
106-
pip install python-sscha
105+
106+
pip install python-sscha
107107
108108
109109
@@ -116,43 +116,121 @@ Installation from source
116116
------------------------
117117

118118
Once all the dependences of the codes are satisfied, you can unzip the source code downloaded from the website.
119-
Then run, inside the directory that contains the setup.py script, the following command:
119+
Then run, inside the directory that contains the meson.build script, the following command:
120120

121121
.. code-block:: console
122122
123-
python setup.py install
123+
pip install .
124124
125125
126126
As for the pip installation, you may append the --user option to install the package only for the user (without requiring administrator powers).
127127

128+
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.
129+
.. code-block:: console
130+
131+
pip install -e .
132+
128133
129134
Install with Intel FORTRAN compiler
130135
-----------------------------------
131136

132-
The setup.py script works automatically with the GNU FORTRAN compiler. However, due to some differences in linking lapack,
133-
to use the intel compiler you need to edit a bit the setup.py script:
137+
Meson works automatically with several FORTRAN compilers, including Intel FORTRAN. However, due to some differences in linking lapack,
138+
to use the intel compiler you need to:
139+
140+
Ensure MKL is installed in your Conda environment:
141+
.. code-block:: console
142+
143+
conda install mkl mkl-devel
144+
145+
You can pass Meson options through pip's \--config-settings flag.
146+
.. code-block:: console
147+
148+
pip install . --config-settings=--setup-args=-Duse_mkl=true
134149
135-
In this case, you need to delete the lapack linking from the
136-
setup.py and include the -mkl as linker option.
137-
Note that you must force to use the same liker compiler as the one used for the compilation.
150+
Or for an editable install:
151+
.. code-block:: console
152+
pip install -e . --config-settings=--setup-args=-Duse_mkl=true
138153
139154
Install with a specific compiler path
140155
-------------------------------------
141156

142-
This can be achieved by specifying the environment variables on which setup.py relies:
157+
Method 1: Using Environment Variables (Recommended for most cases)
158+
------------------------------------------------------------------
159+
160+
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.
161+
162+
The key variables are:
163+
164+
CC: Specifies the C compiler executable.
143165

144-
1. CC (C compiler)
145-
2. FC (Fortran compiler)
146-
3. LDSHARED (linking)
166+
CXX: Specifies the C++ compiler executable.
147167

148-
If we want to use a custom compiler in /path/to/fcompiler we may run the setup as:
168+
FC: Specifies the Fortran compiler executable.
169+
170+
Step-by-Step Instructions
171+
172+
1. Open your terminal. All commands must be run in the same session, as environment variables are typically not permanent.
173+
2. Set the environment variables to point to your desired compilers.
174+
175+
Example for C (using a specific gcc):
149176

150177
.. code-block:: console
178+
export CC=/path/to/my/custom/gcc
151179
152-
FC=/path/to/fcompiler LDSHARED=/path/to/fcompiler python setup.py install
180+
Example for Fortran (using a specific gfortran):
153181

182+
.. code-block:: console
183+
export FC=/path/to/my/custom/gfortran
154184
185+
Example for C++ (if the project needed it):
155186

156-
A specific setup.py script is provided to install it easily in FOSS clusters.
187+
.. code-block:: console
188+
export CXX=/path/to/my/custom/g++
157189
190+
3. Combine them as needed. For this project, you will likely need to set CC and FC.
191+
192+
# Example using compilers from a specific toolchain
193+
.. code-block:: console
194+
export CC=/usr/local/bin/gcc-11
195+
export FC=/usr/local/bin/gfortran-11
196+
197+
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.
198+
199+
.. code-block:: console
200+
# Ensure you are in the project's root directory (where pyproject.toml is)
201+
pip install .
202+
203+
The build process will now use the compilers you specified instead of the system defaults.
204+
205+
Method 2: Using a Meson Cross File (Advanced & Reproducible)
206+
------------------------------------------------------------
207+
208+
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.
209+
Step-by-Step Instructions
210+
211+
1. Create a cross file. In your project's root directory, create a file named native-toolchain.ini (the name can be anything).
212+
213+
2. Edit the file to specify the paths to your compilers in the [binaries] section.
214+
215+
Example native-toolchain.ini:
216+
217+
.. code-block:: console
218+
# native-toolchain.ini
219+
# Defines the compilers to use for the build.
220+
221+
[binaries]
222+
c = '/path/to/my/custom/gcc'
223+
fortran = '/path/to/my/custom/gfortran'
224+
225+
# If you also needed C++, you would add:
226+
# cpp = '/path/to/my/custom/g++'
227+
228+
Note: The keys are c, cpp, and fortran.
229+
230+
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.
231+
232+
.. code-block:: console
233+
# The --native-file option tells Meson which toolchain to use.
234+
pip install . --config-settings=meson-args="--native-file=native-toolchain.ini"
158235
236+
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.

0 commit comments

Comments
 (0)