1111from benchcab import internal
1212from benchcab .internal import get_met_forcing_file_names
1313from benchcab .config import read_config
14- from benchcab .workdir import setup_fluxsite_directory_tree , setup_src_dir
15- from benchcab .repository import CableRepository
16- from benchcab .fluxsite import (
17- get_fluxsite_tasks ,
18- get_fluxsite_comparisons ,
19- run_tasks ,
20- run_tasks_in_parallel ,
21- Task ,
14+ from benchcab .workdir import (
15+ setup_src_dir ,
16+ setup_fluxsite_directory_tree ,
17+ setup_spatial_directory_tree ,
2218)
19+ from benchcab .repository import CableRepository
20+ from benchcab import fluxsite
21+ from benchcab import spatial
2322from benchcab .comparison import run_comparisons , run_comparisons_in_parallel
2423from benchcab .cli import generate_parser
2524from benchcab .environment_modules import EnvironmentModules , EnvironmentModulesInterface
@@ -48,7 +47,15 @@ def __init__(
4847 CableRepository (** config , repo_id = id )
4948 for id , config in enumerate (self .config ["realisations" ])
5049 ]
51- self .tasks : list [Task ] = [] # initialise fluxsite tasks lazily
50+ self .science_configurations = self .config .get (
51+ "science_configurations" , internal .DEFAULT_SCIENCE_CONFIGURATIONS
52+ )
53+ self .fluxsite_tasks : list [
54+ fluxsite .FluxsiteTask
55+ ] = [] # initialise fluxsite tasks lazily
56+ self .spatial_tasks = spatial .get_spatial_tasks (
57+ repos = self .repos , science_configurations = self .science_configurations
58+ )
5259 self .benchcab_exe_path = benchcab_exe_path
5360
5461 if validate_env :
@@ -103,18 +110,16 @@ def _validate_environment(self, project: str, modules: list):
103110 )
104111 sys .exit (1 )
105112
106- def _initialise_tasks (self ) -> list [Task ]:
113+ def _initialise_tasks (self ) -> list [fluxsite . FluxsiteTask ]:
107114 """A helper method that initialises and returns the `tasks` attribute."""
108- self .tasks = get_fluxsite_tasks (
115+ self .fluxsite_tasks = fluxsite . get_fluxsite_tasks (
109116 repos = self .repos ,
110- science_configurations = self .config .get (
111- "science_configurations" , internal .DEFAULT_SCIENCE_CONFIGURATIONS
112- ),
117+ science_configurations = self .science_configurations ,
113118 fluxsite_forcing_file_names = get_met_forcing_file_names (
114119 self .config ["experiment" ]
115120 ),
116121 )
117- return self .tasks
122+ return self .fluxsite_tasks
118123
119124 def fluxsite_submit_job (self ) -> None :
120125 """Submits the PBS job script step in the fluxsite test workflow."""
@@ -189,7 +194,7 @@ def checkout(self):
189194
190195 print ("" )
191196
192- def build (self ):
197+ def build (self , mpi = False ):
193198 """Endpoint for `benchcab build`."""
194199 for repo in self .repos :
195200 if repo .build_script :
@@ -201,30 +206,38 @@ def build(self):
201206 modules = self .config ["modules" ], verbose = self .args .verbose
202207 )
203208 else :
204- build_mode = "with MPI" if internal . MPI else "serially"
209+ build_mode = "with MPI" if mpi else "serially"
205210 print (f"Compiling CABLE { build_mode } for realisation { repo .name } ..." )
206- repo .pre_build (verbose = self .args .verbose )
211+ repo .pre_build (mpi = mpi , verbose = self .args .verbose )
207212 repo .run_build (
208- modules = self .config ["modules" ], verbose = self .args .verbose
213+ modules = self .config ["modules" ], mpi = mpi , verbose = self .args .verbose
209214 )
210- repo .post_build (verbose = self .args .verbose )
215+ repo .post_build (mpi = mpi , verbose = self .args .verbose )
211216 print (f"Successfully compiled CABLE for realisation { repo .name } " )
212217 print ("" )
213218
214219 def fluxsite_setup_work_directory (self ):
215220 """Endpoint for `benchcab fluxsite-setup-work-dir`."""
216- tasks = self .tasks if self .tasks else self ._initialise_tasks ()
221+
222+ if not self .fluxsite_tasks :
223+ self ._initialise_tasks ()
224+
217225 print ("Setting up run directory tree for fluxsite tests..." )
218- setup_fluxsite_directory_tree (fluxsite_tasks = tasks , verbose = self .args .verbose )
226+ setup_fluxsite_directory_tree (
227+ fluxsite_tasks = self .fluxsite_tasks , verbose = self .args .verbose
228+ )
219229 print ("Setting up tasks..." )
220- for task in tasks :
230+ for task in self . fluxsite_tasks :
221231 task .setup_task (verbose = self .args .verbose )
222232 print ("Successfully setup fluxsite tasks" )
223233 print ("" )
224234
225235 def fluxsite_run_tasks (self ):
226236 """Endpoint for `benchcab fluxsite-run-tasks`."""
227- tasks = self .tasks if self .tasks else self ._initialise_tasks ()
237+
238+ if not self .fluxsite_tasks :
239+ self ._initialise_tasks ()
240+
228241 print ("Running fluxsite tasks..." )
229242 try :
230243 multiprocess = self .config ["fluxsite" ]["multiprocess" ]
@@ -234,9 +247,11 @@ def fluxsite_run_tasks(self):
234247 ncpus = self .config .get ("pbs" , {}).get (
235248 "ncpus" , internal .FLUXSITE_DEFAULT_PBS ["ncpus" ]
236249 )
237- run_tasks_in_parallel (tasks , n_processes = ncpus , verbose = self .args .verbose )
250+ fluxsite .run_tasks_in_parallel (
251+ self .fluxsite_tasks , n_processes = ncpus , verbose = self .args .verbose
252+ )
238253 else :
239- run_tasks (tasks , verbose = self .args .verbose )
254+ fluxsite . run_tasks (self . fluxsite_tasks , verbose = self .args .verbose )
240255 print ("Successfully ran fluxsite tasks" )
241256 print ("" )
242257
@@ -248,8 +263,10 @@ def fluxsite_bitwise_cmp(self):
248263 "nccmp/1.8.5.0"
249264 ) # use `nccmp -df` for bitwise comparisons
250265
251- tasks = self .tasks if self .tasks else self ._initialise_tasks ()
252- comparisons = get_fluxsite_comparisons (tasks )
266+ if not self .fluxsite_tasks :
267+ self ._initialise_tasks ()
268+
269+ comparisons = fluxsite .get_fluxsite_comparisons (self .fluxsite_tasks )
253270
254271 print ("Running comparison tasks..." )
255272 try :
@@ -280,13 +297,38 @@ def fluxsite(self):
280297 else :
281298 self .fluxsite_submit_job ()
282299
300+ def spatial_setup_work_directory (self ):
301+ """Endpoint for `benchcab spatial-setup-work-dir`."""
302+ print ("Setting up run directory tree for spatial tests..." )
303+ setup_spatial_directory_tree ()
304+ print ("Setting up tasks..." )
305+ for task in self .spatial_tasks :
306+ task .setup_task (verbose = self .args .verbose )
307+ print ("Successfully setup spatial tasks" )
308+ print ("" )
309+
310+ def spatial_run_tasks (self ):
311+ """Endpoint for `benchcab spatial-run-tasks`."""
312+ print ("Running spatial tasks..." )
313+ spatial .run_tasks (tasks = self .spatial_tasks , verbose = self .args .verbose )
314+ print ("" )
315+
283316 def spatial (self ):
284317 """Endpoint for `benchcab spatial`."""
318+ self .checkout ()
319+ self .build (mpi = True )
320+ self .spatial_setup_work_directory ()
321+ self .spatial_run_tasks ()
285322
286323 def run (self ):
287324 """Endpoint for `benchcab run`."""
288- self .fluxsite ()
289- self .spatial ()
325+ self .checkout ()
326+ self .build ()
327+ self .build (mpi = True )
328+ self .fluxsite_setup_work_directory ()
329+ self .spatial_setup_work_directory ()
330+ self .fluxsite_submit_job ()
331+ self .spatial_run_tasks ()
290332
291333 def main (self ):
292334 """Main function for `benchcab`."""
@@ -298,7 +340,7 @@ def main(self):
298340 self .checkout ()
299341
300342 if self .args .subcommand == "build" :
301- self .build ()
343+ self .build (mpi = self . args . mpi )
302344
303345 if self .args .subcommand == "fluxsite" :
304346 self .fluxsite ()
0 commit comments