MCPcopy Create free account
hub / github.com/M-Nauta/ProtoTree / save_args

Function save_args

util/args.py:157–177  ·  view source on GitHub ↗

Save the arguments in the specified directory as - a text file called 'args.txt' - a pickle file called 'args.pickle' :param args: The arguments to be saved :param directory_path: The path to the directory where the arguments should be saved

(args: argparse.Namespace, directory_path: str)

Source from the content-addressed store, hash-verified

155 return milestones_list
156
157def save_args(args: argparse.Namespace, directory_path: str) -> None:
158 """
159 Save the arguments in the specified directory as
160 - a text file called 'args.txt'
161 - a pickle file called 'args.pickle'
162 :param args: The arguments to be saved
163 :param directory_path: The path to the directory where the arguments should be saved
164 """
165 # If the specified directory does not exists, create it
166 if not os.path.isdir(directory_path):
167 os.mkdir(directory_path)
168 # Save the args in a text file
169 with open(directory_path + '/args.txt', 'w') as f:
170 for arg in vars(args):
171 val = getattr(args, arg)
172 if isinstance(val, str): # Add quotation marks to indicate that the argument is of string type
173 val = f"'{val}'"
174 f.write('{}: {}\n'.format(arg, val))
175 # Pickle the args for possible reuse
176 with open(directory_path + '/args.pickle', 'wb') as f:
177 pickle.dump(args, f)
178
179
180def load_args(directory_path: str) -> argparse.Namespace:

Callers 3

run_ensembleFunction · 0.90
run_treeFunction · 0.90
log_argsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected