33from abc import ABC , abstractmethod
44from datetime import datetime
55from os .path import join , abspath , relpath , normpath , dirname , exists
6- from typing import Sequence , Union , TYPE_CHECKING , Any
6+ from typing import Sequence , Union , TYPE_CHECKING , Any , Optional
77
88from floatcsep .utils .helpers import timewindow2str
99
@@ -149,6 +149,7 @@ def factory(cls, registry_type: str = 'file', **kwargs) -> "ModelRegistry":
149149class ModelFileRegistry (ModelRegistry , FilepathMixin ):
150150 def __init__ (
151151 self ,
152+ model_name : str ,
152153 workdir : str ,
153154 path : str ,
154155 database : str = None ,
@@ -159,19 +160,25 @@ def __init__(
159160 """
160161
161162 Args:
163+ model_name (str): Model's identifier string
162164 workdir (str): The current working directory of the experiment.
163165 path (str): The path of the model working directory (or model filepath).
164166 database (str): The path of the database, in case forecasts are stored therein.
165167 args_file (str): The path of the arguments file (only for TimeDependentModel).
166168 input_cat (str): : The path of the arguments file (only for TimeDependentModel).
167169 """
168170
171+ self .model_name = model_name
169172 self .workdir = workdir
170173 self .path = path
171174 self .database = database
172175 self .args_file = args_file
173176 self .input_cat = input_cat
177+
174178 self .forecasts = {}
179+ self .input_args = {}
180+ self .input_cats = {}
181+ self .input_store = None
175182 self ._fmt = fmt
176183
177184 @property
@@ -227,7 +234,7 @@ def get_input_catalog_key(self, *args: Sequence[str]) -> str:
227234 Returns:
228235 The input catalog registry key from a sequence of key values
229236 """
230- return self .get_attr ("input_cat " , * args )
237+ return self .get_attr ("input_cats " , * args )
231238
232239 def get_forecast_key (self , * args : Sequence [str ]) -> str :
233240 """
@@ -253,15 +260,15 @@ def get_args_key(self, *args: Sequence[str]) -> str:
253260 Returns:
254261 The argument file's key(s) from a sequence of key values
255262 """
256- return self .get_attr ("args_file " , * args )
263+ return self .get_attr ("input_args " , * args )
257264
258265 def build_tree (
259266 self ,
260267 time_windows : Sequence [Sequence [datetime ]] = None ,
261268 model_class : str = "TimeIndependentModel" ,
262269 prefix : str = None ,
263- args_file : str = None ,
264- input_cat : str = None
270+ run_mode : str = 'sequential' ,
271+ run_dir : Optional [ str ] = None
265272 ) -> None :
266273 """
267274 Creates the run directory, and reads the file structure inside.
@@ -270,33 +277,43 @@ def build_tree(
270277 time_windows (list(str)): List of time windows or strings.
271278 model_class (str): Model's class name
272279 prefix (str): prefix of the model forecast filenames if TD
273- args_file (str, bool): input arguments path of the model if TD
274- input_cat (str, bool): input catalog path of the model if TD
275- fmt (str, bool): for time dependent mdoels
276-
280+ run_mode (str): if run mode is sequential, input data (args and cat) will be
281+ dynamically overwritten in 'model/input/` through time_windows. If 'parallel',
282+ input data is dynamically writing anew in
283+ 'results/{time_window}/input/{model_name}/'.
284+ run_dir (str): Where experiment's results are stored.
277285 """
278286
279287 windows = timewindow2str (time_windows )
280-
281288 if model_class == "TimeIndependentModel" :
282289 fname = self .database if self .database else self .path
283290 self .forecasts = {win : fname for win in windows }
284291
285292 elif model_class == "TimeDependentModel" :
286293
287- args = args_file if args_file else join ("input" , "args.txt" )
288- self .args_file = join (self .path , args )
289- input_cat = input_cat if input_cat else join ("input" , "catalog.csv" )
290- self .input_cat = join (self .path , input_cat )
291- # grab names for creating directories
294+ # grab names for creating model directories
292295 subfolders = ["input" , "forecasts" ]
293296 dirtree = {folder : self .abs (self .path , folder ) for folder in subfolders }
294-
295- # create directories if they don't exist
296297 for _ , folder_ in dirtree .items ():
297298 os .makedirs (folder_ , exist_ok = True )
298299
299- # set forecast names
300+ if run_mode == 'sequential' :
301+ self .input_args = {
302+ win : join (self .path , 'input' , self .args_file ) for win in windows
303+ }
304+ self .input_cats = {
305+ win : join (self .path , 'input' , self .input_cat ) for win in windows
306+ }
307+ elif run_mode == 'parallel' :
308+ self .input_args = {
309+ win : join (run_dir , win , 'input' , self .model_name , self .args_file )
310+ for win in windows
311+ }
312+ self .input_cats = {
313+ win : join (run_dir , win , 'input' , self .model_name , self .input_cat )
314+ for win in windows
315+ }
316+
300317 self .forecasts = {
301318 win : join (dirtree ["forecasts" ], f"{ prefix } _{ win } .{ self .fmt } " ) for win in windows
302319 }
@@ -492,6 +509,7 @@ def build_tree(
492509 time_windows : Sequence [Sequence [datetime ]],
493510 models : Sequence ["Model" ],
494511 tests : Sequence ["Evaluation" ],
512+ run_mode : str = 'sequential'
495513 ) -> None :
496514 """
497515 Creates the run directory and reads the file structure inside.
@@ -500,6 +518,7 @@ def build_tree(
500518 time_windows: List of time windows, or representing string.
501519 models: List of models or model names
502520 tests: List of tests or test names
521+ run_mode: 'parallel' or 'sequential'
503522
504523 """
505524 windows = timewindow2str (time_windows )
@@ -509,6 +528,8 @@ def build_tree(
509528
510529 run_folder = self .run_dir
511530 subfolders = ["catalog" , "evaluations" , "figures" ]
531+ if run_mode == 'parallel' :
532+ subfolders .append ('input' )
512533 dirtree = {
513534 win : {folder : self .abs (run_folder , win , folder ) for folder in subfolders }
514535 for win in windows
@@ -518,7 +539,11 @@ def build_tree(
518539 for tw , tw_folder in dirtree .items ():
519540 for _ , folder_ in tw_folder .items ():
520541 os .makedirs (folder_ , exist_ok = True )
521-
542+ print (folder_ )
543+ if run_mode == 'parallel' and folder_ .endswith ('input' ):
544+ print ('a' )
545+ for model in models :
546+ os .makedirs (join (folder_ , model ), exist_ok = True )
522547 results = {
523548 win : {
524549 test : {
0 commit comments