Skip to content

Commit 669db26

Browse files
committed
Merge branch 'development' into tk/onnx-benchmark
2 parents bf03a19 + 7bbd786 commit 669db26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1884
-475
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ jobs:
124124
# Fix bug in FFT3 (cf. https://github.com/FFTW/fftw3/issues/332)
125125
sed -i -e 's/^.*FFTW3LibraryDepends.cmake.*$//1' ${{github.workspace}}/local/lib*/cmake/*/FFTW3Config.cmake
126126
127+
- name: Install HDF5
128+
run: |
129+
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.3/src/hdf5-1.14.3.tar.gz -O- | tar --no-same-owner -xz;
130+
cd hdf5-1.14.3/
131+
mkdir build && cd build
132+
#CC=`which mpicc` CXX=`which mpicxx` ./configure --prefix=${{github.workspace}}/local --enable-parallel --enable-shared --enable-cxx
133+
CC=`which mpicc` CXX=`which mpicxx` cmake .. -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -DHDF5_ENABLE_PARALLEL:BOOL=ON -DALLOW_UNSUPPORTED:BOOL=ON -DHDF5_BUILD_FORTRAN:BOOL=OFF -DHDF5_BUILD_CPP_LIB:BOOL=ON -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF
134+
make -j2 install
135+
127136
- name: Checkout SOPT
128137
uses: actions/checkout@v4
129138
with:
@@ -214,9 +223,10 @@ jobs:
214223
# Build your program with the given configuration
215224
run: |
216225
export CMAKE_PREFIX_PATH=${{github.workspace}}/local:$CMAKE_PREFIX_PATH
226+
#export PATH=${{github.workspace}}/local:$PATH
217227
mkdir -p ${{github.workspace}}/build
218228
cd ${{github.workspace}}/build
219-
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Donnxrt=ON -Ddocasa=OFF -Ddompi=${{matrix.mpi}} -Dopenmp=${{matrix.omp}} -Dtests=ON
229+
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Donnxrt=ON -Dhdf5=ON -Ddocasa=OFF -Ddompi=${{matrix.mpi}} -Dopenmp=${{matrix.omp}} -Dtests=ON
220230
make -j$(nproc --ignore 1) install
221231
222232
- name: Test
@@ -278,7 +288,7 @@ jobs:
278288
export CMAKE_PREFIX_PATH=${{github.workspace}}/local:$CMAKE_PREFIX_PATH
279289
mkdir -p ${{github.workspace}}/build
280290
cd ${{github.workspace}}/build
281-
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Donnxrt=ON -Ddompi=OFF -Dopenmp=OFF -Ddocs=ON
291+
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Donnxrt=ON -Dhdf5=ON -Ddompi=OFF -Dopenmp=OFF -Ddocs=ON
282292
make -j$(nproc --ignore 1) install
283293
284294
- name: Deploy to GH pages

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ option(docasa "Enable CASA" off)
1616
option(docs "Build documentation" off)
1717
option(coverage "Build coverage" off)
1818
option(onnxrt "Build with ONNXruntime interface" off)
19+
option(hdf5 "Build with HDF5 interface" off)
1920

2021
if(NOT CMAKE_BUILD_TYPE)
2122
message(STATUS "Setting build type to 'Release' as none was specified.")

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,34 @@ When `purify` runs a directory will be created, and the output images will be
9191
saved and time-stamped. Additionally, a config file with the settings used will
9292
be saved and time-stamped, helping for reproducibility and book-keeping.
9393

94+
Uncertainty Quantification
95+
--------------------------
96+
97+
Bayesian hypothesis testing may be performed with the `purify_UQ` application, which can be located in the `build` directory.
98+
99+
This application takes a config yaml file with the following parameters:
100+
- `confidence_interval` or `alpha`. (alpha = 1 - confidence interval.))
101+
- `measurements_path`: path to measurements data (.vis file)
102+
- `reference_image_path`: path to reference image i.e. output from purify run. (.fits files)
103+
- `surrogate_image_path`: path to surrogate image i.e. doctored image with blurring or structural change that you want to test. (.fits file)
104+
- `sigma`: standard deviation for Gaussian likelihood.
105+
- `gamma`: multiplicative factor for prior.
106+
- `purify_config`: path to purify config used to generate the reference image. **This should be used if available in order to ensure consistency of things like measurement and wavelet operators.**
107+
108+
You can then run the uncertainty quantification with the command:
109+
```
110+
purify_UQ <path to UQ_config yaml>
111+
```
112+
113+
The application will report the value of the objective function for each image, the threshold value calculated from the reference image, and whether the surrogate image is ruled out or not.
114+
115+
Presently this is designed to work for the unconstrained problem where:
116+
- The negative log-likelihood is a scaled L2-norm i.e. $ \frac{1}{2 \sigma^2} \sum (y_i - \Phi x_i)$ for some data $y$, image $x$, and measurement operator $\Phi$. (Equivalent to indepdendent multivariate Gaussian likelihood.)
117+
- The negative log prior is a scaled L1-norm in _wavelet space_ i.e. $\gamma \sum (\Psi^\dag x)_i$ for some image $x$ and wavelet operator $\Psi$.
118+
- The objective function is the sum of these two terms.
119+
120+
Docker
121+
-------
94122
## Debugging the CI workflow with tmate
95123

96124
The CI workflow has a manual dispatch trigger which allows you to log into the job while it's running. You can trigger it in

cmake_files/LookUpHighFive.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Installs BlueBrain/HighFive into build directory
2+
#
3+
# - GIT_REPOSITORY: defaults to origin BlueBrain/HighFive repo on github
4+
# - GIT_TAG: defaults to master
5+
include(ExternalProject)
6+
if(HighFive_ARGUMENTS)
7+
cmake_parse_arguments(HighFive "" "GIT_REPOSITORY;GIT_TAG" ""
8+
${HighFive_ARGUMENTS})
9+
endif()
10+
if(NOT HighFive_GIT_REPOSITORY)
11+
set(HighFive_GIT_REPOSITORY https://github.com/BlueBrain/HighFive)
12+
endif()
13+
if(NOT HighFive_GIT_TAG)
14+
set(HighFive_GIT_TAG master)
15+
endif()
16+
17+
set(HighFive_DIR "${CMAKE_INSTALL_PREFIX}/external")
18+
ExternalProject_Add(
19+
Lookup-HighFive
20+
GIT_REPOSITORY ${HighFive_GIT_REPOSITORY}
21+
GIT_TAG ${HighFive_GIT_TAG}
22+
PREFIX "${CMAKE_BINARY_DIR}/external"
23+
#INSTALL_DIR ${EXTERNAL_ROOT}
24+
CMAKE_ARGS
25+
-DCMAKE_INSTALL_PREFIX=${HighFive_DIR}
26+
-DCMAKE_INSTALL_LIBDIR=${CMAKE_SHARED_LIBRARY_PREFIX}
27+
-DHIGHFIVE_EXAMPLES=OFF
28+
-DHIGHFIVE_USE_BOOST=OFF
29+
-DHIGHFIVE_UNIT_TESTS=OFF
30+
# Wrap download, configure and build steps in a script to log output
31+
UPDATE_COMMAND ""
32+
LOG_DOWNLOAD ON
33+
LOG_CONFIGURE ON
34+
LOG_BUILD ON
35+
LOG_INSTALL ON
36+
)
37+
set(HighFive_INCLUDE_DIR "${HighFive_DIR}/include")
38+
#set(HighFive_LIBRARY_DIR "${HighFive_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}")
39+
#set(HighFive_LIBRARIES "HighFive")
40+

cmake_files/dependencies.cmake

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ find_package(fftw3 NAMES FFTW3 REQUIRED)
9292
set(PURIFY_MPI FALSE)
9393
if(dompi)
9494
find_package(MPI REQUIRED)
95-
set(PURIFY_MPI TRUE)
95+
if (${sopt_HAS_MPI})
96+
set(PURIFY_MPI TRUE)
97+
else()
98+
message(FATAL_ERROR "SOPT built without MPI support")
99+
endif()
96100
endif()
97101
find_package(TIFF REQUIRED)
98102

@@ -120,5 +124,23 @@ if(docasa)
120124
set(PURIFY_CASACORE TRUE)
121125
endif()
122126

127+
set(PURIFY_H5 FALSE)
128+
if(hdf5)
129+
find_package(HDF5 COMPONENTS CXX REQUIRED)
130+
message(STATUS "Found HDF5 include dir: ${HDF5_INCLUDE_DIR}")
131+
message(STATUS "Found HDF5 CXX library: ${HDF5_CXX_LIBRARIES}")
132+
message(STATUS "HDF5 parallel: ${HDF5_IS_PARALLEL}")
133+
if (PURIFY_MPI AND NOT ${HDF5_IS_PARALLEL})
134+
message(FATAL_ERROR "HDF5 built without MPI support")
135+
endif()
136+
find_package(HighFive QUIET)
137+
if(NOT HighFive_FOUND)
138+
message(STATUS "HighFive not found. Attempt to install...")
139+
include(LookUpHighFive)
140+
set(PURIFY_HIGHFIVE_LOOKUP TRUE)
141+
endif()
142+
set(PURIFY_H5 TRUE)
143+
endif()
144+
123145
# Add script to execute to make sure libraries in the build tree can be found
124146
add_to_ld_path("${EXTERNAL_ROOT}/lib")

cpp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ add_include_dir(
2323
${yaml-cpp_INCLUDE_DIR}
2424
${Cubature_INCLUDE_DIR}
2525
${CImg_INCLUDE_DIR}
26+
${HDF5_INCLUDE_DIR}
27+
${HighFive_INCLUDE_DIR}
2628
)
2729

2830

@@ -45,6 +47,8 @@ if (docs)
4547
add_subdirectory(docs)
4648
endif()
4749

50+
add_subdirectory(uncertainty_quantification)
51+
4852
add_executable(purify main.cc)
4953
set_target_properties(purify PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
5054
target_link_libraries(purify libpurify ${sopt_LIBRARIES})

cpp/benchmarks/algorithms.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ BENCHMARK_DEFINE_F(AlgoFixture, ForwardBackwardOnnx)(benchmark::State &state) {
115115
m_fb = factory::fb_factory<sopt::algorithm::ImagingForwardBackward<t_complex>>(
116116
factory::algo_distribution::serial, m_measurements_transform, wavelets, m_uv_data, m_sigma,
117117
beta, gamma, m_imsizey, m_imsizex, m_sara.size(), state.range(3) + 1, true, true, false, 1e-3,
118-
1e-2, 50, 1.0, tf_model_path, factory::g_proximal_type::TFGProximal);
118+
1e-2, 50, 1.0, tf_model_path, nondiff_func_type::Denoiser);
119119

120120
while (state.KeepRunning()) {
121121
auto start = std::chrono::high_resolution_clock::now();

cpp/benchmarks/algorithms_mpi.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ BENCHMARK_DEFINE_F(AlgoFixtureMPI, FbOnnxDistributeImage)(benchmark::State &stat
188188
m_fb = factory::fb_factory<sopt::algorithm::ImagingForwardBackward<t_complex>>(
189189
factory::algo_distribution::mpi_serial, m_measurements_distribute_image, wavelets, m_uv_data,
190190
m_sigma, beta, gamma, m_imsizey, m_imsizex, m_sara.size(), state.range(3), true, true,
191-
false, 1e-3, 1e-2, 50, 1.0, tf_model_path, factory::g_proximal_type::TFGProximal);
191+
false, 1e-3, 1e-2, 50, 1.0, tf_model_path, nondiff_func_type::Denoiser);
192192

193193
// Benchmark the application of the algorithm
194194
while (state.KeepRunning()) {

0 commit comments

Comments
 (0)