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

DM-44393: Prompt Processing does not transfer visit definitions #166

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions python/activator/middleware_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,21 +1283,7 @@ def _export_subset(self, exposure_ids: set[int],
# Transferring governor dimensions in parallel can cause deadlocks in
# central registry. We need to transfer our exposure/visit dimensions,
# so handle those manually.
for dimension in ["group",
"day_obs",
"exposure",
"visit",
]:
if dimension in self.butler.registry.dimensions:
records = self.butler.registry.queryDimensionRecords(
dimension,
where="exposure in (exposure_ids)",
bind={"exposure_ids": exposure_ids},
instrument=self.instrument.getName(),
detector=self.visit.detector,
)
# If records don't match, this is not an error, and central takes precedence.
self.central_butler.registry.insertDimensionData(dimension, *records, skip_existing=True)
self._export_exposure_dimensions(exposure_ids)
transferred = self.central_butler.transfer_from(self.butler, datasets,
transfer="copy", transfer_dimensions=False)
if len(transferred) != len(datasets):
Expand All @@ -1307,6 +1293,44 @@ def _export_subset(self, exposure_ids: set[int],

return transferred

def _export_exposure_dimensions(self, exposure_ids):
"""Transfer dimensions generated from an exposure to the central repo.

In many cases the exposure records will already exist in the central
repo, but this is not guaranteed (especially in dev environments).
Visit records never exist in the central repo and are the sole
responsibility of Prompt Processing.

Parameters
----------
exposure_ids : `set` [`int`]
Identifiers of the exposures that were processed.
"""
core_dimensions = ["group",
"day_obs",
"exposure",
"visit",
"visit_system",
]
universe = self.butler.dimensions

full_dimensions = [universe[d] for d in core_dimensions if d in universe]
extra_dimensions = []
for d in full_dimensions:
extra_dimensions.extend(universe.get_elements_populated_by(universe[d]))
sorted_dimensions = universe.sorted(full_dimensions + extra_dimensions)

for dimension in sorted_dimensions:
records = self.butler.registry.queryDimensionRecords(
dimension,
where="exposure in (exposure_ids)",
bind={"exposure_ids": exposure_ids},
instrument=self.instrument.getName(),
detector=self.visit.detector,
)
# If records don't match, this is not an error, and central takes precedence.
self.central_butler.registry.insertDimensionData(dimension, *records, skip_existing=True)

def _chain_exports(self, output_chain: str, output_runs: collections.abc.Iterable[str]) -> None:
"""Associate exported datasets with a chained collection in the
central Butler.
Expand Down
7 changes: 7 additions & 0 deletions tests/test_middleware_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,13 @@ def test_export_outputs(self):
central_butler = Butler(self.central_repo.name, writeable=False)
self.assertEqual(self._count_datasets(central_butler, "calexp", self.output_run), 2)
self.assertEqual(self._count_datasets(central_butler, "calexp", self.output_chain), 2)
# Should be able to look up datasets by both visit and exposure
self.assertEqual(
self._count_datasets_with_id(central_butler, "calexp", self.output_run, self.raw_data_id),
1)
self.assertEqual(
self._count_datasets_with_id(central_butler, "calexp", self.output_run, self.second_data_id),
1)
self.assertEqual(
self._count_datasets_with_id(central_butler, "calexp", self.output_run, self.processed_data_id),
1)
Expand Down
Loading