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

If not resuming, remove intermediate dir. #244

Merged
merged 1 commit into from
Feb 28, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/hipscat_import/pipeline_resume_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import re
import warnings
from dataclasses import dataclass
from pathlib import Path

Expand Down Expand Up @@ -35,11 +36,11 @@ def safe_to_resume(self):
"""
if file_io.directory_has_contents(self.tmp_path):
if not self.resume:
raise ValueError(
f"tmp_path ({self.tmp_path}) contains intermediate files."
" choose a different directory or use --resume flag"
self.clean_resume_files()
else:
warnings.warn(
f"tmp_path ({self.tmp_path}) contains intermediate files; resuming prior progress."
)
print(f"tmp_path ({self.tmp_path}) contains intermediate files. resuming prior progress.")
else:
file_io.make_directory(self.tmp_path, exist_ok=True)

Expand Down
60 changes: 34 additions & 26 deletions tests/hipscat_import/catalog/test_resume_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@ def test_done_checks(tmp_path):
plan = ResumePlan(tmp_path=tmp_path, progress_bar=False, resume=True)
plan.touch_stage_done_file(ResumePlan.REDUCING_STAGE)

with pytest.raises(ValueError, match="before reducing"):
plan.gather_plan()
with pytest.warns(UserWarning, match="resuming prior progress"):
with pytest.raises(ValueError, match="before reducing"):
plan.gather_plan()

plan.touch_stage_done_file(ResumePlan.SPLITTING_STAGE)
with pytest.raises(ValueError, match="before reducing"):
plan.gather_plan()
with pytest.warns(UserWarning, match="resuming prior progress"):
with pytest.raises(ValueError, match="before reducing"):
plan.gather_plan()

plan.clean_resume_files()

plan = ResumePlan(tmp_path=tmp_path, progress_bar=False, resume=True)
plan.touch_stage_done_file(ResumePlan.SPLITTING_STAGE)
with pytest.raises(ValueError, match="before splitting"):
plan.gather_plan()
with pytest.warns(UserWarning, match="resuming prior progress"):
with pytest.raises(ValueError, match="before splitting"):
plan.gather_plan()


def test_same_input_paths(tmp_path, small_sky_single_file, formats_headers_csv):
Expand All @@ -63,30 +66,33 @@ def test_same_input_paths(tmp_path, small_sky_single_file, formats_headers_csv):
map_files = plan.map_files
assert len(map_files) == 2

with pytest.raises(ValueError, match="Different file set"):
ResumePlan(
tmp_path=tmp_path,
progress_bar=False,
resume=True,
input_paths=[small_sky_single_file],
)
with pytest.warns(UserWarning, match="resuming prior progress"):
with pytest.raises(ValueError, match="Different file set"):
ResumePlan(
tmp_path=tmp_path,
progress_bar=False,
resume=True,
input_paths=[small_sky_single_file],
)

## List is the same length, but includes a duplicate
with pytest.raises(ValueError, match="Different file set"):
ResumePlan(
with pytest.warns(UserWarning, match="resuming prior progress"):
with pytest.raises(ValueError, match="Different file set"):
ResumePlan(
tmp_path=tmp_path,
progress_bar=False,
resume=True,
input_paths=[small_sky_single_file, small_sky_single_file],
)

## Includes a duplicate file, but that's ok.
with pytest.warns(UserWarning, match="resuming prior progress"):
plan = ResumePlan(
tmp_path=tmp_path,
progress_bar=False,
resume=True,
input_paths=[small_sky_single_file, small_sky_single_file],
input_paths=[small_sky_single_file, small_sky_single_file, formats_headers_csv],
)

## Includes a duplicate file, but that's ok.
plan = ResumePlan(
tmp_path=tmp_path,
progress_bar=False,
resume=True,
input_paths=[small_sky_single_file, small_sky_single_file, formats_headers_csv],
)
map_files = plan.map_files
assert len(map_files) == 2

Expand Down Expand Up @@ -148,13 +154,15 @@ def test_read_write_splitting_keys(tmp_path, small_sky_single_file, formats_head

ResumePlan.touch_key_done_file(tmp_path, ResumePlan.SPLITTING_STAGE, "split_0")

plan.gather_plan()
with pytest.warns(UserWarning, match="resuming prior progress"):
plan.gather_plan()
split_keys = plan.split_keys
assert len(split_keys) == 1
assert split_keys[0][0] == "split_1"

ResumePlan.touch_key_done_file(tmp_path, ResumePlan.SPLITTING_STAGE, "split_1")
plan.gather_plan()
with pytest.warns(UserWarning, match="resuming prior progress"):
plan.gather_plan()
split_keys = plan.split_keys
assert len(split_keys) == 0

Expand Down
27 changes: 14 additions & 13 deletions tests/hipscat_import/catalog/test_run_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ def test_resume_dask_runner(
os.path.join(tmp_path, "resume_catalog", "Norder=0"),
)

args = ImportArguments(
output_artifact_name="resume_catalog",
input_path=small_sky_parts_dir,
file_reader="csv",
output_path=tmp_path,
dask_tmp=tmp_path,
tmp_dir=tmp_path,
resume_tmp=os.path.join(tmp_path, "tmp"),
overwrite=True,
highest_healpix_order=0,
pixel_threshold=1000,
progress_bar=False,
)
with pytest.warns(UserWarning, match="resuming prior progress"):
args = ImportArguments(
output_artifact_name="resume_catalog",
input_path=small_sky_parts_dir,
file_reader="csv",
output_path=tmp_path,
dask_tmp=tmp_path,
tmp_dir=tmp_path,
resume_tmp=os.path.join(tmp_path, "tmp"),
overwrite=True,
highest_healpix_order=0,
pixel_threshold=1000,
progress_bar=False,
)

runner.run(args, dask_client)

Expand Down
17 changes: 9 additions & 8 deletions tests/hipscat_import/margin_cache/test_margin_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ def test_margin_cache_gen(small_sky_source_catalog, tmp_path, dask_client):
@pytest.mark.dask(timeout=150)
def test_margin_cache_gen_negative_pixels(small_sky_source_catalog, tmp_path, dask_client):
"""Test that margin cache generation can generate a file for a negative pixel."""
args = MarginCacheArguments(
margin_threshold=36000.0,
input_catalog_path=small_sky_source_catalog,
output_path=tmp_path,
output_artifact_name="catalog_cache",
margin_order=4,
progress_bar=False,
)
with pytest.warns(UserWarning, match="smaller resolution"):
args = MarginCacheArguments(
margin_threshold=36000.0,
input_catalog_path=small_sky_source_catalog,
output_path=tmp_path,
output_artifact_name="catalog_cache",
margin_order=4,
progress_bar=False,
)

assert args.catalog.catalog_info.ra_column == "source_ra"

Expand Down
9 changes: 6 additions & 3 deletions tests/hipscat_import/soap/test_soap_resume_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ def test_count_keys(small_sky_soap_args):
## Mark one done and check that there's one less key to count later.
Path(small_sky_soap_args.tmp_path, "2_187.csv").touch()

plan.gather_plan(small_sky_soap_args)
with pytest.warns(UserWarning, match="resuming prior progress"):
plan.gather_plan(small_sky_soap_args)
assert len(plan.count_keys) == 13

## Mark them ALL done and check that there are on keys later.
plan.touch_stage_done_file(SoapPlan.COUNTING_STAGE)

plan.gather_plan(small_sky_soap_args)
with pytest.warns(UserWarning, match="resuming prior progress"):
plan.gather_plan(small_sky_soap_args)
assert len(plan.count_keys) == 0


Expand All @@ -115,7 +117,8 @@ def test_cached_map_file(small_sky_soap_args):
cache_map_file = os.path.join(small_sky_soap_args.tmp_path, SoapPlan.SOURCE_MAP_FILE)
assert os.path.exists(cache_map_file)

plan = SoapPlan(small_sky_soap_args)
with pytest.warns(UserWarning, match="resuming prior progress"):
plan = SoapPlan(small_sky_soap_args)
assert len(plan.count_keys) == 14


Expand Down
3 changes: 1 addition & 2 deletions tests/hipscat_import/test_pipeline_resume_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def test_safe_to_resume(tmp_path):
## explicitly setting resume=True
done_file = "action_done"
plan.touch_stage_done_file(done_file)
with pytest.raises(ValueError, match="contains intermediate"):
plan.safe_to_resume()
plan.safe_to_resume()

## If we mark as a resuming pipeline, we're safe to resume.
resuming_plan = PipelineResumePlan(tmp_path=tmp_path, progress_bar=False, resume=True)
Expand Down