@@ -1921,24 +1921,28 @@ class MPIMapProcessor(Processor):
1921
1921
"""A Processor that applies a parallel generic sub-pipeline to
1922
1922
a map configuration.
1923
1923
"""
1924
- def process (self , data , sub_pipeline = None , inputdir = '.' , outputdir = '.' ,
1925
- interactive = False , log_level = 'INFO' ):
1924
+ def process (self , data , config = None , sub_pipeline = None , inputdir = None ,
1925
+ outputdir = None , interactive = None , log_level = None ):
1926
1926
"""Run a parallel generic sub-pipeline.
1927
1927
1928
1928
:param data: Input data.
1929
1929
:type data: list[PipelineData]
1930
+ :param config: Initialization parameters for an instance of
1931
+ common.models.map.MapConfig.
1932
+ :type config: dict, optional
1930
1933
:param sub_pipeline: The sub-pipeline.
1931
1934
:type sub_pipeline: Pipeline, optional
1932
1935
:param inputdir: Input directory, used only if files in the
1933
- input configuration are not absolute paths,
1934
- defaults to `'.'`.
1936
+ input configuration are not absolute paths.
1935
1937
:type inputdir: str, optional
1936
1938
:param outputdir: Directory to which any output figures will
1937
- be saved, defaults to `'.'` .
1939
+ be saved.
1938
1940
:type outputdir: str, optional
1939
- :param interactive: Allows for user interactions, defaults to
1940
- `False`.
1941
+ :param interactive: Allows for user interactions.
1941
1942
:type interactive: bool, optional
1943
+ :ivar log_level: Logger level (not case sesitive).
1944
+ :type log_level: Literal[
1945
+ 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], optional
1942
1946
:return: The `data` field of the first item in the returned
1943
1947
list of sub-pipeline items.
1944
1948
"""
@@ -1956,11 +1960,24 @@ def process(self, data, sub_pipeline=None, inputdir='.', outputdir='.',
1956
1960
num_proc = comm .Get_size ()
1957
1961
rank = comm .Get_rank ()
1958
1962
1959
- # Get the map configuration from data
1960
- map_config = self .get_config (
1961
- data , 'common.models.map.MapConfig' , inputdir = inputdir )
1963
+ # Get the validated map configuration
1964
+ try :
1965
+ map_config = self .get_config (
1966
+ data , 'common.models.map.MapConfig' , inputdir = inputdir )
1967
+ except :
1968
+ self .logger .info ('No valid Map configuration in input pipeline '
1969
+ 'data, using config parameter instead.' )
1970
+ try :
1971
+ # Local modules
1972
+ from CHAP .common .models .map import MapConfig
1973
+
1974
+ map_config = MapConfig (** config , inputdir = inputdir )
1975
+ except Exception as exc :
1976
+ raise RuntimeError from exc
1962
1977
1963
1978
# Create the spec reader configuration for each processor
1979
+ # FIX: catered to EDD with one spec scan
1980
+ assert len (map_config .spec_scans ) == 1
1964
1981
spec_scans = map_config .spec_scans [0 ]
1965
1982
scan_numbers = spec_scans .scan_numbers
1966
1983
num_scan = len (scan_numbers )
@@ -1985,7 +2002,7 @@ def process(self, data, sub_pipeline=None, inputdir='.', outputdir='.',
1985
2002
run_config = {'inputdir' : inputdir , 'outputdir' : outputdir ,
1986
2003
'interactive' : interactive , 'log_level' : log_level }
1987
2004
run_config .update (sub_pipeline .get ('config' ))
1988
- run_config = RunConfig (** run_config , comm = comm , logger = self . logger )
2005
+ run_config = RunConfig (** run_config , comm = comm )
1989
2006
pipeline_config = []
1990
2007
for item in sub_pipeline ['pipeline' ]:
1991
2008
if isinstance (item , dict ):
@@ -2000,20 +2017,17 @@ def process(self, data, sub_pipeline=None, inputdir='.', outputdir='.',
2000
2017
pipeline_config .append (item )
2001
2018
2002
2019
# Run the sub-pipeline on each processor
2003
- return run (
2004
- pipeline_config , inputdir = run_config .inputdir ,
2005
- outputdir = run_config .outputdir , interactive = run_config .interactive ,
2006
- logger = self .logger , comm = comm )
2020
+ return run (run_config , pipeline_config , logger = self .logger , comm = comm )
2007
2021
2008
2022
2009
2023
class MPISpawnMapProcessor (Processor ):
2010
2024
"""A Processor that applies a parallel generic sub-pipeline to
2011
2025
a map configuration by spawning workers processes.
2012
2026
"""
2013
2027
def process (
2014
- self , data , num_proc = 1 , root_as_worker = True , collect_on_root = True ,
2015
- sub_pipeline = None , inputdir = '.' , outputdir = '.' , interactive = False ,
2016
- log_level = 'INFO' ):
2028
+ self , data , num_proc = 1 , root_as_worker = True , collect_on_root = False ,
2029
+ sub_pipeline = None , inputdir = None , outputdir = None , interactive = None ,
2030
+ log_level = None ):
2017
2031
"""Spawn workers running a parallel generic sub-pipeline.
2018
2032
2019
2033
:param data: Input data.
@@ -2024,7 +2038,7 @@ def process(
2024
2038
defaults to `True`.
2025
2039
:type root_as_worker: bool, optional
2026
2040
:param collect_on_root: Collect the result of the spawned
2027
- workers on the root node, defaults to `True `.
2041
+ workers on the root node, defaults to `False `.
2028
2042
:type collect_on_root: bool, optional
2029
2043
:param sub_pipeline: The sub-pipeline.
2030
2044
:type sub_pipeline: Pipeline, optional
@@ -2038,6 +2052,9 @@ def process(
2038
2052
:param interactive: Allows for user interactions, defaults to
2039
2053
`False`.
2040
2054
:type interactive: bool, optional
2055
+ :ivar log_level: Logger level (not case sesitive).
2056
+ :type log_level: Literal[
2057
+ 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], optional
2041
2058
:return: The `data` field of the first item in the returned
2042
2059
list of sub-pipeline items.
2043
2060
"""
@@ -2144,7 +2161,7 @@ def process(
2144
2161
2145
2162
# Run the sub-pipeline on the root node
2146
2163
if root_as_worker :
2147
- data = runner (run_config , pipeline_config [0 ], common_comm )
2164
+ data = runner (run_config , pipeline_config [0 ], comm = common_comm )
2148
2165
elif collect_on_root :
2149
2166
run_config .spawn = 0
2150
2167
pipeline_config = [{'common.MPICollectProcessor' : {
@@ -2158,7 +2175,10 @@ def process(
2158
2175
2159
2176
# Disconnect spawned workers and cleanup temporary files
2160
2177
if num_proc > first_proc :
2178
+ # Align with the barrier in main() on common_comm
2179
+ # when disconnecting the spawned worker
2161
2180
common_comm .barrier ()
2181
+ # Disconnect spawned workers and cleanup temporary files
2162
2182
sub_comm .Disconnect ()
2163
2183
for tmp_name in tmp_names :
2164
2184
os .remove (tmp_name )
0 commit comments