Skip to content

Commit 789d575

Browse files
authored
Merge pull request #3 from DanShort12/implement_ci
Implement CI Implements a CI pipeline to build, test, and publish wheels as artifacts. Implements a baseline set of tests.
2 parents c2cc5ea + 3353357 commit 789d575

9 files changed

Lines changed: 171 additions & 17 deletions

File tree

.github/workflows/python.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Python package
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build_and_test:
11+
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: [3.6, 3.7, 3.8]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Install plasma source
24+
run: |
25+
pip install -r requirements-develop.txt
26+
python setup.py bdist_wheel
27+
python -m pip install --verbose dist/*.whl
28+
- name: Run tests
29+
run: |
30+
pytest tests
31+
- name: Upload wheel artifact
32+
uses: actions/upload-artifact@v2
33+
with:
34+
name: dist
35+
path: dist

CMakeLists.txt

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ set(OPENMC_DIR /opt/openmc)
1818
set(OPENMC_INC_DIR ${OPENMC_DIR}/include)
1919
set(OPENMC_LIB_DIR ${OPENMC_DIR}/lib)
2020

21+
# Ensure submodules are available and up to date
22+
find_package(Git QUIET)
23+
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
24+
# Update submodules as needed
25+
option(GIT_SUBMODULE "Check submodules during build" ON)
26+
if(GIT_SUBMODULE)
27+
message(STATUS "Submodule update")
28+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
29+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
30+
RESULT_VARIABLE GIT_SUBMOD_RESULT)
31+
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
32+
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
33+
endif()
34+
endif()
35+
endif()
36+
37+
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/pybind11/CMakeLists.txt")
38+
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
39+
endif()
40+
2141
# Build source_sampling
2242
list(APPEND source_sampling_SOURCES
2343
${SRC_DIR}/source_sampling.cpp
@@ -26,13 +46,15 @@ list(APPEND source_sampling_SOURCES
2646

2747
add_library(source_sampling SHARED ${source_sampling_SOURCES})
2848

29-
find_library(OPENMC_LIB openmc HINTS ${OPENMC_LIB_DIR})
49+
find_library(OPENMC_LIB openmc HINTS ${OPENMC_LIB_DIR} OPTIONAL)
3050

31-
set_target_properties(source_sampling PROPERTIES PREFIX "")
32-
set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON)
33-
target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR})
34-
target_include_directories(source_sampling PUBLIC ${OPENMC_DIR}/vendor/pugixml)
35-
target_link_libraries(source_sampling ${OPENMC_LIB} gfortran)
51+
if (OPENMC_LIB)
52+
set_target_properties(source_sampling PROPERTIES PREFIX "")
53+
set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON)
54+
target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR})
55+
target_include_directories(source_sampling PUBLIC ${OPENMC_DIR}/vendor/pugixml)
56+
target_link_libraries(source_sampling ${OPENMC_LIB} gfortran)
57+
endif()
3658

3759
# Build plasma_source Python bindings
3860
list(APPEND plasma_source_pybind_SOURCES

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# parametric-plasma-source
22

3+
![Python package](https://github.com/DanShort12/parametric-plasma-source/workflows/Python%20package/badge.svg)
4+
35
Python package, C++ source and build files for parametric plasma source for use in fusion neutron transport calculations with OpenMC.
46

57
The plasma source is based on a paper by [C. Fausser et al](https://www.sciencedirect.com/science/article/pii/S0920379612000853)
68

7-
# Installation
9+
## Installation
810

911
```pip install parametric_plasma_source```
1012

11-
# Usage
13+
## Usage
1214

1315
The parametric plasma source can be imported an used in Python 3 in the following manner.
1416

15-
```
17+
```[python]
1618
from parametric_plasma_source import Plasma
1719
my_plasma = Plasma(major_radius=6,
1820
minor_radius=1.5,
@@ -25,7 +27,7 @@ In the above example the major_radius, minor_radius, elongation and triangularit
2527

2628
There are a number of additional arguments that can be passed to the Plasma class on construction. Units are in SI (e.g. meters not cm)
2729

28-
```
30+
```[python]
2931
ion_density_pedistal = 1.09e+20
3032
ion_density_seperatrix = 3e+19
3133
ion_density_origin = 1.09e+20
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
from .plasma import Plasma
2-
from .plasma_source import PlasmaSource

parametric_plasma_source/plasma_source.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
#include <cmath>
44
#include "plasma_source.hpp"
55
#include <stdlib.h>
6-
#include "openmc/random_lcg.h"
7-
8-
#define RANDOM openmc::prn()
96

107
namespace plasma_source {
118

requirements-develop.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest
2+
wheel

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def build_extension(self, ext):
3636
"-DPYTHON_EXECUTABLE=" + sys.executable]
3737

3838
cfg = "Debug" if self.debug else "Release"
39-
build_args = ["--config", cfg]
39+
build_args = ["--target", "plasma_source"]
40+
build_args += ["--config", cfg]
4041

4142
cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg]
4243
build_args += ["--", "-j2"]
43-
build_args += ["plasma_source"]
4444

4545
env = os.environ.copy()
4646
env["CXXFLAGS"] = "{} -DVERSION_INFO=\\\"{}\\\"".format(

tests/test_Compile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from parametric_plasma_source.plasma import Plasma
1010

11+
pytest.importorskip("openmc")
12+
1113
class test_object_properties(unittest.TestCase):
1214

1315
def test_compile(self):

tests/test_plasma_source.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""Tests for the methods in plasma_source."""
2+
3+
import pytest
4+
5+
from parametric_plasma_source.plasma_source import PlasmaSource
6+
7+
plasma_params = {
8+
"elongation": 1.557,
9+
"ion_density_origin": 1.09e20,
10+
"ion_density_peaking_factor": 1,
11+
"ion_density_pedistal": 1.09e20,
12+
"ion_density_seperatrix": 3e19,
13+
"ion_temperature_origin": 45.9,
14+
"ion_temperature_peaking_factor": 8.06,
15+
"ion_temperature_pedistal": 6.09,
16+
"ion_temperature_seperatrix": 0.1,
17+
"major_radius": 906.0,
18+
"minor_radius": 292.258,
19+
"pedistal_radius": 0.8 * 292.258,
20+
"plasma_id": 1,
21+
"shafranov_shift": 44.789,
22+
"triangularity": 0.270,
23+
"ion_temperature_beta": 6,
24+
}
25+
26+
27+
@pytest.fixture(scope="session")
28+
def plasma_source():
29+
"""Make a plasma source to use as a test fixture."""
30+
return PlasmaSource(**plasma_params)
31+
32+
33+
class TestPlasmaSource:
34+
"""A class to run tests against the plasma source."""
35+
36+
def test_ion_density_magnetic_origin(self, plasma_source):
37+
"""Test the ion density at the magnetic origin."""
38+
ion_density = plasma_source.ion_density(0.0)
39+
40+
assert pytest.approx(ion_density, 1.09e20)
41+
42+
def test_ion_density_inside_pedestal(self, plasma_source):
43+
"""Test the ion density inside the pedestal."""
44+
ion_density = plasma_source.ion_density(0.2)
45+
46+
assert pytest.approx(ion_density, 1.09e20)
47+
48+
def test_ion_density_outside_pedestal(self, plasma_source):
49+
"""Test the ion density outside the pedestal."""
50+
ion_density = plasma_source.ion_density(2.4)
51+
52+
assert pytest.approx(ion_density, 1.00628584e20)
53+
54+
def test_ion_density_boundary(self, plasma_source):
55+
"""Test the ion density at the boundary."""
56+
boundary = plasma_params["minor_radius"] / 100.0
57+
ion_density = plasma_source.ion_density(boundary)
58+
59+
assert pytest.approx(
60+
ion_density, plasma_params["ion_density_seperatrix"]
61+
)
62+
63+
def test_ion_temperature_magnetic_origin(self, plasma_source):
64+
"""Test the ion temperature at the magnetic origin."""
65+
ion_temperature = plasma_source.ion_temperature(0.0)
66+
67+
assert pytest.approx(
68+
ion_temperature, plasma_params["ion_temperature_origin"]
69+
)
70+
71+
def test_ion_temperature_inside_pedestal(self, plasma_source):
72+
"""Test the ion temperature inside the pedestal."""
73+
ion_temperature = plasma_source.ion_temperature(0.2)
74+
75+
assert pytest.approx(ion_temperature, 45.89987429)
76+
77+
def test_ion_temperature_outside_pedestal(self, plasma_source):
78+
"""Test the ion temperature outside the pedestal."""
79+
ion_temperature = plasma_source.ion_temperature(2.4)
80+
81+
assert pytest.approx(ion_temperature, 5.45525594)
82+
83+
def test_ion_temperature_boundary(self, plasma_source):
84+
"""Test the ion temperature at the boundary."""
85+
boundary = plasma_params["minor_radius"] / 100.0
86+
ion_temperature = plasma_source.ion_temperature(boundary)
87+
88+
assert pytest.approx(
89+
ion_temperature, plasma_params["ion_temperature_seperatrix"]
90+
)
91+
92+
def test_dt_cross_section(self, plasma_source):
93+
"""Test the dt cross section at a specific temperature."""
94+
dt_cross_section = plasma_source.dt_xs(4.25e7)
95+
96+
assert pytest.approx(dt_cross_section, 0.0)

0 commit comments

Comments
 (0)