Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
93 changes: 71 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Build DiffuseCode with the Python module and run the tests.
#
# 1. pytest tests/python – diffuse package, suite_python, golden data, demo
# 2. legacy macro tests – tools/run_legacy_tests.py, tags fast and mc
# 3. documentation – Sphinx (docs/), uploaded as the "docs-html"
# artifact; not published anywhere yet
# linux full build with graphics (PGPLOT, X11):
# legacy macro tests (tools/run_legacy_tests.py) + pytest
# python-nographics DIFFUSE_GRAPHICS=OFF without PGPLOT/X11 installed (the
# set-up of the future Python package): pytest + Sphinx
# docs, uploaded as the "docs-html" artifact
# publish-docs pushes to claude-python-app only: docs to gh-pages
#
# Development happens on claude-python-app until the first release of the
# Python package; feature branches (claude/**) merge into it.
Expand All @@ -24,10 +26,7 @@ jobs:
linux:
runs-on: ubuntu-24.04
timeout-minutes: 60
env:
FC: gfortran
CC: gcc
CXX: g++
# No FC/CC/CXX and no PGPLOT_DIR: CMake finds the compilers and PGPLOT.
steps:
- uses: actions/checkout@v4

Expand All @@ -42,19 +41,17 @@ jobs:
- name: Configure
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
-DDIFFUSE_PYTHON=ON -DPGPLOT_DIR=/usr/lib/pgplot5 \
-DPYTHON_EXECUTABLE=/usr/bin/python3 -Wno-dev
-DDIFFUSE_PYTHON=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 -Wno-dev

- name: Build
run: cmake --build build -j "$(nproc)"

- name: Python environment
# --system-site-packages: use the apt NumPy/matplotlib/pytest that the
# compiled module was built against; add gemmi (test references) and
# the docs tools.
# compiled module was built against; add gemmi (test references).
run: |
python3 -m venv --system-site-packages .venv
.venv/bin/pip install --quiet -r tests/requirements.txt -r docs/requirements.txt
.venv/bin/pip install --quiet -r tests/requirements.txt

- name: Python tests (pytest)
env:
Expand All @@ -67,14 +64,69 @@ jobs:

- name: Legacy macro tests
# Tests tagged mc run with "seed 1234" on one thread (repeatable). A
# failed mc test is still re-run: 04.sro3 rarely gets a broken Fourier
# result (WP0 log). A pass on retry is reported as flaky; a real break
# still fails.
# failed mc test is still re-run: 04.sro3 can get a broken Fourier
# result after its MMC run (WP0 log). A pass on retry is reported as
# flaky; a real break still fails.
run: |
python3 tools/run_legacy_tests.py \
--exe build/suite/prog/discus_suite -j "$(nproc)" \
--tags fast,mc --retry-mc 2 --junit legacy-results.xml --workdir legacy-work

- name: Upload results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
pytest-results.xml
legacy-results.xml
legacy-work/**/*.log
if-no-files-found: ignore

# The Python package needs no graphics: build without PGPLOT and X11
# (neither is installed here), check nothing links them, run the Python
# tests and build the docs.
python-nographics:
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- uses: actions/checkout@v4

- name: Install dependencies (no PGPLOT, X11 or Xvfb)
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
gfortran cmake make libfftw3-dev libhdf5-dev libreadline-dev zlib1g-dev \
python3-dev python3-numpy python3-pytest python3-matplotlib python3-venv

- name: Configure (DIFFUSE_GRAPHICS=OFF)
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DDIFFUSE_GRAPHICS=OFF \
-DDIFFUSE_PYTHON=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 -Wno-dev

- name: Build
run: cmake --build build -j "$(nproc)"

- name: Check that nothing links PGPLOT, X11 or PNG
run: |
for f in build/suite/prog/discus_suite build/python/suite_python*.so; do
if ldd "$f" | grep -i -E 'pgplot|libx11|libpng'; then
echo "::error::$f links graphics libraries"; exit 1
fi
done

- name: Python environment
run: |
python3 -m venv --system-site-packages .venv
.venv/bin/pip install --quiet -r tests/requirements.txt -r docs/requirements.txt

- name: Python tests (pytest)
env:
DIFFUSE_PYTHON_PATH: ${{ github.workspace }}/build/python
DIFFUSE_REQUIRE_PYTHON: "1"
MPLBACKEND: Agg
run: .venv/bin/python -m pytest tests/python -v -rxs --junitxml=pytest-nographics.xml

- name: Documentation
if: success() || failure()
env:
Expand All @@ -95,19 +147,16 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
pytest-results.xml
legacy-results.xml
legacy-work/**/*.log
name: test-results-nographics
path: pytest-nographics.xml
if-no-files-found: ignore

# Publish the docs to https://tproffen.github.io/DiffuseCode/python-docs/
# The gh-pages branch is the DISCUS homepage: tools/publish_docs.sh only
# replaces python-docs/ (plus an empty .nojekyll at the root) and refuses
# to publish if anything else would change.
publish-docs:
needs: linux
needs: [linux, python-nographics]
if: github.event_name == 'push' && github.ref == 'refs/heads/claude-python-app'
runs-on: ubuntu-24.04
timeout-minutes: 10
Expand Down
7 changes: 4 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ targets `claude-python-app`.
## Build and test

```bash
FC=gfortran CC=gcc CXX=g++ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
-DDIFFUSE_PYTHON=ON -DPGPLOT_DIR=/usr/lib/pgplot5
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DDIFFUSE_PYTHON=ON
# add -DDIFFUSE_GRAPHICS=OFF for a build without PGPLOT/X11 (what the Python
# package will use; CI tests both)
cmake --build build -j
pip install -r tests/requirements.txt # gemmi
DIFFUSE_PYTHON_PATH=build/python python3 -m pytest tests/python
python3 tools/run_legacy_tests.py --exe build/suite/prog/discus_suite -j 4 --tags fast,mc
```

CMake needs `FC` set. Keep build trees outside `tests/`.
CMake finds the compilers itself (`FC` is optional). Keep build trees outside `tests/`.

## Documentation

Expand Down
13 changes: 4 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ cmake_minimum_required(VERSION 3.12.0)
project(DIFFUSE)
enable_language(Fortran)

if ( NOT DEFINED ENV{FC} )
message(FATAL_ERROR "The environment variable FC is not set
Please set FC to the full path to fortran compiler before running CMake/ccmake
For example use: export FC=$(which gfortran) or export FC=$(which ifort) ")
else ()
message (status " FC set to $ENV{FC} ")
endif()
set (CMAKE_Fortran_COMPILER $ENV{FC})
message ( status " TOPLEVEL COMPILER is ${CMAKE_Fortran_COMPILER}" )
# CMake chooses the Fortran compiler in enable_language() above: from
# -DCMAKE_Fortran_COMPILER=..., else the FC environment variable, else the
# first one it finds (gfortran, ifort, ...). FC is no longer required.
message ( status " TOPLEVEL COMPILER is ${CMAKE_Fortran_COMPILER} (${CMAKE_Fortran_COMPILER_ID})" )

# Detect if Intel or Portland Fortran compiler is used.
if (${CMAKE_Fortran_COMPILER} MATCHES "ifort")
Expand Down
12 changes: 9 additions & 3 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ On Debian or Ubuntu, install the build dependencies:

```bash
sudo apt-get install -y gfortran cmake libfftw3-dev libhdf5-dev libreadline-dev \
libpng-dev libx11-dev zlib1g-dev pgplot5 python3-dev python3-numpy python3-matplotlib
zlib1g-dev python3-dev python3-numpy python3-matplotlib
```

The Python interface needs no graphics libraries: `-DDIFFUSE_GRAPHICS=OFF`
below builds without PGPLOT and X11. For the classic `discus_suite` with
KUPLOT plots, leave that option out and also install `libpng-dev libx11-dev
pgplot5`.

Then, from the repository root:

```bash
FC=gfortran CC=gcc CXX=g++ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
-DDIFFUSE_PYTHON=ON -DPGPLOT_DIR=/usr/lib/pgplot5
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DDIFFUSE_PYTHON=ON -DDIFFUSE_GRAPHICS=OFF
cmake --build build -j
```

This builds `discus_suite` and the Python module `build/python/suite_python*.so`.
CMake finds the Fortran compiler itself; set `FC` (or
`-DCMAKE_Fortran_COMPILER=...`) only to pick a different one.

## Use

Expand Down
30 changes: 24 additions & 6 deletions kuplot/prog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ if(DIFFUSE_GRAPHICS)
kuplot_select_device.f90 )
set (LIBS lib_f90 lib_f90c ${DIFFUSE_LIBS} ${PNG_LIBRARY})
set (LIBS_GRAPHIC ${PGPLOT_PGPLOT_LIBRARY} ${X11_X11_LIB} )
set (PGSERVER ${PGPLOT_DIR}/pgxwin_server)
set (LIBS_GRAPHIC ${LIBS_GRAPHIC} ${PNG_LIBRARY})
else (DIFFUSE_GRAPHICS)
set (SOURCES_GRAPHIC color_low_nographic.f90 draw_nographic.f90
Expand Down Expand Up @@ -95,11 +94,30 @@ if (DIFFUSE_SHARED_LIB)
install (TARGETS kuplot_all DESTINATION lib)
endif (DIFFUSE_SHARED_LIB)

option(INSTALL_PGPLOT "Switch to optionally install pgplot files" ON)
if (INSTALL_PGPLOT)
install (FILES ${PGPLOT_DIR}/grfont.dat DESTINATION share)
install (PROGRAMS ${PGSERVER} DESTINATION bin)
endif (INSTALL_PGPLOT)
# PGPLOT's font file and X11 server are copied into the installation, so
# that KUPLOT finds them next to discus_suite. They are looked up in
# PGPLOT_DIR and in the usual system places (Debian/Ubuntu: grfont.dat in
# /usr/lib/pgplot5, pgxwin_server in /usr/bin); a file that is not found is
# skipped with a warning. Nothing is installed without graphics.
option(INSTALL_PGPLOT "Switch to optionally install pgplot files" ${DIFFUSE_GRAPHICS})
if (INSTALL_PGPLOT AND DIFFUSE_GRAPHICS)
find_file (PGPLOT_GRFONT grfont.dat
PATHS ${PGPLOT_DIR} $ENV{PGPLOT_DIR} /usr/lib/pgplot5 /usr/local/pgplot
/usr/share/pgplot5 /usr/local/share/pgplot /opt/local/lib/pgplot
NO_DEFAULT_PATH)
find_program (PGPLOT_SERVER pgxwin_server
PATHS ${PGPLOT_DIR} $ENV{PGPLOT_DIR} /usr/lib/pgplot5 /usr/local/pgplot)
if (PGPLOT_GRFONT)
install (FILES ${PGPLOT_GRFONT} DESTINATION share)
else ()
message (WARNING "PGPLOT grfont.dat not found; not installed (set PGPLOT_DIR)")
endif ()
if (PGPLOT_SERVER)
install (PROGRAMS ${PGPLOT_SERVER} DESTINATION bin)
else ()
message (WARNING "pgxwin_server not found; not installed (set PGPLOT_DIR)")
endif ()
endif (INSTALL_PGPLOT AND DIFFUSE_GRAPHICS)

FILE(GLOB files "${DIFFUSE_SOURCE_DIR}/kuplot/prog/sysmac/*.mac")
install (FILES ${files} DESTINATION share/kuplot)
Expand Down
Loading
Loading