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

Modifications for psmr2024 #1430

Open
wants to merge 83 commits into
base: master
Choose a base branch
from
Open

Modifications for psmr2024 #1430

wants to merge 83 commits into from

Conversation

NikEfth
Copy link
Collaborator

@NikEfth NikEfth commented May 15, 2024

Changes in this pull request

Testing performed

Related issues

Checklist before requesting a review

  • [] I have performed a self-review of my code
  • [] I have added docstrings/doxygen in line with the guidance in the developer guide
  • [] I have implemented unit tests that cover any new or modified functionality (if applicable)
  • [] The code builds and runs on my machine
  • [] documentation/release_XXX.md has been updated with any functionality change (if applicable)

A single TOF scanner can be used in the calculation of the sensitivity
image, while applying the boundaries of the coincidence window.
* Building upon the cached lm reconstruction, we further parallelize the
calculation of the sensitity image to muliple passes when the scanner is
long.

* Now, a scanner is TOF ready even if it does not have set timing
resolution. If the timing resolution is 0 ps or if the TOF mashing leads
to a scanner with 1 TOF bin then we apply boundaries on the LOR's
length, equal to the coinc window. The probabilities do not change as we
set them to 1.

* cxx17 is nessesary for newer ROOT.
@NikEfth
Copy link
Collaborator Author

NikEfth commented May 15, 2024

If this commit breaks many tests, I would consider it expected.

src/buildblock/ProjDataInfo.cxx Outdated Show resolved Hide resolved
src/IO/InterfileHeader.cxx Show resolved Hide resolved

//! Similar to create_non_tof_clone() but returns a single TOF version of the ProjDataInfo setting the TOF mashing factor sush that,
//! a single TOF bin remains. This is usefull to apply the coincidence window boundaries without affecting the probabilities.
inline shared_ptr<ProjDataInfo> create_single_tof_clone() const;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we need this for backwards compatibility? i.e. need to keep create_non_tof_clone unmodified? If so, I'd be tempted to add a bool to create_non_tof_clone() instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: will be obsolete once we merge another PR on SSRB for TOF

src/include/stir/ProjDataInfo.inl Outdated Show resolved Hide resolved
src/include/stir/Scanner.h Outdated Show resolved Hide resolved
info(boost::format("Calculating sensitivity for subset %1%") % subset_num);

int min_timing_pos_num = use_tofsens ? this->proj_data_info_sptr->get_min_tof_pos_num() : 0;
int max_timing_pos_num = use_tofsens ? this->proj_data_info_sptr->get_max_tof_pos_num() : 0;
if (min_timing_pos_num < 0 || max_timing_pos_num > 0)
if (min_timing_pos_num < 0 || max_timing_pos_num > 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (min_timing_pos_num < 0 || max_timing_pos_num > 1)
if (min_timing_pos_num < 0 || max_timing_pos_num > 0)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is correct. Up to one TOF bin should not be considered TOF reconstruction.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not with you on this one (i.e. with the 1). Why not say num_timing_poss > 1

src/recon_buildblock/ProjMatrixByBin.cxx Outdated Show resolved Hide resolved
@KrisThielemans
Copy link
Collaborator

tests fail with

ERROR: Non-TOF data with inconsistent Time-of-Flight bin number - Aborted operation.

@NikEfth
Copy link
Collaborator Author

NikEfth commented May 16, 2024

We can turn this to a warning, for now.
Or, drop the old nonTOF altogether. But it will break people reading old headers.

Copy link
Collaborator

@KrisThielemans KrisThielemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments. Please merge master as CI is currently not running due to a conflict.

src/IO/InterfileHeader.cxx Outdated Show resolved Hide resolved
Comment on lines 86 to 91
\li \c If the user set number for TOF positions to 1 and a bin size equal to the
coincidence window then the reconstruction will essential be nonTOF but the
projector will restrict the size of the LOR to the size of the coincidence window.
\li \c The scanner will be classified as TOF enabled when the numer of TOF bins and
TOF bin size are >1 and >0, respectively. If the energy resolution is not set that will be fine
as long as the final TOF possitions is 1. Then we just restict the size of the LOR.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\li \c If the user set number for TOF positions to 1 and a bin size equal to the
coincidence window then the reconstruction will essential be nonTOF but the
projector will restrict the size of the LOR to the size of the coincidence window.
\li \c The scanner will be classified as TOF enabled when the numer of TOF bins and
TOF bin size are >1 and >0, respectively. If the energy resolution is not set that will be fine
as long as the final TOF possitions is 1. Then we just restict the size of the LOR.
\li \c The scanner will be classified as TOF enabled when the number of TOF bins and
TOF bin size are >1 and >0, respectively.
\li \c If the user sets the number for TOF positions to 1, the TOF bin size should correspond to the size of the coincidence window. If the TOF timing resolution is zero, then the reconstruction will essentially be nonTOF but the
projector will restrict the length of the LOR according to the TOF bin width.

info(boost::format("Calculating sensitivity for subset %1%") % subset_num);

int min_timing_pos_num = use_tofsens ? this->proj_data_info_sptr->get_min_tof_pos_num() : 0;
int max_timing_pos_num = use_tofsens ? this->proj_data_info_sptr->get_max_tof_pos_num() : 0;
if (min_timing_pos_num < 0 || max_timing_pos_num > 0)
if (min_timing_pos_num < 0 || max_timing_pos_num > 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not with you on this one (i.e. with the 1). Why not say num_timing_poss > 1

CMakeLists.txt Outdated Show resolved Hide resolved
@NikEfth
Copy link
Collaborator Author

NikEfth commented May 16, 2024

A few more comments. Please merge master as CI is currently not running due to a conflict.

I hadn't noticed that ...

This will allow implementation specific tests for a particular prior.
- we were using abs() which (at least on some systems) converted to
  integers, giving the wrong result. now using std::abs()
- introduce value/derivative_10 function for more concise code
now use INFINITY for second order derivatives, obtained by
continuity
split the tests for the different priors in different classes, such
that we can have specific tests for each. Currently, only added some for the RDP,
including a Lipschitz test and limit for large values.
The RDP test was failing with eps=1.e-3, so now using 1.e-4
use double in neighbourhood calculations
previous version failed on macos-14-arm64.
We have a very fragile list of checks. Presumably, CMake does a lot better,
so use CMAKE_CXX_BYTE_ORDER in ByteOrderDefine (via config.h)
run clang-format on Ubuntu on ByteOrderDefine.h. Apparently, there
was a version mismatch.
@KrisThielemans
Copy link
Collaborator

good catch. Another case for getting rid of this special handling relying on the generic one...

@KrisThielemans
Copy link
Collaborator

@markus-jehl you're probably not able to, but in case you can, this PR should speed up the ML_norm code a fair amount, so you could potentially try that. It'd be good to have some reassurance on real data, as opposed to our simple test.

@@ -14,6 +14,7 @@ View offset (degrees) := 0
Maximum number of (unmashed) TOF time bins := 5
Size of unmashed TOF time bins (ps) := 820.0
TOF timing resolution (ps) := 400.0
TOF mashing factor:= 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need to add this.

@@ -72,7 +72,7 @@ FilePath::is_directory() const
struct stat info;

if (stat(my_string.c_str(), &info) != 0)
error(boost::format("FilePath: Cannot access %1%.") % my_string);
warning(boost::format("FilePath: Cannot access %1%.") % my_string);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we make this change?

@@ -177,9 +177,46 @@ ProjDataInfo::set_tof_mash_factor(const int new_num)
{
tof_mash_factor = new_num;
if (tof_mash_factor > scanner_ptr->get_max_num_timing_poss())
error("ProjDataInfo::set_tof_mash_factor: TOF mashing factor (" + std::to_string(tof_mash_factor)
{
warning("ProjDataInfo::set_tof_mash_factor: TOF mashing factor (" + std::to_string(tof_mash_factor)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still want an error here

+ +") must be smaller than or equal to the scanner's number of max timing bins ("
+ std::to_string(scanner_ptr->get_max_num_timing_poss()) + ").");
}
else if (tof_mash_factor == scanner_ptr->get_max_num_timing_poss())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's see what happens if we remove this special case, as it shouldn't be "special"

We need to preserve the TOF character, such that coincidence window
etc is taken into account.
src/include/stir/Scanner.h Outdated Show resolved Hide resolved
Comment on lines +190 to +193
// if (check_scanner_match_geometry(error_str, this_scanner_sptr) == Succeeded::no)
// {
// error(error_str.c_str());
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will have to re-enable this. Why did you need it?

src/utilities/construct_fanProjData_fromProjData.cxx Outdated Show resolved Hide resolved
@@ -21,6 +21,7 @@ set(${dir_EXE_SOURCES}
manip_projdata.cxx
display_projdata.cxx
do_linear_regression.cxx
construct_fanProjData_fromProjData
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename this file to save_FanProjData_from_ProjData

@KrisThielemans
Copy link
Collaborator

KrisThielemans commented Jun 1, 2024

Ubuntu clang job fails with

usr/bin/ld: CMakeFiles/test_BSplinesRegularGrid.dir/test_BSplinesRegularGrid.cxx.o: in function `.omp_outlined.':
test_BSplinesRegularGrid.cxx:(.text+0x39bf): undefined reference to `__atomic_load'
/usr/bin/ld: test_BSplinesRegularGrid.cxx:(.text+0x39f3): undefined reference to `__atomic_compare_exchange'
clang: error: linker command failed with exit code 1 (use -v to see invocation)usr/bin/ld: CMakeFiles/test_BSplinesRegularGrid.dir/test_BSplinesRegularGrid.cxx.o: in function `.omp_outlined.':
test_BSplinesRegularGrid.cxx:(.text+0x39bf): undefined reference to `__atomic_load'
/usr/bin/ld: test_BSplinesRegularGrid.cxx:(.text+0x39f3): undefined reference to `__atomic_compare_exchange'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Potentially related to https://gitlab.kitware.com/cmake/cmake/-/issues/23021 but it's weird tst_BSplines links ok.

@KrisThielemans
Copy link
Collaborator

test_ML_norm segfaults in the MacOS Debug job

@KrisThielemans
Copy link
Collaborator

Potentially related to https://gitlab.kitware.com/cmake/cmake/-/issues/23021 but it's weird tst_BSplines links ok.

Now https://gitlab.kitware.com/cmake/cmake/-/issues/26037

@KrisThielemans
Copy link
Collaborator

Linking problem was fixed in #1449 which has taken the sum/find_min/max parallelisation commits, and is now merged to master, so I've merged that back on here.

I suggest we split this PR in 2: one for the sensitivity calculation, and one for the parallelisation of the norm code. We can do that again by cherry-picking relevant commits. Maybe we can resolve things here first though, as you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants