Skip to content

Commit 86e498b

Browse files
authored
Merge pull request #68 from DiamondLightSource/sweepchanges
Yaml generator changes to enable sweep tag
2 parents d680de8 + eb428e3 commit 86e498b

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- method: standard_tomo
2+
module_path: httomo.data.hdf.loaders
3+
- method: find_center_vo
4+
module_path: httomolibgpu.recon.rotation
5+
- method: normalize
6+
module_path: httomolibgpu.prep.normalize
7+
- method: paganin_filter_tomopy
8+
module_path: httomolibgpu.prep.phase
9+
sweep_parameter: alpha
10+
sweep_values: [0.01, 0.001, 0.0001]
11+
- method: FBP3d_tomobar
12+
module_path: httomolibgpu.recon.algorithm

httomo_backends/scripts/yaml_pipelines_generator.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@
3333

3434
CS = ruamel.yaml.comments.CommentedSeq # defaults to block style
3535

36-
3736
class SweepRange:
3837
"""SweepRange class."""
3938

4039
def __init__(self, start, stop, step):
4140
self._start, self._stop, self._step = start, stop, step
4241

43-
4442
def __sweeprange_representer(
4543
dumper: yaml.SafeDumper, swp: SweepRange
4644
) -> yaml.nodes.MappingNode:
@@ -54,6 +52,19 @@ def __sweeprange_representer(
5452
},
5553
)
5654

55+
class SweepManual:
56+
"""SweepManual class."""
57+
58+
def __init__(self, lst):
59+
self._lst = lst
60+
61+
62+
def __sweepmanual_representer(
63+
dumper: yaml.SafeDumper, swp: SweepManual
64+
) -> yaml.nodes.SequenceNode:
65+
"""Represent a sweepmanual as a YAML sequence node."""
66+
return dumper.represent_sequence("!Sweep", swp._lst)
67+
5768

5869
def __represent_none(self, data):
5970
return self.represent_scalar("tag:yaml.org,2002:null", "null")
@@ -86,17 +97,22 @@ def yaml_pipelines_generator(
8697
# a loop over methods in the high-level pipeline file (directive)
8798
methods_no = len(pipeline_file_content)
8899
pipeline_full = CS()
89-
sweep_enabled = False
100+
sweep_enabled_range = False
101+
sweep_enabled_value = False
90102
for i in range(methods_no):
91103
method_content = pipeline_file_content[i]
92104
method_name = method_content["method"]
93105
module_name = method_content["module_path"]
94106
if "sweep_parameter" in method_content:
95107
sweep_parameter = method_content["sweep_parameter"]
96-
sweep_start = method_content["sweep_start"]
97-
sweep_stop = method_content["sweep_stop"]
98-
sweep_step = method_content["sweep_step"]
99-
sweep_enabled = True
108+
if "sweep_start" in method_content:
109+
sweep_start = method_content["sweep_start"]
110+
sweep_stop = method_content["sweep_stop"]
111+
sweep_step = method_content["sweep_step"]
112+
sweep_enabled_range = True
113+
else:
114+
sweep_values = method_content["sweep_values"]
115+
sweep_enabled_value = True
100116

101117
# get the corresponding yaml template from httomo-backends
102118
backend_name = module_name[0 : module_name.find(".")]
@@ -291,13 +307,20 @@ def yaml_pipelines_generator(
291307
)
292308
pipeline_full += yaml_template_method
293309

294-
if sweep_enabled:
310+
if sweep_enabled_range:
295311
pipeline_full[i]["parameters"][sweep_parameter] = SweepRange(
296312
start=sweep_start, stop=sweep_stop, step=sweep_step
297313
)
314+
yaml.representer.add_representer(SweepRange, __sweeprange_representer)
315+
sweep_enabled_range = False
316+
if sweep_enabled_value:
317+
pipeline_full[i]["parameters"][sweep_parameter] = SweepManual(
318+
list(sweep_values)
319+
)
320+
yaml.representer.add_representer(SweepManual, __sweepmanual_representer)
321+
sweep_enabled_value = False
298322

299323
yaml.representer.add_representer(type(None), __represent_none)
300-
yaml.representer.add_representer(SweepRange, __sweeprange_representer)
301324
yaml.dump(pipeline_full, f)
302325

303326
return 0

0 commit comments

Comments
 (0)