Skip to content

Commit 6f705b1

Browse files
committed
Added the ability of uploading custom libraries for RMG T3 runs
1 parent f689590 commit 6f705b1

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

requirements.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

t3/runners/rmg_adapter.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def __init__(self,
5555
server: str=None,
5656
testing: bool=False,
5757
):
58-
self.rmg = rmg
59-
self.t3 = t3
58+
self.rmg = rmg.copy()
59+
self.t3 = t3.copy()
6060
self.iteration = iteration
6161
self.paths = paths
6262
self.walltime = walltime
@@ -84,6 +84,26 @@ def __init__(self,
8484
self.rmg_errors = list()
8585
self.rmg_run_count = 0
8686
self.cont_run_rmg = True
87+
self.dict_of_custom_libraries = dict()
88+
if self.rmg_execution_type == 'queue':
89+
self.set_file_paths()
90+
# We need to check if the strings in the rmg database kintetic library are path to the files
91+
for library_key, library_value in self.rmg['database'].items():
92+
if isinstance(library_value, list):
93+
for library_item in range(len(library_value)):
94+
if os.path.isdir(self.rmg['database'][library_key][library_item]):
95+
96+
# Make the library item name the key, and then inside that key there are two keys: local and remote
97+
# The local key will be the path to the library item on the local machine
98+
# The remote key will be the path to the library item on the remote machine
99+
if os.path.basename(self.rmg['database'][library_key][library_item]) not in self.dict_of_custom_libraries:
100+
self.dict_of_custom_libraries[os.path.basename(self.rmg['database'][library_key][library_item])] = dict()
101+
self.dict_of_custom_libraries[os.path.basename(self.rmg['database'][library_key][library_item])]['local'] = self.rmg['database'][library_key][library_item]
102+
self.dict_of_custom_libraries[os.path.basename(self.rmg['database'][library_key][library_item])]['remote'] = os.path.join(self.remote_path, os.path.basename(self.rmg['database'][library_key][library_item]))
103+
# Add the library item to the dict of custom libraries
104+
# We now need to change it's path to the path on the server
105+
self.rmg['database'][library_key][library_item] = os.path.join(self.remote_path, os.path.basename(self.rmg['database'][library_key][library_item]))
106+
87107

88108
def run_rmg(self):
89109
"""
@@ -483,6 +503,16 @@ def set_files(self) -> None:
483503
file_name=submit_filenames[CLUSTER_SOFT]))
484504
# 1.2. RMG input file
485505
self.write_rmg_input_file()
506+
# 1.3 Custom Libraries
507+
# Need to upload the custom libraries if they exist and are not already uploaded
508+
if self.dict_of_custom_libraries:
509+
for lib_name, lib_paths in self.dict_of_custom_libraries.items():
510+
if lib_paths['local'] not in self.files_to_upload:
511+
self.files_to_upload.append(self.get_file_property_dictionary(
512+
file_name=lib_name,
513+
local=lib_paths['local'],
514+
remote=lib_paths['remote']))
515+
486516
# If this a restart, we need to upload the restart file
487517
if self.restart_rmg:
488518
restart_string = "restartFromSeed(path='seed')"

t3/utils/ssh.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,30 @@ def upload_file(self,
151151
if not local_file_path and not file_string:
152152
raise InputError('Cannot upload file to server. Either `file_string` or `local_file_path`'
153153
' must be specified')
154-
if local_file_path and not os.path.isfile(local_file_path):
154+
if local_file_path and not os.path.isfile(local_file_path) and not os.path.isdir(local_file_path):
155155
raise InputError(f'Cannot upload a non-existing file. '
156156
f'Check why file in path {local_file_path} is missing.')
157+
157158
# If the directory does not exist, _upload_file cannot create a file based on the given path
158-
remote_dir_path = os.path.dirname(remote_file_path)
159+
if os.path.isdir(local_file_path):
160+
remote_dir_path = remote_file_path
161+
else:
162+
remote_dir_path = os.path.dirname(remote_file_path)
159163
if not self._check_dir_exists(remote_dir_path):
160164
self._create_dir(remote_dir_path)
161165

162166
try:
163167
if file_string:
164168
with self._sftp.open(remote_file_path, 'w') as f_remote:
165169
f_remote.write(file_string)
170+
171+
elif os.path.isdir(local_file_path):
172+
for root, dirs, files in os.walk(local_file_path):
173+
for file in files:
174+
local_file_path = os.path.join(root, file)
175+
remote_file_path = os.path.join(remote_dir_path, file)
176+
self._sftp.put(localpath=local_file_path,
177+
remotepath=remote_file_path)
166178
else:
167179
self._sftp.put(localpath=local_file_path,
168180
remotepath=remote_file_path)

0 commit comments

Comments
 (0)