Skip to content

Commit 8cab0f5

Browse files
authored
Merge branch 'main' into new-ckpt-restart-tests
2 parents e09d392 + 9bfe665 commit 8cab0f5

File tree

9 files changed

+83
-37
lines changed

9 files changed

+83
-37
lines changed

.circleci/config.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ commands:
112112
usegrackle:
113113
type: boolean
114114
default: true
115+
setupCTests:
116+
type: boolean
117+
default: true
118+
description: whether to build CTest machinery (has no effect on pytest framework)
115119
steps:
116120
- run:
117121
name: "Checkout target tag from enzo-e repository."
@@ -128,9 +132,6 @@ commands:
128132
source $BASH_ENV
129133
source $HOME/venv/bin/activate
130134
131-
# convert boolean parameter to an env var storing 0 or 1
132-
USE_DOUBLE=$(( 0 <<# parameters.usedouble >> + 1 <</ parameters.usedouble >> ))
133-
USE_GRACKLE=$(( 0 <<# parameters.usegrackle >> + 1 <</ parameters.usegrackle >> ))
134135
# remove build directory in case we've already compiled before
135136
rm -rf build
136137
@@ -139,11 +140,11 @@ commands:
139140
-GNinja \
140141
-DUSE_DOUBLE_PREC=<< parameters.usedouble >> \
141142
-DUSE_GRACKLE=<< parameters.usegrackle >> \
143+
-DBUILD_TESTING=<< parameters.setupCTests >> \
142144
-Bbuild \
143145
-DPARALLEL_LAUNCHER_NPROC_ARG="++local;+p" \
144146
-DPython3_FIND_VIRTUALENV=ONLY
145147
cmake --build build -j 4
146-
source $HOME/venv/bin/activate
147148
fi
148149
149150
run-ctests:
@@ -277,6 +278,7 @@ jobs:
277278
tag: tip
278279
skipfile: notafile
279280
usegrackle: << parameters.usegrackle >>
281+
setupCTests: true
280282

281283
- run-ctests:
282284
skipfile: notafile
@@ -321,6 +323,7 @@ jobs:
321323
tag: gold-standard-004
322324
skipfile: notafile
323325
usegrackle: << parameters.usegrackle >>
326+
setupCTests: false
324327

325328
- run-answer-tests:
326329
usedouble: << parameters.usedouble >>
@@ -332,6 +335,7 @@ jobs:
332335
tag: tip
333336
skipfile: notafile
334337
usegrackle: << parameters.usegrackle >>
338+
setupCTests: false
335339

336340
- run-answer-tests:
337341
usedouble: << parameters.usedouble >>

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ if (__processedUserDefaults)
309309
include(${Enzo-E_CONFIG_PATH})
310310
endif()
311311

312+
# we need to pull CTest sooner or later anyways. We do it before adding the
313+
# source directories because it introduces the BUILD_TESTING option which is
314+
# set to ON if it was not previously initialized (e.g. from the command line)
315+
# -> this option is used within source directories to determine whether the
316+
# binaries for unit-tests should be declared
317+
include(CTest)
318+
312319
# In principle a more fine grained control (i.e., target specific include directories
313320
# rather than this global one would be preferred, but, e.g., `pngwriter.h` is curently
314321
# included in many targets/libraries (without being linked) so we'll use the global for
@@ -321,10 +328,7 @@ add_subdirectory(src/Enzo)
321328
add_subdirectory(src/External)
322329

323330

324-
include(CTest)
325331

326-
# include(CTest) implicitly initializes BUILD_TESTING to ON if it was not
327-
# previously initialized (e.g. from the command line)
328332
if (BUILD_TESTING)
329333
add_subdirectory(test)
330334
endif()

doc/source/tests/pytest_framework.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ simulation is run with two versions of ``enzo-e`` and their results are compared
99
This is useful for testing problems with no analytical solution or generally
1010
verifying that results from commonly run simulations don't drift.
1111

12-
It is also useful for testing properties of simulation runs beyond the exit-time/cycle of the simulation.
13-
(While such tests do exist in the ctest-framework, they often involve more boiler-plate code).
12+
It is also useful for testing problems that do have analytic solutions (the answer test might quantify how close a simulation result is to the analytic expected solution).
13+
While such tests do exist in the ctest-framework, they often involve more boiler-plate code.
1414

1515
`pytest <https://docs.pytest.org/>`__ is a Python-based framework for detecting
1616
and running a series of tests within a source code repository. When running
@@ -44,7 +44,7 @@ other useful answer testing functionality are located in the source in
4444
`test/answer_tests/answer_testing.py`. All answer tests are located in the
4545
other files within the `test/answer_tests` directory.
4646

47-
Some other functionality, that may be reused in other unrelated scripts provided in the Enzo-E repository, is provided in the ``test_utils`` subdirectory.
47+
Some other functionality, that may be reused in other unrelated scripts provided in the Enzo-E repository, are provided in the ``test_utils`` subdirectory.
4848

4949
Running the Answer Test Suite
5050
-----------------------------
@@ -91,7 +91,7 @@ In cases where both are set, the command line argument is given precedence.
9191
- points to the build-directory where the target enzo-e binary was built (that binary has the path: BUILD_DIR/bin/enzo-e).
9292
The path to the charmrun launcher will be inferred from the `BUILD_DIR/CMakeCache.txt` file, but can be overwritten by the ``--charm`` flag or the ``CHARM_PATH`` environment variable.
9393
This precedence was chosen in case a user causes a change to relevant cached build-variables, but have not rebuilt Enzo-E (i.e. `CMakeCache.txt` may not be valid for the binary).
94-
When this flag isn't specified, the test infrastructure searches for the enzo-e binary at ENZOE_ROOT/build/bin/enzo-e, but does'nt try to infer charmrun's location from `CMakeCache.txt`.
94+
When this flag isn't specified, the test infrastructure searches for the enzo-e binary at ENZOE_ROOT/build/bin/enzo-e, but doesn't try to infer charmrun's location from `CMakeCache.txt`.
9595
* - ``--local-dir``
9696
- ``TEST_RESULTS_DIR``
9797
- points to a directory in which answers will be stored/loaded
@@ -121,7 +121,8 @@ First, check out the highest numbered gold standard tag and compile ``enzo-e``.
121121

122122
.. code-block:: bash
123123
124-
$ git checkout gold-standard-1
124+
# in the future, you will need to subsitute 004 for a higher number
125+
$ git checkout gold-standard-004
125126
$ ...compile enzo-e
126127
127128
Then, run the test suite by calling ``pytest`` with the answer test directory (make sure to configure behavior correctly with command-line arguments or environment variables).

doc/source/tutorial/getting_started.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ These options control compilation choices that can be used to facillitate profil
284284
Testing Options
285285
^^^^^^^^^^^^^^^
286286

287-
These options configure properties of parallel automated tests.
287+
These options configure properties of automated tests. These options currently just affect tests in the :ref:`ctest framework <ctest>` and don't affect tests in the :ref:`pytest framework <pytest>`.
288288

289289
.. list-table:: Testing-Related Configuration
290290
:widths: 10 30 5
@@ -302,6 +302,10 @@ These options configure properties of parallel automated tests.
302302
* - ``PARALLEL_LAUNCHER_NPROC``
303303
- Number of processors to run parallel unit tests
304304
- 4
305+
* - ``BUILD_TESTING``
306+
- Whether to setup the CTest infrastructure and build unit test binaries (which are primarily built to be executed by the CTest infrastructure). This has no effect on the pytest infrastructure.
307+
- "ON"
308+
305309

306310
Debugging Options
307311
^^^^^^^^^^^^^^^^^

src/Cello/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,13 @@ function(addUnitTestBinary BINNAME SRCS LIB TESTER)
338338
# TESTER: Tester target library (usually, this is tester_default,
339339
# tester_mesh, OR tester_simulation)
340340

341-
add_executable(${BINNAME} ${SRCS})
342-
target_link_libraries(${BINNAME} PUBLIC ${LIB} ${TESTER})
343-
target_link_options(${BINNAME} PRIVATE ${Cello_TARGET_LINK_OPTIONS})
341+
if (BUILD_TESTING)
342+
# only declare the binary for a unit-test when BUILD_TESTING is ON (the
343+
# default case)
344+
add_executable(${BINNAME} ${SRCS})
345+
target_link_libraries(${BINNAME} PUBLIC ${LIB} ${TESTER})
346+
target_link_options(${BINNAME} PRIVATE ${Cello_TARGET_LINK_OPTIONS})
347+
endif()
344348
endfunction(addUnitTestBinary)
345349

346350
# tests of the cello-component

src/Cello/view_ViewCollec.hpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,23 @@ class ViewCollec{
229229
// used in destructor and to help switch the active member of the enum
230230
// need to explicitly call destructor because we use placement new
231231
void dealloc_active_member_() noexcept{
232-
// note, we need to use the full qualified names of destructors to avoid
233-
// errors with the nvidia compiler
232+
// Note: we need to use the full qualified names of destructors to avoid
233+
// errors with the nvidia compiler
234+
// Note: Subsequently, we ran into problems with how clang 10.0 requires us
235+
// to specify the destructor. I had to mutate this again to get it to
236+
// work with clang and g++. I'm not sure if I broke compatability
237+
// with nvcc (I suspect that it may still work).
238+
// Going forward, the most obvious solution for getting this to work is to
239+
// use C++17's std::variant
240+
234241
switch (tag_){
235242
case Tag::CONTIG: {
236-
single_arr_.detail::SingleAddressViewCollec_<T>::~SingleAddressViewCollec_();
237-
break;
243+
using ContigCollec = typename detail::SingleAddressViewCollec_<T>;
244+
single_arr_.~ContigCollec(); break;
238245
}
239246
case Tag::ARR_OF_PTR: {
240-
arr_of_ptr_.detail::ArrOfPtrsViewCollec_<T>::~ArrOfPtrsViewCollec_();
241-
break;
247+
using ArrOfPtr = typename detail::ArrOfPtrsViewCollec_<T>;
248+
arr_of_ptr_.~ArrOfPtr(); break;
242249
}
243250
}
244251
}

src/Enzo/CMakeLists.txt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@ add_subdirectory(io)
8989
add_subdirectory(mesh)
9090
add_subdirectory(obsolete)
9191
add_subdirectory(particle)
92-
add_subdirectory(tests)
9392
add_subdirectory(utils)
9493

94+
# note that the tests subdirectory introduces problem initializers that can
95+
# be used to setup test-problems. The BUILD_TESTING option has no impact on
96+
# what is built from this directory (it only affects whether binaries,
97+
# expressly used for unit-testing are built)
98+
add_subdirectory(tests)
99+
95100
# Step 4: specify additional information about the Enzo library
96101
# (dependencies are only PUBLIC because of the way that all headers are
97102
# transitively included in all targets. If they weren't public, the include
@@ -116,12 +121,14 @@ add_executable(enzo-e enzo-e.cpp)
116121
target_link_libraries(enzo-e PRIVATE enzo main_enzo ${External_LIBS})
117122
target_link_options(enzo-e PRIVATE ${Cello_TARGET_LINK_OPTIONS})
118123

119-
# define a unit test:
120-
#
121-
# consider removing the enzo-specific stuff from this test so that we can
122-
# define it entirely in the Cello layer
123-
add_executable(
124-
test_class_size "${CMAKE_CURRENT_SOURCE_DIR}/../Cello/test_class_size.cpp"
125-
)
126-
target_link_libraries(test_class_size PRIVATE enzo mesh tester_mesh)
127-
target_link_options(test_class_size PRIVATE ${Cello_TARGET_LINK_OPTIONS})
124+
if (BUILD_TESTING)
125+
# define a unit test:
126+
#
127+
# consider removing the enzo-specific stuff from this test so that we can
128+
# define it entirely in the Cello layer
129+
add_executable(
130+
test_class_size "${CMAKE_CURRENT_SOURCE_DIR}/../Cello/test_class_size.cpp"
131+
)
132+
target_link_libraries(test_class_size PRIVATE enzo mesh tester_mesh)
133+
target_link_options(test_class_size PRIVATE ${Cello_TARGET_LINK_OPTIONS})
134+
endif()

src/Enzo/enzo-core/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ list(FILTER LOCAL_SRC_FILES EXCLUDE REGEX "test_EnzoUnits")
2626

2727
target_sources(enzo PRIVATE ${LOCAL_SRC_FILES})
2828

29-
# Add a unit test
30-
add_executable(test_enzo_units "test_EnzoUnits.cpp")
31-
target_link_libraries(test_enzo_units PRIVATE enzo main_enzo)
32-
target_link_options(test_enzo_units PRIVATE ${Cello_TARGET_LINK_OPTIONS})
29+
if (BUILD_TESTING)
30+
# Add a unit test
31+
add_executable(test_enzo_units "test_EnzoUnits.cpp")
32+
target_link_libraries(test_enzo_units PRIVATE enzo main_enzo)
33+
target_link_options(test_enzo_units PRIVATE ${Cello_TARGET_LINK_OPTIONS})
34+
endif()

src/Enzo/hydro-mhd/SolveHydroEquations.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,20 @@ int EnzoBlock::SolveHydroEquations
144144

145145
if (density_floor > 0.0) {
146146
for (int i=0; i<mx*my*mz; i++) {
147-
density[i] = std::max(density[i], density_floor);
147+
148+
if (density[i] < density_floor) {
149+
double d_pre = density[i];
150+
density[i] = density_floor;
151+
double density_ratio = density[i] / d_pre;
152+
153+
// rescale color fields to account for change in
154+
// baryon mass from enforcing density floor
155+
for (int ic = 0; ic < ncolor; ic++){
156+
enzo_float * cfield = (enzo_float *)
157+
field.values(field.groups()->item("color",ic));
158+
cfield[i] *= density_ratio;
159+
}
160+
}
148161
}
149162
}
150163

0 commit comments

Comments
 (0)