Skip to content

Commit 7ae7f5e

Browse files
authored
Fix parsl config deprecation issues (#78)
* Fix parsl config deprecation issues * Add test coverage for all resource configurations * Fix Python 3.9 compatibility (use Optional instead of |) * Remove pinned python version from pre-commit config * Fix linting in test_basic.py and duplicate key search config * Remove unneeded commented lines in parsl_configurator.py * Refactor tests: Rename to test_resource_config.py and use unittest * Simplify test docstrings and comments * Remove deprecated mom_lims from search config yaml
1 parent 62b7ad2 commit 7ae7f5e

File tree

8 files changed

+189
-102
lines changed

8 files changed

+189
-102
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ repos:
5454
# supported by your project here, or alternatively use
5555
# pre-commit's default_language_version, see
5656
# https://pre-commit.com/#top_level-default_language_version
57-
language_version: python3.12
5857
# Make sure Sphinx can build the documentation while explicitly omitting
5958
# notebooks from the docs, so users don't have to wait through the execution
6059
# of each notebook or each commit. By default, these will be checked in the

scripts/generic_search_config.yaml

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ clip_negative: false
44
cluster_eps: 120.0
55
cluster_type: nn_start_end
66
cluster_v_scale: 1.0
7-
coadds: []
87
debug: true
98
do_clustering: true
109
do_mask: true
@@ -14,44 +13,38 @@ gpu_filter: true
1413
generator_config:
1514
angle_units: degree
1615
angles:
17-
- 90
18-
- -90
19-
- 64
16+
- 90
17+
- -90
18+
- 64
2019
given_ecliptic: null
2120
name: EclipticCenteredSearch
2221
velocities:
23-
- 25.0
24-
- 225.0
25-
- 64
22+
- 25.0
23+
- 225.0
24+
- 64
2625
velocity_units: pix / d
2726
im_filepath: null
2827
legacy_filename: null
2928
lh_level: 5.0
3029
max_lh: 10000.0
31-
mom_lims:
32-
- 35.5
33-
- 35.5
34-
- 2.0
35-
- 0.3
36-
- 0.3
3730
num_obs: 7
3831
peak_offset:
39-
- 2.0
40-
- 2.0
32+
- 2.0
33+
- 2.0
4134
psf_val: 1.4
4235
res_filepath: /sdf/home/c/colinc/rubin-user/20X20_patch250060
4336
result_filename: /sdf/home/c/colinc/rubin-user/20X20_patch250060/full_results.ecsv
4437
results_per_pixel: 4
4538
save_all_stamps: False
4639
sigmaG_lims:
47-
- 25
48-
- 75
40+
- 25
41+
- 75
4942
stamp_radius: 50
5043
coadds:
51-
- sum
52-
- mean
53-
- median
54-
- weighted
44+
- sum
45+
- mean
46+
- median
47+
- weighted
5548
stamp_type: sum
5649
track_filtered: false
5750
x_pixel_bounds: null

scripts/parsl_configurator.py

Lines changed: 97 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
script_directory = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
1010

11+
1112
def get_reflex_distance(basedir, mode="collection"):
1213
"""Determine reflex distance, either by filename or by .collection content. 5/5/2025 COC"""
1314
reflex_distance = None
1415
first_ic_path = glob.glob(f"{basedir}/*.collection")[0]
1516
if mode == "collection":
1617
print(f"Determining reflex distances via first row of first collection in {basedir}...")
1718
import kbmod
19+
1820
ic = kbmod.ImageCollection.read(first_ic_path)
1921
reflex_distance = ic["helio_guess_dist"][0]
2022
else:
@@ -25,10 +27,18 @@ def get_reflex_distance(basedir, mode="collection"):
2527
return reflex_distance
2628

2729

28-
def make_toml_file(basedir, generic_toml_path, site_name="Rubin", disable_cleanup=False, nworkers=32, repo_path="/repo/main", reflex_distances=None):
30+
def make_toml_file(
31+
basedir,
32+
generic_toml_path,
33+
site_name="Rubin",
34+
disable_cleanup=False,
35+
nworkers=32,
36+
repo_path="/repo/main",
37+
reflex_distances=None,
38+
):
2939
#
3040
if reflex_distances == None:
31-
print(f'WARNING: default reflex distances hardcoded to [39.0]')
41+
print(f"WARNING: default reflex distances hardcoded to [39.0]")
3242
reflex_distances = [39.0]
3343
lookup_dict = {}
3444
lookup_dict["____basedir____"] = basedir
@@ -46,7 +56,7 @@ def make_toml_file(basedir, generic_toml_path, site_name="Rubin", disable_cleanu
4656
with open(generic_toml_path, "r") as g:
4757
for line in g:
4858
line = line.strip()
49-
if line.startswith("#") or len(line.strip()) == 0: # comment or blank line
59+
if line.startswith("#") or len(line.strip()) == 0: # comment or blank line
5060
print(line, file=f)
5161
continue
5262
found_key = False
@@ -57,7 +67,7 @@ def make_toml_file(basedir, generic_toml_path, site_name="Rubin", disable_cleanu
5767
break
5868
if found_key == True:
5969
continue
60-
print(line, file=f) # catch-all
70+
print(line, file=f) # catch-all
6171
print(f"Finished writing {outfile} to disk.")
6272

6373

@@ -81,9 +91,6 @@ def make_sbatch_file(generic_sbatch_file, basedir, comment=None):
8191
with open(generic_sbatch_file, "r") as g:
8292
for line in g:
8393
line = line.rstrip("\n")
84-
# if line.startswith("#") or len(line) == 0:
85-
# print(line, file=f)
86-
# continue
8794
found_key = False
8895
for key in lookup_dict:
8996
if key in line:
@@ -93,32 +100,91 @@ def make_sbatch_file(generic_sbatch_file, basedir, comment=None):
93100
if found_key == True:
94101
continue
95102
print(line, file=f)
96-
print(f'Wrote {outfile} to disk.')
103+
print(f"Wrote {outfile} to disk.")
97104
return outfile
98105

106+
99107
def make_yaml_file(generic_yaml_file, basedir):
100108
yaml_outfile = f"{basedir}/search_config.yaml"
101-
with open(generic_yaml_file, 'r') as g:
102-
with open(yaml_outfile, 'w') as f:
109+
with open(generic_yaml_file, "r") as g:
110+
with open(yaml_outfile, "w") as f:
103111
for line in g:
104112
line = line.rstrip("\n")
105113
print(line, file=f)
106-
print(f'Wrote {yaml_outfile} to disk.')
114+
print(f"Wrote {yaml_outfile} to disk.")
107115
return yaml_outfile
108116

109117

110-
if __name__ == '__main__':
118+
if __name__ == "__main__":
111119
import argparse
112-
parser = argparse.ArgumentParser(description='Tool to generate .toml files for Parsl Workflow.') # 4/21/2025 COC
113-
parser.add_argument('--basedir', dest='basedir', help='path to staging directory containing ImageCollections. Default: current working directory.', type=str, default=os.getcwd())
114-
parser.add_argument('--reflex-distances', dest='reflex_distances', help='reflex-correction distances; default is None, which results in the directory being crawled and the first reflex-distance found in an ImageCollection is used. There should only be one distance, but multiple are supported.', type=float, default=None, nargs='+')
115-
parser.add_argument('--site-name', dest='site_name', help='Observatory site name. Default: "Rubin"', type=str, default="Rubin")
116-
parser.add_argument('--disable-cleanup', dest='disable_cleanup', help='disable deletion of reprojected WorkUnits after successful run. Default: False', type=bool, default=False)
117-
parser.add_argument('--nworkers', dest='nworkers', help='number of workers (cores) to assume. Default: 32', type=int, default=32)
118-
parser.add_argument('--repo-path', dest='repo_path', help='Butler repository path. Default: /repo/main', type=str, default="/repo/main")
119-
parser.add_argument('--generic-toml-path', dest='generic_toml_path', help='Path to a special generic TOML file. Default: ~/generic_runtime_config.toml', type=str, default=f"{script_directory}/generic_runtime_config.toml")
120-
parser.add_argument('--generic-sbatch-path', dest='generic_sbatch_path', help='Path to a special generic sbatch file. Default: ~/generic_parent_parsl_sbatch.sh', type=str, default=f"{script_directory}/generic_parent_parsl_sbatch.sh")
121-
parser.add_argument('--generic-yaml-path', dest='generic_yaml_path', help='Path to a special generic kbmod search config yaml file. Default: ~/generic_search_config.yaml', type=str, default=f"{script_directory}/generic_search_config.yaml")
120+
121+
parser = argparse.ArgumentParser(
122+
description="Tool to generate .toml files for Parsl Workflow."
123+
) # 4/21/2025 COC
124+
parser.add_argument(
125+
"--basedir",
126+
dest="basedir",
127+
help="path to staging directory containing ImageCollections. Default: current working directory.",
128+
type=str,
129+
default=os.getcwd(),
130+
)
131+
parser.add_argument(
132+
"--reflex-distances",
133+
dest="reflex_distances",
134+
help="reflex-correction distances; default is None, which results in the directory being crawled and the first reflex-distance found in an ImageCollection is used. There should only be one distance, but multiple are supported.",
135+
type=float,
136+
default=None,
137+
nargs="+",
138+
)
139+
parser.add_argument(
140+
"--site-name",
141+
dest="site_name",
142+
help='Observatory site name. Default: "Rubin"',
143+
type=str,
144+
default="Rubin",
145+
)
146+
parser.add_argument(
147+
"--disable-cleanup",
148+
dest="disable_cleanup",
149+
help="disable deletion of reprojected WorkUnits after successful run. Default: False",
150+
type=bool,
151+
default=False,
152+
)
153+
parser.add_argument(
154+
"--nworkers",
155+
dest="nworkers",
156+
help="number of workers (cores) to assume. Default: 32",
157+
type=int,
158+
default=32,
159+
)
160+
parser.add_argument(
161+
"--repo-path",
162+
dest="repo_path",
163+
help="Butler repository path. Default: /repo/main",
164+
type=str,
165+
default="/repo/main",
166+
)
167+
parser.add_argument(
168+
"--generic-toml-path",
169+
dest="generic_toml_path",
170+
help="Path to a special generic TOML file. Default: ~/generic_runtime_config.toml",
171+
type=str,
172+
default=f"{script_directory}/generic_runtime_config.toml",
173+
)
174+
parser.add_argument(
175+
"--generic-sbatch-path",
176+
dest="generic_sbatch_path",
177+
help="Path to a special generic sbatch file. Default: ~/generic_parent_parsl_sbatch.sh",
178+
type=str,
179+
default=f"{script_directory}/generic_parent_parsl_sbatch.sh",
180+
)
181+
parser.add_argument(
182+
"--generic-yaml-path",
183+
dest="generic_yaml_path",
184+
help="Path to a special generic kbmod search config yaml file. Default: ~/generic_search_config.yaml",
185+
type=str,
186+
default=f"{script_directory}/generic_search_config.yaml",
187+
)
122188
#
123189
args = parser.parse_args()
124190
#
@@ -127,14 +193,15 @@ def make_yaml_file(generic_yaml_file, basedir):
127193
reflex_distances = args.reflex_distances
128194
if reflex_distances == None or reflex_distances == []:
129195
reflex_distances = [get_reflex_distance(basedir=args.basedir)]
130-
make_toml_file(basedir=args.basedir,
131-
generic_toml_path=args.generic_toml_path,
132-
site_name=args.site_name,
133-
disable_cleanup=args.disable_cleanup,
134-
nworkers=args.nworkers,
135-
repo_path=args.repo_path,
136-
reflex_distances=reflex_distances
137-
)
196+
make_toml_file(
197+
basedir=args.basedir,
198+
generic_toml_path=args.generic_toml_path,
199+
site_name=args.site_name,
200+
disable_cleanup=args.disable_cleanup,
201+
nworkers=args.nworkers,
202+
repo_path=args.repo_path,
203+
reflex_distances=reflex_distances,
204+
)
138205
make_sbatch_file(generic_sbatch_file=args.generic_sbatch_path, basedir=args.basedir)
139206
make_yaml_file(generic_yaml_file=args.generic_yaml_path, basedir=args.basedir)
140207
#

src/kbmod_wf/resource_configs/dev_configuration.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ def dev_resource_config():
1313
return Config(
1414
# put the log files in in the top level folder, "run_logs".
1515
run_dir=os.path.join(project_dir, "run_logs", datetime.date.today().isoformat()),
16-
app_cache=True,
17-
checkpoint_mode="task_exit",
18-
checkpoint_files=get_all_checkpoints(
19-
os.path.join(project_dir, "run_logs", datetime.date.today().isoformat())
20-
),
2116
executors=[
2217
ThreadPoolExecutor(
2318
label="local_dev_testing",

src/kbmod_wf/resource_configs/klone_configuration.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515

1616
def klone_resource_config():
1717
return Config(
18-
app_cache=True,
19-
checkpoint_mode="task_exit",
20-
checkpoint_files=get_all_checkpoints(
21-
os.path.join("/gscratch/dirac/kbmod/workflow/run_logs", datetime.date.today().isoformat())
22-
),
2318
run_dir=os.path.join("/gscratch/dirac/kbmod/workflow/run_logs", datetime.date.today().isoformat()),
2419
retries=1,
2520
executors=[

0 commit comments

Comments
 (0)