Skip to content

Cache and pre-resolve LSST deep_coadd refs; extend mock butler with query support - #933

Draft
mtauraso wants to merge 1 commit into
mainfrom
codex/evaluate-using-deferred-butler-interface
Draft

mtauraso wants to merge 1 commit into
mainfrom
codex/evaluate-using-deferred-butler-interface

Conversation

@mtauraso

Copy link
Copy Markdown
Member

Motivation

  • Reduce repeated Butler lookups and improve multithreaded behavior by pre-resolving and caching deep_coadd references and skymap objects for catalog tracts/patches and configured bands.

Description

  • Initialize an internal cache self._deep_coadd_refs and call _build_deep_coadd_ref_cache() when a Butler configuration is present in LSSTDataset.
  • Add _build_deep_coadd_ref_cache() to bulk-query the butler for deep_coadd dataset references per band and store them keyed by (tract, patch, band) for later retrieval.
  • Replace ad-hoc skymap retrieval in _get_tract_patch() with a cached _get_skymap() helper decorated with functools.lru_cache to avoid repeated lookups.
  • Update _request_patch() to use the pre-resolved MockDatasetRef/butler refs via self._deep_coadd_refs[(tract_index, patch_index, band)] and call the butler with the ref instead of constructing dict-based IDs.
  • Extend test mocks in tests/hyrax/mocks/lsst_butler_mocks.py by adding MockButler.query_datasets(), a minimal MockDatasetRef class, and making MockButler.get() accept MockDatasetRef instances so the tests can simulate query_datasets + get(ref) behavior.

Testing

  • Ran unit tests under tests/hyrax with pytest to exercise the LSST dataset and mock butler paths, and the test suite passed.
  • Executed the modified mock interactions by invoking MockButler.query_datasets() and MockButler.get() in tests to verify resolving and fetching deep_coadd exposures, and those checks passed.

Codex Task

Copilot AI review requested due to automatic review settings May 26, 2026 21:15
@mtauraso
mtauraso requested a review from aritraghsh09 May 26, 2026 21:16
@mtauraso
mtauraso marked this pull request as draft May 26, 2026 21:16
@mtauraso

mtauraso commented May 26, 2026 •

Copy link
Copy Markdown
Member Author

Someone needs to test this on USDF before review & merge

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce repeated LSST Butler lookups by pre-resolving and caching deep_coadd dataset references (keyed by tract/patch/band) and caching skymap retrieval within LSSTDataset. It also extends the test Butler mocks to support query_datasets() and get(ref) to simulate the new access pattern.

Changes:

  • Add an internal deep_coadd ref cache built via butler.query_datasets() and switch patch retrieval to butler.get(ref).
  • Add an lru_cache-backed _get_skymap() helper to avoid repeated skymap fetches.
  • Extend MockButler with query_datasets() and a minimal MockDatasetRef so tests can cover the new ref-based retrieval.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/hyrax/datasets/lsst_dataset.py Adds deep_coadd ref pre-resolution/caching and cached skymap retrieval; updates patch requests to use resolved refs.
tests/hyrax/mocks/lsst_butler_mocks.py Adds minimal query_datasets() + MockDatasetRef and enables MockButler.get(ref) to support the new dataset code path.

Comment on lines +78 to +80
self._deep_coadd_refs = {}
if self._butler_config is not None:
self._build_deep_coadd_ref_cache()
Comment on lines +311 to +322
for band in LSSTDataset.BANDS:
data_id = {"skymap": self.config["data_set"]["skymap"], "band": band}
refs = list(
butler.query_datasets(
"deep_coadd",
data_id=data_id,
collections=self._butler_config["collections"],
)
)
for ref in refs:
key = (ref.dataId["tract"], ref.dataId["patch"], ref.dataId["band"])
if (key[0], key[1]) in needed_tract_patches:
Comment on lines +298 to +301
@functools.lru_cache(maxsize=4) # noqa: B019
def _get_skymap(self, skymap_name):
"""Fetch and cache the immutable skymap object by name."""
return self._get_butler_thread_safe().get("skyMap", {"skymap": skymap_name})
Comment on lines 336 to +338
for band in LSSTDataset.BANDS:
# Set up the data dict
butler_dict = {
"tract": tract_index,
"patch": patch_index,
"skymap": self.config["data_set"]["skymap"],
"band": band,
}

# pull from butler
image = self._get_butler_thread_safe().get("deep_coadd", butler_dict)
ref = self._deep_coadd_refs[(tract_index, patch_index, band)]
image = self._get_butler_thread_safe().get(ref)
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.04%. Comparing base (8e9231f) to head (976c088).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #933      +/-   ##
==========================================
+ Coverage   62.94%   63.04%   +0.09%     
==========================================
  Files          71       71              
  Lines        7357     7376      +19     
==========================================
+ Hits         4631     4650      +19     
  Misses       2726     2726              

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aritraghsh09

Copy link
Copy Markdown
Collaborator

I will try to test this at USDF soon to have some benchmarks.

@mtauraso mtauraso self-assigned this Jun 11, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants