Skip to content

Commit dae0d3d

Browse files
authored
Merge pull request #169 from Computer-Aided-Validation-Laboratory/dev
QOL and bugfixes following 2D DIC workshop
2 parents 5de7fa4 + 871e926 commit dae0d3d

35 files changed

Lines changed: 816 additions & 263 deletions

.github/workflows/install_and_lint.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41-
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-13, macos-14]
41+
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
4242

4343
steps:
4444
- uses: actions/checkout@v3
@@ -66,6 +66,14 @@ jobs:
6666
echo "LDFLAGS=-L$(brew --prefix libomp)/lib" >> $GITHUB_ENV
6767
echo "CPPFLAGS=-I$(brew --prefix libomp)/include" >> $GITHUB_ENV
6868
69+
- name: Install dependencies for ubuntu-latest
70+
if: matrix.os == 'ubuntu-latest'
71+
run: |
72+
sudo apt update
73+
sudo apt install libegl1
74+
sudo apt install libgl1 libxext6 libx11-6
75+
76+
6977
- name: Test package installation
7078
run: |
7179
python -m pip install --upgrade pip

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
project = 'Pyvale'
1919
copyright = '2025, The CAV Team'
2020
author = 'The CAV Team at United Kingdom Atomic Energy Authority (UKAEA)'
21-
release = '2025.5.3'
22-
version = '2025.5.3'
21+
release = '2025.7.2'
22+
version = '2025.7.2'
2323

2424
# -- General configuration ---------------------------------------------------
2525
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "pyvale"
8-
version = "2025.7.1"
8+
version = "2025.7.2"
99
description = "An all-in-one package for sensor simulation, sensor uncertainty quantification, sensor placement optimisation and simulation calibration or validation."
1010
authors = [
1111
{ name = "scepticalrabbit et al.", email = "thescepticalrabbit@gmail.com" },

src/pyvale/dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def dic_challenge_ref() -> Path:
397397
Path to the reference image (*.tiff).
398398
"""
399399
return Path(files("pyvale.data")
400-
.joinpath("DIC_Challenge_Star_Noise_Ref.tif"))
400+
.joinpath("DIC_Challenge_Star_Noise_Ref.tiff"))
401401

402402
@staticmethod
403403
def dic_challenge_def() -> Path:
@@ -409,7 +409,7 @@ def dic_challenge_def() -> Path:
409409
Path to the reference image (*.tiff).
410410
"""
411411
return Path(files("pyvale.data")
412-
.joinpath("DIC_Challenge_Star_Noise_Def.tif"))
412+
.joinpath("DIC_Challenge_Star_Noise_Def.tiff"))
413413

414414

415415

src/pyvale/dic/cpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ file(GLOB DIC_SRC_FILES dic*.cpp)
1414
pybind11_add_module(dic2dcpp MODULE ${DIC_SRC_FILES})
1515
target_link_libraries(dic2dcpp PRIVATE ${FFTW_LIBRARIES} OpenMP::OpenMP_CXX)
1616

17+
# Add -O3 optimization
18+
target_compile_options(dic2dcpp PRIVATE -O3)

src/pyvale/dic/cpp/defines.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
// ================================================================================
2+
// pyvale: the python validation engine
3+
// License: MIT
4+
// Copyright (C) 2025 The Computer Aided Validation Team
5+
// ================================================================================
6+
7+
// defines.hpp
8+
#ifndef DEFINES_H
9+
#define DEFINES_H
10+
111
#define TITLE(a) std::cout << std::string(80, '-') << std::endl; std::cout << std::string(38 - std::strlen(a)/2, '-') << " " << a << " " << std::string(38 - std::strlen(a)/2, '-') << std::endl; std::cout << std::string(80, '-') << std::endl;
212
#define INFO_OUT(a,b) std::cout << " - " << std::left << std::setw(50) << a << b << std::endl;
313
#define DEBUGGER std::cout << __FILE__ << " " << __LINE__ << std::endl;
14+
415
#ifdef CUDA
516
#define CUDA_CALL(x) do { if((x) != cudaSuccess) {\
617
printf("Error at %s:%d\n",__FILE__,__LINE__);\
@@ -10,3 +21,19 @@
1021
printf("Error at %s:%d\n",__FILE__,__LINE__);\
1122
exit(EXIT_FAILURE);}} while(0)
1223
#endif
24+
25+
// Use static function approach instead of inline variable
26+
inline int& get_debug_level() {
27+
static int level = 0;
28+
return level;
29+
}
30+
31+
inline int& g_debug_level = get_debug_level();
32+
#define DEBUG_PROGRESS_BAR(level) \
33+
if (g_debug_level >= level)
34+
#define DEBUG(level) \
35+
if (g_debug_level >= level)
36+
37+
#endif // DEFINES_HPP
38+
39+

src/pyvale/dic/cpp/dicfourier.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#include <cmath>
1313
#include <algorithm>
1414
#include <omp.h>
15+
#include <csignal>
1516

1617
// Program Header files
1718
#include "./defines.hpp"
1819
#include "./dicutil.hpp"
1920
#include "./dicfourier.hpp"
21+
#include "./dicsignalhandler.hpp"
2022

2123
namespace fourier {
2224

@@ -134,8 +136,10 @@ namespace fourier {
134136
}
135137

136138
void mgwd(const std::vector<util::SubsetData> &ssdata,
137-
const double *img_ref, const double *img_def,
138-
const Interpolator &interp_def, const bool fft_mad,
139+
const double *img_ref,
140+
const double *img_def,
141+
const Interpolator &interp_def,
142+
const bool fft_mad,
139143
const double fft_mad_scale){
140144

141145
const int px_hori = interp_def.px_hori;
@@ -150,11 +154,21 @@ namespace fourier {
150154
//util::Timer timer("FFT windowing for subset size: " + std::to_string(ssdata[i].size));
151155

152156
const int ss_size = ssdata[i].size;
157+
const int num_ss = ssdata[i].num;
153158

154159
std::fill(shifts[i].x.begin(), shifts[i].x.end(), 0.0);
155160
std::fill(shifts[i].y.begin(), shifts[i].y.end(), 0.0);
156161

157-
#pragma omp parallel
162+
indicators::ProgressBar bar;
163+
std::atomic<int> current_progress = 0;
164+
int prev_pct = 0;
165+
166+
if (g_debug_level == 1){
167+
std::string bar_title = "FFT windowing for size: " + std::to_string(ss_size);
168+
util::create_progress_bar(bar, bar_title, ssdata[i].num);
169+
}
170+
171+
#pragma omp parallel shared(stop_request)
158172
{
159173

160174

@@ -165,6 +179,11 @@ namespace fourier {
165179
#pragma omp for
166180
for (int ss = 0; ss < ssdata[i].num; ss++){
167181

182+
// exit when ctrl+C
183+
if (stop_request){
184+
continue;
185+
}
186+
168187
int ss_x = ssdata[i].coords[2*ss];
169188
int ss_y = ssdata[i].coords[2*ss+1];
170189

@@ -213,6 +232,12 @@ namespace fourier {
213232
//util::extract_ss_subpx(fft.ss_def, ss_x+shifts[i].x[ss], ss_y+shifts[i].y[ss], interp_def);
214233
//shifts[i].cost[ss] = debugcost(fft.ss_ref,fft.ss_def);
215234
shifts[i].max_val[ss] = max_val;
235+
236+
237+
if (g_debug_level == 1){
238+
int progress = current_progress.fetch_add(1);
239+
if (omp_get_thread_num()==0) util::update_progress_bar(bar, progress, num_ss, prev_pct);
240+
}
216241
}
217242
}
218243

@@ -222,7 +247,6 @@ namespace fourier {
222247
remove_outliers(shifts[i].y, ssdata[i], fft_mad);
223248
}
224249

225-
226250
//smooth_field(shifts[i].x, ssdata[i], 7.0, 5);
227251
//smooth_field(shifts[i].y, ssdata[i], 7.0, 5);
228252

@@ -233,9 +257,17 @@ namespace fourier {
233257
// std::cout << shifts[i].cost[ss] << std::endl;
234258
//}
235259
//std::cout << std::endl;
260+
261+
if (g_debug_level == 1){
262+
int progress = current_progress;
263+
util::update_progress_bar(bar, progress-1, num_ss, prev_pct);
264+
bar.mark_as_completed();
265+
indicators::show_console_cursor(true);
266+
}
236267
}
237268

238269

270+
239271
}
240272

241273

src/pyvale/dic/cpp/dicinterpolator.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
// Program Header files
1313
#include "./dicinterpolator.hpp"
14-
14+
#include "./dicutil.hpp"
15+
#include "defines.hpp"
16+
#include "./dicsignalhandler.hpp"
1517

1618

1719
inline int idx_from_2d(const int x, const int y, const int length){
@@ -49,10 +51,27 @@ Interpolator::Interpolator(double*img, int px_hori, int px_vert){
4951

5052
//interpolator data
5153
std::vector<double> data(px_hori,0);
54+
55+
56+
indicators::ProgressBar bar;
57+
std::atomic<int> current_progress = 0;
58+
int prev_pct = 0;
59+
int niters = px_vert+px_hori+px_hori;
60+
61+
if (g_debug_level == 1){
62+
std::string bar_title = "Creating Interpolator: ";
63+
util::create_progress_bar(bar, bar_title, niters);
64+
}
65+
5266

5367
//#pragma omp parallel for
5468
for (int j = 0; j < px_vert; j++){
5569

70+
// exit if ctrl+C
71+
if (stop_request){
72+
continue;
73+
}
74+
5675
// get 1D data
5776
for (int i = 0; i < px_hori; i++) {
5877
data[i] = image[j*px_hori + i];
@@ -62,13 +81,24 @@ Interpolator::Interpolator(double*img, int px_hori, int px_vert){
6281
for (int i = 0; i < px_hori; i++){
6382
dx[j*px_hori + i] = cspline_eval_deriv(px_x, data, px_x[i], px_hori);
6483
}
84+
85+
// update progress bar if enabled
86+
if (g_debug_level == 1){
87+
int progress = current_progress.fetch_add(1);
88+
util::update_progress_bar(bar, progress, niters, prev_pct);
89+
}
6590
}
6691

6792
data.resize(px_vert,0);
6893

6994
//#pragma omp parallel for
7095
for (int i = 0; i < px_hori; ++i) {
7196

97+
// exit if ctrl+C
98+
if (stop_request){
99+
continue;
100+
}
101+
72102
// get 1D data
73103
for (int j = 0; j < px_vert; j++){
74104
data[j] = image[j*px_hori + i];
@@ -78,6 +108,12 @@ Interpolator::Interpolator(double*img, int px_hori, int px_vert){
78108
for (int j = 0; j < px_vert; j++){
79109
dy[j*px_hori + i] = cspline_eval_deriv(px_y, data, px_y[j], px_vert);
80110
}
111+
112+
// update progress bar if enabled
113+
if (g_debug_level == 1){
114+
int progress = current_progress.fetch_add(1);
115+
util::update_progress_bar(bar, progress, niters, prev_pct);
116+
}
81117
}
82118

83119

@@ -86,6 +122,11 @@ Interpolator::Interpolator(double*img, int px_hori, int px_vert){
86122
//#pragma omp parallel for
87123
for (int j = 0; j < px_vert; j++){
88124

125+
// exit if ctrl+C
126+
if (stop_request){
127+
continue;
128+
}
129+
89130
// get 1D data
90131
for (int i = 0; i < px_hori; i++) {
91132
data[i] = dy[j*px_hori + i];
@@ -95,6 +136,20 @@ Interpolator::Interpolator(double*img, int px_hori, int px_vert){
95136
for (int i = 0; i < px_hori; i++){
96137
dxy[j*px_hori + i] = cspline_eval_deriv(px_x, data, px_x[i], px_hori);
97138
}
139+
140+
// update progress bar if enabled
141+
if (g_debug_level == 1){
142+
int progress = current_progress.fetch_add(1);
143+
util::update_progress_bar(bar, progress, niters, prev_pct);
144+
}
145+
}
146+
147+
148+
if (g_debug_level == 1){
149+
int progress = current_progress;
150+
util::update_progress_bar(bar, progress-1, niters, prev_pct);
151+
bar.mark_as_completed();
152+
indicators::show_console_cursor(true);
98153
}
99154
}
100155

0 commit comments

Comments
 (0)