Skip to content

[WIP] Fix rng - #1411

Open
garrettwrong wants to merge 59 commits into
developfrom
fix_rng
Open

garrettwrong wants to merge 59 commits into
developfrom
fix_rng

Conversation

@garrettwrong

Copy link
Copy Markdown
Collaborator

Resolves #1406 and #1405.

Still WIP. Stashing here for potential discussion during weekly dev meeting.

Still need to replace more instances of randi randn and random, but the main uses in the code have been converted at 87b4

Refactors Simulation to consolidate the randomized components. Legacy MATLAB behaviors isolated to LegacySimulation which should repro old work/sequences. Simulation should now use the modern numpy rng implementation and be randomly seeded by default.

@garrettwrong

Copy link
Copy Markdown
Collaborator Author

At fd8f704 this branch has migrated all the code not tied to hardcoded references towards modern Numpy RNG practices. With the exception noted below, legacy references/implementations have been isolated. They are currently still able to reproduce. Code has been refactored to allow easily dropping them entirely in the future if the related tests are replaced. Legacy random utils have been deprecated into our third level of imports, ie they are no longer exposed as aspire.utils. I'll plan to update the docstrings more after this patch is otherwise ready to go.

One problem area that remains is NoiseAdder. I found that a collection of tests require the exact sequence of generated noise to reproduce hard coded references. This is similar to what I found for generate_random_rotations, Simulation, and LegacyVolume, except that in those cases it was more straightforward to replicate and seperate the behavior for the legacy situations. I'm not sure exactly what to do with the NoiseAdder quite yet. Need to think on the options a little.

The other area remaining is the collection of commonlines tests. Most of the tests were not robust and some were not actually functional. The tolerances appear to be derived from whatever results come out with the prior seed/rng. While I can adjust the test tolerances, its probably better that Josh does this since most of these are his recent work. Some of them (the commonlines indices one for example) date back to Junchoa and should probably replaced with a legitimate test.

The following are the remaining test failures in the regular suite:

FAILED tests/test_orient_sdp.py::test_gram_matrix[resolution=33-offsets=0-dtype=<class 'numpy.float32'>]
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=32-offsets=0-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=True]
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=32-offsets=0-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=False]
FAILED tests/test_orient_d2.py::test_estimate_rotations[n images=10-resolution=48-dtype=<class 'numpy.float32'>-offsets=0]
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=33-offsets=0-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=True]
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=33-offsets=0-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=False]
FAILED tests/test_orient_d2.py::test_estimate_rotations[n images=10-resolution=49-dtype=<class 'numpy.float32'>-offsets=0]
FAILED tests/test_rotation.py::test_common_lines[dtype=<class 'numpy.float64'>]
FAILED tests/test_orient_sdp.py::test_construct_S[resolution=32-offsets=0-dtype=<class 'numpy.float32'>]
FAILED tests/test_orient_sdp.py::test_construct_S[resolution=33-offsets=0-dtype=<class 'numpy.float32'>]
FAILED tests/test_orient_sdp.py::test_gram_matrix[resolution=32-offsets=0-dtype=<class 'numpy.float32'>]
FAILED tests/test_rotation.py::test_common_lines[dtype=<class 'numpy.float32'>]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=32-offsets=0-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=True]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=32-offsets=0-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=False]
FAILED tests/test_orient_symmetric.py::test_relative_viewing_directions[24-45-4-float64]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=32-offsets=None-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=True]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=32-offsets=None-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=False]

These are the failures in the expensive suite:

FAILED tests/test_orient_sdp.py::test_gram_matrix[resolution=32-offsets=0-dtype=<class 'numpy.float64'>]                           
FAILED tests/test_orient_sdp.py::test_gram_matrix[resolution=33-offsets=0-dtype=<class 'numpy.float64'>]                           
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=33-offsets=None-dtype=<class 'numpy.float64'>-alpha=None-adp_pr
oj=True]                                                                                                                           
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=32-offsets=None-dtype=<class 'numpy.float64'>-alpha=0.66666666
66666666-adp_proj=True]                                                                                                            
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=33-offsets=None-dtype=<class 'numpy.float64'>-alpha=None-adp_pr
oj=False]                                                                                                                          
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=32-offsets=None-dtype=<class 'numpy.float64'>-alpha=0.66666666
66666666-adp_proj=False]                                                                                                           
FAILED tests/test_orient_d2.py::test_estimate_rotations[n images=10-resolution=48-dtype=<class 'numpy.float64'>-offsets=None]      
FAILED tests/test_orient_symmetric.py::test_relative_viewing_directions[24-44-4-float32]                                           
FAILED tests/test_orient_d2.py::test_scl_scores[n images=10-resolution=48-dtype=<class 'numpy.float64'>-offsets=None]              
FAILED tests/test_orient_d2.py::test_estimate_rotations[n images=10-resolution=48-dtype=<class 'numpy.float32'>-offsets=None]      
FAILED tests/test_orient_symmetric.py::test_relative_viewing_directions[24-44-4-float64]                                           FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=33-offsets=0-dtype=<class 'numpy.float64'>-alpha=0.666666666666
6666-adp_proj=True]                                                                                                                FAILED tests/test_orient_symmetric.py::test_relative_viewing_directions[24-45-4-float32]                                           
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=33-offsets=0-dtype=<class 'numpy.float32'>-alpha=0.66666666666
66666-adp_proj=True]                                                                                                               FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=33-offsets=0-dtype=<class 'numpy.float64'>-alpha=0.666666666666
6666-adp_proj=False]                                                                                                               
FAILED tests/test_orient_d2.py::test_estimate_rotations[n images=10-resolution=48-dtype=<class 'numpy.float64'>-offsets=0]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=33-offsets=0-dtype=<class 'numpy.float32'>-alpha=0.6666666666666666-adp_proj=False]  
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=32-offsets=None-dtype=<class 'numpy.float32'>-alpha=None-adp_proj=True]                
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=32-offsets=None-dtype=<class 'numpy.float32'>-alpha=None-adp_pr
oj=False]                                         
FAILED tests/test_orient_d2.py::test_estimate_rotations[n images=10-resolution=49-dtype=<class 'numpy.float64'>-offsets=None]
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=32-offsets=None-dtype=<class 'numpy.float64'>-alpha=None-adp_pr
oj=True]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=33-offsets=0-dtype=<class 'numpy.float64'>-alpha=0.66666666666
66666-adp_proj=True]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=32-offsets=0-dtype=<class 'numpy.float64'>-alpha=0.66666666666
66666-adp_proj=True]
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=32-offsets=None-dtype=<class 'numpy.float64'>-alpha=None-adp_pr
oj=False]
FAILED tests/test_orient_d2.py::test_estimate_rotations[n images=10-resolution=49-dtype=<class 'numpy.float64'>-offsets=0]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=33-offsets=0-dtype=<class 'numpy.float64'>-alpha=0.66666666666
66666-adp_proj=False]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=32-offsets=0-dtype=<class 'numpy.float64'>-alpha=0.66666666666
66666-adp_proj=False]
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=32-offsets=0-dtype=<class 'numpy.float64'>-alpha=0.666666666666
6666-adp_proj=True]
FAILED tests/test_orient_lud.py::test_estimate_rotations[resolution=32-offsets=0-dtype=<class 'numpy.float64'>-alpha=0.666666666666
6666-adp_proj=False]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=33-offsets=None-dtype=<class 'numpy.float32'>-alpha=0.66666666
66666666-adp_proj=True]
FAILED tests/test_orient_d2.py::test_estimate_rotations[n images=10-resolution=49-dtype=<class 'numpy.float32'>-offsets=None]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=33-offsets=None-dtype=<class 'numpy.float32'>-alpha=0.66666666
66666666-adp_proj=False]
FAILED tests/test_orient_sdp.py::test_construct_S[resolution=32-offsets=0-dtype=<class 'numpy.float64'>]
FAILED tests/test_orient_sdp.py::test_construct_S[resolution=33-offsets=0-dtype=<class 'numpy.float64'>]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=33-offsets=None-dtype=<class 'numpy.float64'>-alpha=0.66666666
66666666-adp_proj=True]
FAILED tests/test_orient_irls.py::test_estimate_rotations[resolution=33-offsets=None-dtype=<class 'numpy.float64'>-alpha=0.66666666
66666666-adp_proj=False]
FAILED tests/test_synthetic_volume.py::test_volume_symmetry[ISymmetricVolume, res=70-float32]
FAILED tests/test_synthetic_volume.py::test_volume_symmetry[ISymmetricVolume, res=71-float32]
FAILED tests/test_synthetic_volume.py::test_volume_symmetry[ISymmetricVolume, res=70-float64]
FAILED tests/test_synthetic_volume.py::test_volume_symmetry[ISymmetricVolume, res=71-float64]
FAILED tests/test_orient_symmetric.py::test_estimate_rotations[24-45-6-float64]
FAILED tests/test_orient_sync_voting.py::test_estimate_shifts_with_est_rots[resolution=41-offsets=None-dtype=<class 'numpy.float64'
>]
FAILED tests/test_orient_sync_voting.py::test_estimate_shifts_with_est_rots[resolution=41-offsets=None-dtype=<class 'numpy.float32'
>]
FAILED tests/test_orient_symmetric.py::test_estimate_rotations[24-44-8-float32]
FAILED tests/test_orient_symmetric.py::test_estimate_rotations[24-45-9-float64]

@j-c-c please make a PR (into this fix_rng branch) that corrects these tests (either by updating tolerances or addressing code problems) .

While that is happening I will setup to run the experimental data reconstructions to see how they are performing with this implementation.

@j-c-c

j-c-c commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

@j-c-c please make a PR (into this fix_rng branch) that corrects these tests (either by updating tolerances or addressing code problems) .

While that is happening I will setup to run the experimental data reconstructions to see how they are performing with this implementation.

@garrettwrong Working on it now.

@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.33679% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.11%. Comparing base (e4a05cc) to head (cec9d3a).

Files with missing lines Patch % Lines
src/aspire/utils/random.py 61.90% 8 Missing ⚠️
src/aspire/source/simulation.py 98.24% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1411      +/-   ##
===========================================
- Coverage    90.65%   90.11%   -0.55%     
===========================================
  Files          135      135              
  Lines        14932    15001      +69     
===========================================
- Hits         13537    13518      -19     
- Misses        1395     1483      +88     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tests/test_orient_sync_voting.py Resolved
@garrettwrong

Copy link
Copy Markdown
Collaborator Author

Just kicking off the review suite, not ready for review yet.

@garrettwrong
garrettwrong marked this pull request as ready for review October 1, 2026 17:36
@garrettwrong
garrettwrong requested a review from janden as a code owner October 1, 2026 17:36
@garrettwrong garrettwrong changed the title Fix rng [WIP] Fix rng Oct 1, 2026
Comment thread tests/test_orient_symmetric.py Resolved
Comment thread tests/test_orient_symmetric.py Resolved
Comment thread tests/test_orient_symmetric.py Resolved
@garrettwrong

Copy link
Copy Markdown
Collaborator Author

Looks like most of the remaining failures are in tests/test_orient_sync_voting.py::test_estimate_rotations_fuzzy_mask where it often comes just slightly outside 10% for the test now that it is randomly seeded.

Comment thread tests/test_orient_sync_voting.py Resolved
@garrettwrong

Copy link
Copy Markdown
Collaborator Author

Manually re-running the ampere jobs to see if there is any flaky tests that pop up before those machines go down for maintenance.

@garrettwrong

Copy link
Copy Markdown
Collaborator Author

@j-c-c , what's the ETA looking like on this review?

@j-c-c

j-c-c commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@j-c-c , what's the ETA looking like on this review?

@garrettwrong still working through it. Should have it sometime after lunch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup support User Support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants