pyushkevich / greedy

Very fast greedy diffeomorphic registration code
GNU General Public License v3.0
59 stars 16 forks source link

Non-deterministic output transformations on Linux #30

Open machur opened 2 years ago

machur commented 2 years ago

Hi,

I've identified an issue with output transformations calculated by Greedy on Linux. I run it several times to register data using affine options with the command below and received different affine transformations on every run:

greedy -i /path/test_data/moving.nii.gz /path/test_data/reference.nii.gz -o /path/test_output/SSD_100x50x20/affine.mat -n 100x50x20 -d 3 -m SSD -ia-image-centers -a -dof 12

The following transformation matrices were saved on two separate runs on Linux for the exact same input data and Greedy parameters:

1.02348 0.000315488 0.00602789 -1.52572 0.00256797 0.994491 0.00338622 -1.88332 0.00062883 -0.00871956 0.797624 -44.4442 0 0 0 1

1.01814 0.00120815 0.00449941 -1.06076 -0.000651167 0.996294 0.0018094 -2.27074 0.00119741 -0.00765716 0.796436 -44.8874 0 0 0 1

The version of Greedy used for calculation:

Greedy Version 1.2.0 Release date: Jan 12, 2021 Compile date: Nov 23, 2021 GIT branch: itk5 GIT commit: 6488047a0ae736b8cc7c45761126dc41902ba6e3 GIT commit date: 2021-10-22 14:16:34 -0400

I didn't find any random seeds/parameters in the source code of registration algorithms, so as far as I'm concerned all the results should be repeatable. Would you please investigate?

machur commented 2 years ago

@pyushkevich I just built and tested Greedy binary in version 1.0.1 (Linux build of the same version that is distributed with the latest ITK-SNAP). Results are fully reproducible and deterministic regardless of registration options, so it looks like something got changed in the source code of Greedy on the way to the latest version. The version I tested is as follows:

Greedy Version 1.0.1 Release date: Mar 21, 2019 Compile date: Dec 08, 2021 GIT branch: master_1.0.1 GIT commit: 79e69e3d7b4d1e88cf87218ca99d6d373d323f9f GIT commit date: 2019-03-21 13:41:18 -0400

machur commented 2 years ago

@pyushkevich I have one more observation regarding the numeric stability of Greedy algorithms. I tested Greedy binaries created for Windows and Linux against each other (both built from commit 79e69e3d7b4d1e88cf87218ca99d6d373d323f9f) with different "thread" parameter. The results were fully repeatable per configuration, but it looks like not only the OS version had impact on the final matrices, but the number of threads as well, so I suspect some race-conditions in the code that need to be handled.

devDonnn commented 1 year ago

Hi. I also get a non-deterministic output of the affine registration using the latest build. Is there a way to guarantee a deterministic behavior without using the earlier version of greedy?