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,27 +194,40 @@ def checkout(self):
189194
190195 print ("" )
191196
192- def build (self ):
197+ def build (self , mpi = None , clean = False ):
193198 """Endpoint for `benchcab build`."""
194199 for repo in self .repos :
195- repo .build (modules = self .config ["modules" ], verbose = self .args .verbose )
200+ repo .build (
201+ modules = self .config ["modules" ],
202+ verbose = self .args .verbose ,
203+ mpi = mpi if mpi else self .args .mpi ,
204+ clean = clean ,
205+ )
196206 print (f"Successfully compiled CABLE for realisation { repo .name } " )
197207 print ("" )
198208
199209 def fluxsite_setup_work_directory (self ):
200210 """Endpoint for `benchcab fluxsite-setup-work-dir`."""
201- tasks = self .tasks if self .tasks else self ._initialise_tasks ()
211+
212+ if not self .fluxsite_tasks :
213+ self ._initialise_tasks ()
214+
202215 print ("Setting up run directory tree for fluxsite tests..." )
203- setup_fluxsite_directory_tree (fluxsite_tasks = tasks , verbose = self .args .verbose )
216+ setup_fluxsite_directory_tree (
217+ fluxsite_tasks = self .fluxsite_tasks , verbose = self .args .verbose
218+ )
204219 print ("Setting up tasks..." )
205- for task in tasks :
220+ for task in self . fluxsite_tasks :
206221 task .setup_task (verbose = self .args .verbose )
207222 print ("Successfully setup fluxsite tasks" )
208223 print ("" )
209224
210225 def fluxsite_run_tasks (self ):
211226 """Endpoint for `benchcab fluxsite-run-tasks`."""
212- tasks = self .tasks if self .tasks else self ._initialise_tasks ()
227+
228+ if not self .fluxsite_tasks :
229+ self ._initialise_tasks ()
230+
213231 print ("Running fluxsite tasks..." )
214232 try :
215233 multiprocess = self .config ["fluxsite" ]["multiprocess" ]
@@ -219,9 +237,11 @@ def fluxsite_run_tasks(self):
219237 ncpus = self .config .get ("pbs" , {}).get (
220238 "ncpus" , internal .FLUXSITE_DEFAULT_PBS ["ncpus" ]
221239 )
222- run_tasks_in_parallel (tasks , n_processes = ncpus , verbose = self .args .verbose )
240+ fluxsite .run_tasks_in_parallel (
241+ self .fluxsite_tasks , n_processes = ncpus , verbose = self .args .verbose
242+ )
223243 else :
224- run_tasks (tasks , verbose = self .args .verbose )
244+ fluxsite . run_tasks (self . fluxsite_tasks , verbose = self .args .verbose )
225245 print ("Successfully ran fluxsite tasks" )
226246 print ("" )
227247
@@ -233,8 +253,10 @@ def fluxsite_bitwise_cmp(self):
233253 "nccmp/1.8.5.0"
234254 ) # use `nccmp -df` for bitwise comparisons
235255
236- tasks = self .tasks if self .tasks else self ._initialise_tasks ()
237- comparisons = get_fluxsite_comparisons (tasks )
256+ if not self .fluxsite_tasks :
257+ self ._initialise_tasks ()
258+
259+ comparisons = fluxsite .get_fluxsite_comparisons (self .fluxsite_tasks )
238260
239261 print ("Running comparison tasks..." )
240262 try :
@@ -265,13 +287,38 @@ def fluxsite(self):
265287 else :
266288 self .fluxsite_submit_job ()
267289
290+ def spatial_setup_work_directory (self ):
291+ """Endpoint for `benchcab spatial-setup-work-dir`."""
292+ print ("Setting up run directory tree for spatial tests..." )
293+ setup_spatial_directory_tree ()
294+ print ("Setting up tasks..." )
295+ for task in self .spatial_tasks :
296+ task .setup_task (verbose = self .args .verbose )
297+ print ("Successfully setup spatial tasks" )
298+ print ("" )
299+
300+ def spatial_run_tasks (self ):
301+ """Endpoint for `benchcab spatial-run-tasks`."""
302+ print ("Running spatial tasks..." )
303+ spatial .run_tasks (tasks = self .spatial_tasks , verbose = self .args .verbose )
304+ print ("" )
305+
268306 def spatial (self ):
269307 """Endpoint for `benchcab spatial`."""
308+ self .checkout ()
309+ self .build (mpi = True )
310+ self .spatial_setup_work_directory ()
311+ self .spatial_run_tasks ()
270312
271313 def run (self ):
272314 """Endpoint for `benchcab run`."""
273- self .fluxsite ()
274- self .spatial ()
315+ self .checkout ()
316+ self .build ()
317+ self .build (mpi = True , clean = True )
318+ self .fluxsite_setup_work_directory ()
319+ self .spatial_setup_work_directory ()
320+ self .fluxsite_submit_job ()
321+ self .spatial_run_tasks ()
275322
276323 def main (self ):
277324 """Main function for `benchcab`."""
0 commit comments