Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions #1

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4ac1307
Create test_examples.yml
JulienDoerner Oct 26, 2023
13c0565
Update installation
JulienDoerner Oct 26, 2023
41040e3
add vector include
JulienDoerner Oct 26, 2023
75ffaba
change secondaries in EMPP test to pointer
JulienDoerner Oct 26, 2023
0aae03c
add pythonpath for notebook conversion
JulienDoerner Oct 26, 2023
3ca1463
use less test steps, add debug statements
JulienDoerner Oct 26, 2023
c64632d
update pythonpath variable
JulienDoerner Oct 26, 2023
e92f74a
fix typos
JulienDoerner Oct 26, 2023
9293bc6
show current pathes in action
JulienDoerner Oct 26, 2023
b54082e
more detailed description
JulienDoerner Oct 26, 2023
5155ef3
fix typo
JulienDoerner Oct 26, 2023
769c173
add printing path
JulienDoerner Oct 26, 2023
5435eb3
extact field from vector before passing to module
JulienDoerner Oct 26, 2023
0405a41
move to python3 statement
JulienDoerner Oct 26, 2023
02b3d01
fix typo
JulienDoerner Oct 26, 2023
5b339bd
update example testing
JulienDoerner Oct 26, 2023
3ef7cfd
add execution of python scripts
JulienDoerner Oct 26, 2023
626bfe0
filter for magic comands
JulienDoerner Oct 26, 2023
a49e2b3
add printings
JulienDoerner Oct 26, 2023
5fdcac6
add more print statements
JulienDoerner Oct 26, 2023
d8d9d4c
update workflow
JulienDoerner Oct 26, 2023
9192b21
fix typo
JulienDoerner Oct 27, 2023
db214f4
simplify OSX test for faster testing
JulienDoerner Oct 27, 2023
cbc2440
fix typo
JulienDoerner Oct 27, 2023
7ace51b
update path
JulienDoerner Oct 27, 2023
3aeccd4
more debug statements
JulienDoerner Oct 27, 2023
8b77ffe
add import test
JulienDoerner Oct 27, 2023
60682a4
fix for magic comand
JulienDoerner Oct 27, 2023
b6360c7
improve debugging
JulienDoerner Oct 27, 2023
e651bcf
typo fix
JulienDoerner Oct 27, 2023
cb02918
update example testing and add failing test
JulienDoerner Oct 27, 2023
2e96185
update tests
JulienDoerner Oct 27, 2023
b180ac5
update
JulienDoerner Oct 27, 2023
15b270c
add more debug statements
JulienDoerner Oct 27, 2023
e54d16d
remove delete statement
JulienDoerner Oct 27, 2023
96600f9
add python requriements for examples
JulienDoerner Oct 27, 2023
f5a4af6
fix typo in filename
JulienDoerner Oct 27, 2023
67e91e2
add jupyter to python requirements
JulienDoerner Oct 27, 2023
2bf416f
upgread numpy
JulienDoerner Oct 27, 2023
d612c1a
print running notebook
JulienDoerner Oct 30, 2023
d5ffe49
Merge branch 'actions' of github.com:JulienDoerner/CRPropa3 into actions
JulienDoerner Oct 30, 2023
b9a7a63
add some notebooks to skip
JulienDoerner Oct 30, 2023
3384c89
test examples with skipping external dependencies
JulienDoerner Nov 8, 2023
8050fd8
Update test_examples.yml
JulienDoerner Nov 8, 2023
cdec99d
add documentation
JulienDoerner Nov 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/create_documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: create-documentation
on:
workflow_dispatch

jobs:
create-documentation:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
config:
- name: "ubuntu-20"
os: ubuntu-20.04
cxx: "g++-9"
cc: "gcc-9"
fc: "gfortran-9"
swig_builtin: "Off" #uses swig 4.0.1
py: "/usr/bin/python3" #python 3.8

# define steps to take
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Python install
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip' # caching pip dependencies
- name: Prerequirements
run: |
sudo apt-get update
sudo apt-get install libmuparser-dev libhdf5-serial-dev libomp5 libomp-dev libfftw3-dev libcfitsio-dev lcov
pip install -r doc/pages/example_notebooks/requirements.txt # load requrements for notebooks
- name: Set up the build
env:
CXX: ${{ matrix.config.cxx }}
CC: ${{ matrix.config.cc }}
FC: ${{ matrix.config.fc }}
run: |
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/.local
-DENABLE_PYTHON=True -DPYTHON_EXECUTABLE=${{ matrix.config.py }}
-DENABLE_TESTING=Off -DENABLE_SWIG_BUILTIN=${{ matrix.config.swig_builtin }}
-DSIMD_EXTENSIONS=native
-DBUILD_DOC=True -DENABLE_COVERAGE=True
- name: Build CRPropa
run: |
cd build
make -j
- name: run test
run: |
cd build
make test
continue-on-error: true
- name: coverage and documentation
run: |
cd build
make coverage
tar -zcvf coverage.tar.gz coverageReport
make doc
tar -zcvf documentation.tar.gz doc
- name: archive documentation
uses: actions/upload-artifact@v3
with:
name: "documentation.tar.gz"
path: |
documentation.tar.gz
coverage.tar.gz
77 changes: 77 additions & 0 deletions .github/workflows/test_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: crpropa-example-test
on: [push, pull_request]

jobs:
linux:
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- name: "ubuntu-20"
os: ubuntu-20.04
cxx: "g++-9"
cc: "gcc-9"
fc: "gfortran-9"
swig_builtin: "Off" #uses swig 4.0.1
py: "/usr/bin/python3" #python 3.8
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Preinstall
run: |
sudo apt-get update
sudo apt-get install libmuparser-dev python3-dev python-dev python3-numpy python-numpy python3-setuptools python-setuptools libhdf5-serial-dev libomp5 libomp-dev libfftw3-dev libcfitsio-dev lcov
pip3 install -r doc/pages/example_notebooks/requirements.txt # load requrements for notebooks
pip3 install --upgrade Pygments
pip3 install --upgrade numpy
- name: Set up the build
env:
CXX: ${{ matrix.config.cxx }}
CC: ${{ matrix.config.cc }}
FC: ${{ matrix.config.fc }}
run: |
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/.local -DENABLE_PYTHON=True -DPYTHON_EXECUTABLE=${{ matrix.config.py }} -DENABLE_TESTING=Off -DENABLE_SWIG_BUILTIN=${{ matrix.config.swig_builtin }} -DSIMD_EXTENSIONS=native
- name: Build CRPropa
run: |
cd build
make install -j
- name: convert notebooks to python
env:
PYTHONPATH: "/home/runner/.local/lib/python3.8/site-packages/"
runfolder: "/home/runner/notebook_run"
run: |
mkdir "$runfolder"
cd doc/pages/example_notebooks/
for file in */*.ipynb; do
echo "$file"
if [ -f "$file" ]; then
f=(${file//// })
f=${f[1]}
f=(${f//./})
finalFile="$runfolder"/"$f".py
echo "convert notebook $file to script $finalFile"
jupyter nbconvert --to python "$file" --stdout | grep -v -e "^get_ipython" > "$runfolder"/"$f".py
fi
done
- name: run all python scripts
env:
PYTHONPATH: "$/home/runner/.local/lib/python3.8/site-packages/"
runfolder: "/home/runner/notebook_run"
run: |
cd "$runfolder"
function skip() { # this notebooks have external dependencies and can not be tested
if [ "$1" = "custom-photon-fieldipynb.py" ] || [ "$1" = "MHD_modelsipynb.py" ] || [ "$1" = "density_grid_samplingipynb.py" ]; then
return 1
fi
return 0
}
for file in *.py; do
echo "work on file $file"
skip "$file"
if [ $? -eq 0 ]; then
python3 "$file"
fi
done
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: crpropa-testing
on: [push, pull_request]
on: [pull_request]

jobs:
linux:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/testing_OSX.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DENABLE_PYTHON=True -DPYTHON_EXECUTABLE=${{ matrix.config.py }} -DENABLE_TESTING=On -DENABLE_SWIG_BUILTIN=${{ matrix.config.swig_builtin }} -DSIMD_EXTENSIONS=avx
cmake .. -DENABLE_PYTHON=False -DENABLE_TESTING=On -DSIMD_EXTENSIONS=avx -DENABLE_HDF5=OFF -DENABLE_GALACTICMAGETICLENS=OFF
- name: Build CRPropa
run: |
cd build
Expand All @@ -39,7 +39,7 @@ jobs:
CRPROPA_DATA_PATH: "/Users/runner/work/CRPropa3/CRPropa3/build/data"
run: |
cd build
make test
./testInteraction
- name: Archive test results
if: always()
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing_ubuntu22.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: crpropa-testing_ubuntu22
on: [push, pull_request]
on: [pull_request]

jobs:
linux:
Expand Down
53 changes: 53 additions & 0 deletions doc/pages/example_notebooks/basics/failing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "RuntimeError",
"evalue": "this notebook should not succeed",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/home1/jdo/CRPropa3/doc/pages/example_notebooks/basics/faining.ipynb Zelle 1\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> <a href='vscode-notebook-cell://ssh-remote%2Bk10/home/home1/jdo/CRPropa3/doc/pages/example_notebooks/basics/faining.ipynb#W0sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mRuntimeError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mthis notebook should not succeed\u001b[39m\u001b[39m\"\u001b[39m)\n",
"\u001b[0;31mRuntimeError\u001b[0m: this notebook should not succeed"
]
}
],
"source": [
"raise RuntimeError(\"this notebook should not succeed\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
10 changes: 10 additions & 0 deletions doc/pages/example_notebooks/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# collection of all packages used in the analyis of the example notebooks. This is used for the automatic test of the notebooks
numpy
matplotlib
pandas
healpy
seaborn
scipy
tqdm
h5py
jupyter
40 changes: 31 additions & 9 deletions test/testInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#include "gtest/gtest.h"

#include <fstream>
#include <vector>

namespace crpropa {

/*
// ElectronPairProduction -----------------------------------------------------
TEST(ElectronPairProduction, allBackgrounds) {
// Test if interaction data files are loaded.
Expand Down Expand Up @@ -694,7 +696,7 @@ TEST(Redshift, limitRedshiftDecrease) {
redshift.process(&c);
EXPECT_DOUBLE_EQ(0, c.getRedshift());
}

*/
// EMPairProduction -----------------------------------------------------------
TEST(EMPairProduction, allBackgrounds) {
// Test if interaction data files are loaded.
Expand Down Expand Up @@ -735,44 +737,64 @@ TEST(EMPairProduction, limitNextStep) {
}

TEST(EMPairProduction, secondaries) {
std::cout << "start with the test \n";
// Test if secondaries are correctly produced.
ref_ptr<PhotonField> CMB_instance = new CMB();
ref_ptr<PhotonField> IRB = new IRB_Gilmore12();
ref_ptr<PhotonField> URB = new URB_Protheroe96();
std::cout << "photon field instances created \n";
EMPairProduction m(CMB_instance);
m.setHaveElectrons(true);
m.setThinning(0.);

std::vector< ref_ptr<PhotonField> > fields;
std::cout << "created photon field list \n add ";
fields.push_back(CMB_instance);
std::cout << "first";
fields.push_back(IRB);
std::cout << " / second";
fields.push_back(URB);
std::cout << " / thrid field to list\n";
std::cout << "have in total " << fields.size() << "fields\n";

// loop over photon backgrounds
for (int f = 0; f < fields.size(); f++) {
m.setPhotonField(fields[f]);
std::cout << "start loop f = " << f << "\n";
ref_ptr<PhotonField> field = fields[f];
std::cout << "got Photonfield \n";
m.setPhotonField(field);
std::cout << "give photonfield to model \n";
for (int i = 0; i < 140; i++) { // loop over energies Ep = (1e10 - 1e23) eV
double Ep = pow(10, 9.05 + 0.1 * i) * eV;
Candidate c(22, Ep);
EXPECT_TRUE(c.isActive()); // new candidate is always active

//c.setCurrentStep(std::numeric_limits<double>::max());
c.setCurrentStep(1e10 * Mpc);
m.process(&c);

std::cout << "i = " << i << " processed the candidate. Candidate is now ";
// pass if no interaction has occured (no tabulated rates)
if (c.isActive())
if (c.isActive()) {
std::cout << "active\n";
continue;
}

std::cout << "inactive and has " << c.secondaries.size() << "secondaries \n";

// expect 2 secondaries
EXPECT_EQ(c.secondaries.size(), 2);

std::cout << "no. of secondaries is " << c.secondaries.size() << "\n";

// expect electron / positron with energies 0 < E < Ephoton
double Etot = 0;
for (int j = 0; j < c.secondaries.size(); j++) {
Candidate s = *c.secondaries[j];
EXPECT_EQ(abs(s.current.getId()), 11);
EXPECT_GT(s.current.getEnergy(), 0);
EXPECT_LT(s.current.getEnergy(), Ep);
Etot += s.current.getEnergy();
ref_ptr<Candidate> s = c.secondaries[j];
std::cout << "\t secondary #" << j << " works \n";
EXPECT_EQ(abs(s->current.getId()), 11);
EXPECT_GT(s->current.getEnergy(), 0);
EXPECT_LT(s->current.getEnergy(), Ep);
Etot += s->current.getEnergy();
}

// test energy conservation
Expand Down
Loading