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

Batch search inside stack search #530

Merged
merged 10 commits into from
Apr 8, 2024

Conversation

vlnistor
Copy link
Collaborator

@vlnistor vlnistor commented Mar 23, 2024

This tackles #356

The idea is that you'd replace the full in-memory search:

min_observations = ... # Some min observations
candidates = ... # Some trajectories
stack = ImageStack(im_list)
search = StackSearch(stack)
search.search(candidates, min_observations)

With a batched version:

 batch_results = []
 with BatchSearchManager(StackSearch(stack), candidates, min_observations) as batch_search:
    batch_results = []
    for i in range(0, width, 5):
        batch_search.set_start_bounds_x(i, i + 5)
        for j in range(0, height, 5):
            batch_search.set_start_bounds_y(j, j + 5)
            batch_results.extend(batch_search.search_batch())

The steps are:

  1. Use the BatchSearchManager context manager to obtain a managed batch_search object
  2. Loop through the whole grid by breaking it into smaller subsets

@vlnistor vlnistor force-pushed the I-356/batch-search branch from 9e322bb to 0b25c32 Compare March 23, 2024 20:48
…so as to be able to init gpu_search_list outside of the main search func
@@ -0,0 +1,40 @@
class BatchSearchManager:
Copy link
Collaborator Author

@vlnistor vlnistor Mar 23, 2024

Choose a reason for hiding this comment

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

The main idea here was that I didn't want the user to have to call prepare_batch_search and finish_search manually

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not for this PR, but something to consider as a future extension: In theory this could be extended further by making this a generator:

for batch_search in BatchSearchManager(stack_search, search_list, min_observations, x_size, y_size):
    batch_results.extend(batch_search.search_batch())

where the BatchSearchManager tracks the block sizes to search, current block locations, etc.

@vlnistor vlnistor requested a review from jeremykubica March 25, 2024 21:03
Copy link
Collaborator

@jeremykubica jeremykubica left a comment

Choose a reason for hiding this comment

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

A bunch of points for discussion.

src/kbmod/batch_search.py Outdated Show resolved Hide resolved
src/kbmod/search/trajectory_list.cpp Outdated Show resolved Hide resolved
src/kbmod/search/stack_search.cpp Outdated Show resolved Hide resolved
src/kbmod/search/stack_search.h Show resolved Hide resolved
src/kbmod/search/stack_search.h Outdated Show resolved Hide resolved
src/kbmod/search/trajectory_list.h Outdated Show resolved Hide resolved
tests/test_search.py Outdated Show resolved Hide resolved
@@ -0,0 +1,40 @@
class BatchSearchManager:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not for this PR, but something to consider as a future extension: In theory this could be extended further by making this a generator:

for batch_search in BatchSearchManager(stack_search, search_list, min_observations, x_size, y_size):
    batch_results.extend(batch_search.search_batch())

where the BatchSearchManager tracks the block sizes to search, current block locations, etc.

…e_batch + removed move assignment operator in favour of set_trajectories + updated search to search_all across the python code
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@vlnistor vlnistor requested a review from jeremykubica April 3, 2024 22:19
Copy link
Collaborator

@jeremykubica jeremykubica left a comment

Choose a reason for hiding this comment

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

This is looking really good. A few stylistic cleanups.

}


int StackSearch::extract_max_results(){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good call breaking this out into a function.

stack = ImageStack(imlist)
im_list = stack.get_images()
# Create a new list of LayeredImages with the added object.
new_im_list = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove new_im_list

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed now

@@ -29,6 +29,7 @@ using Point = indexing::Point;
using Image = search::Image;

class StackSearch {
int extract_max_results();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe rename this to get_max_results or compute_max_results to avoid any confusion about this somehow extracting the results from the cached list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point - renamed

src/kbmod/search/stack_search.cpp Show resolved Hide resolved

// Do the actual search on the GPU.
DebugTimer search_timer = DebugTimer("search execution", rs_logger);
// Do the actual search on the GPU.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indentation of this comment appears off.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cleaned

src/kbmod/search/stack_search.h Show resolved Hide resolved
@jeremykubica jeremykubica merged commit 7412363 into dirac-institute:main Apr 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants