@@ -55,9 +55,13 @@ def preliminary_yaml_parsing(self):
55
55
56
56
"""
57
57
# open the file, an error will be thrown if invalid yaml?
58
- user_file = open (self .input_file , mode = 'r' )
59
- self .yaml_dict = yaml .load (user_file , Loader = yaml .FullLoader )
60
- user_file .close ()
58
+ if isinstance (self .input_file , dict ):
59
+ self .yaml_dict = self .input_file
60
+ elif (isinstance (self .input_file , str ) or
61
+ isinstance (self .input_file , Path )):
62
+ self .yaml_dict = self ._open_yaml (self .input_file )
63
+ else :
64
+ raise ValueError ('Invalid input file argument.' )
61
65
62
66
if 'ensemble' in self .yaml_dict .keys ():
63
67
self ._has_ensemble = True
@@ -75,6 +79,27 @@ def preliminary_yaml_parsing(self):
75
79
76
80
return self .yaml_dict
77
81
82
+ def _open_yaml (self , input_file ):
83
+ """Safely open, read, and close a yaml file.
84
+
85
+ Parameters
86
+ ----------
87
+ input file
88
+ string or path to file
89
+
90
+ Returns
91
+ -------
92
+ yaml_dict
93
+ yaml file, as a Python dict
94
+ """
95
+ if (input_file is None ):
96
+ return {} # return an empty dict
97
+ else :
98
+ user_file = open (input_file , mode = 'r' )
99
+ yaml_dict = yaml .load (user_file , Loader = yaml .FullLoader )
100
+ user_file .close ()
101
+ return yaml_dict
102
+
78
103
def _create_matrix (self ):
79
104
"""Create a matrix if not already in the yaml.
80
105
@@ -310,6 +335,9 @@ def run_jobs(self):
310
335
num_parallel_processes = _parallel_flag
311
336
else :
312
337
num_parallel_processes = 1
338
+ # number of parallel processes is never greater than number of jobs
339
+ num_parallel_processes = np .minimum (
340
+ num_parallel_processes , num_total_processes )
313
341
314
342
_msg = 'Running %g parallel jobs' % num_parallel_processes
315
343
if self .verbose >= 1 :
@@ -324,10 +352,15 @@ def run_jobs(self):
324
352
# loop and create and start all jobs
325
353
for i in range (0 , num_total_processes ):
326
354
s .acquire () # aquire resource from Semaphore
355
+
356
+ # open yaml file for specific job
357
+ job_yaml = self ._open_yaml (self .file_list [i ])
358
+
359
+ # instantiate the job
327
360
p = _ParallelJob (i = i , queue = q , sema = s ,
328
361
input_file = self .file_list [i ],
329
362
cli_dict = self .cli_dict ,
330
- yaml_dict = self . yaml_dict )
363
+ yaml_dict = job_yaml )
331
364
self .job_list .append (p )
332
365
p .start ()
333
366
@@ -350,10 +383,14 @@ def run_jobs(self):
350
383
351
384
# loop and create all jobs
352
385
for i in range (0 , num_total_processes ):
386
+
387
+ # open yaml file for specific job
388
+ job_yaml = self ._open_yaml (self .file_list [i ])
389
+
353
390
p = _SerialJob (i = i ,
354
391
input_file = self .file_list [i ],
355
392
cli_dict = self .cli_dict ,
356
- yaml_dict = self . yaml_dict )
393
+ yaml_dict = job_yaml )
357
394
self .job_list .append (p )
358
395
359
396
# run the job(s)
@@ -890,10 +927,10 @@ def scale_relative_sea_level_rise_rate(mmyr, If=1):
890
927
891
928
.. math::
892
929
893
- \widehat{RSLR} = (RSLR / 1000) \cdot \dfrac{1}{I_f \cdot 365.25 \cdot 86400}
930
+ \\ widehat{RSLR} = (RSLR / 1000) \\ cdot \\ dfrac{1}{I_f \\ cdot 365.25 \ \ cdot 86400}
894
931
895
932
This conversion makes it such that when one real-world year has elapsed
896
- (:math:`I_f \cdot 365.25 \cdot 86400` seconds in model time), the relative
933
+ (:math:`I_f \\ cdot 365.25 \ \ cdot 86400` seconds in model time), the relative
897
934
sea level has changed by the number of millimeters specified in the input
898
935
:obj:`mmyr`.
899
936
0 commit comments