easyvvuq.encoders.copy_encoder
An encoder meant to simply copy a file to the input directory unchanged. It is meant to be used in combination with MultiBuilder encoder and possibly the DirectoryBuilder. It duplicates some functionality of the ApplyFixtures encoder but can be useful for very simple cases.
Examples
>>> multiencoder = uq.encoders.MultiEncoder(
DirectoryBuilder(tree={"parent" : {"child1" : None, "child2" : None}}),
CopyEncoder('/home/user/input1.conf', 'parent/child1/input1.conf')
CopyEncoder('/home/user/input2.conf', 'parent/child1/input2.conf')
CopyEncoder('/home/user/input3.conf', 'parent/child2/input3.conf')
GenericEncoder(delimiter='$', template_fname='/home/user/template.in',
target_filename='parent/input.int'))
1"""An encoder meant to simply copy a file to the input directory unchanged. 2It is meant to be used in combination with MultiBuilder encoder and possibly 3the DirectoryBuilder. It duplicates some functionality of the ApplyFixtures 4encoder but can be useful for very simple cases. 5 6Examples 7-------- 8>>> multiencoder = uq.encoders.MultiEncoder( 9 DirectoryBuilder(tree={"parent" : {"child1" : None, "child2" : None}}), 10 CopyEncoder('/home/user/input1.conf', 'parent/child1/input1.conf') 11 CopyEncoder('/home/user/input2.conf', 'parent/child1/input2.conf') 12 CopyEncoder('/home/user/input3.conf', 'parent/child2/input3.conf') 13 GenericEncoder(delimiter='$', template_fname='/home/user/template.in', 14 target_filename='parent/input.int')) 15""" 16 17import os 18import shutil 19 20 21class CopyEncoder: 22 """An Encoder to copy an input file to a simulation. 23 24 Parameters 25 ---------- 26 source_filename : str 27 a full path to some file that a simulation needs 28 29 target_filename : str 30 a target filename inside the simulation directory 31 """ 32 33 def __init__(self, source_filename, target_filename): 34 self.source_filename = source_filename 35 self.target_filename = target_filename 36 if not os.path.isfile(self.source_filename): 37 raise RuntimeError("Specified source file does not exist:", source_filename) 38 39 def encode(self, params={}, target_dir=''): 40 """Copy a file to target_dir. 41 42 Parameters 43 ---------- 44 params : dict 45 keep empty, has no effect 46 47 target_dir : str 48 target directory, full path 49 """ 50 if not os.path.isdir(target_dir): 51 raise RuntimeError("Specified target directory does not exist:", target_dir) 52 shutil.copyfile(self.source_filename, os.path.join(target_dir, self.target_filename)) 53 54 def get_restart_dict(self): 55 return {"source_filename": self.source_filename, 56 "target_filename": self.target_filename} 57 58 def element_version(self): 59 return "0.1"
class
CopyEncoder:
22class CopyEncoder: 23 """An Encoder to copy an input file to a simulation. 24 25 Parameters 26 ---------- 27 source_filename : str 28 a full path to some file that a simulation needs 29 30 target_filename : str 31 a target filename inside the simulation directory 32 """ 33 34 def __init__(self, source_filename, target_filename): 35 self.source_filename = source_filename 36 self.target_filename = target_filename 37 if not os.path.isfile(self.source_filename): 38 raise RuntimeError("Specified source file does not exist:", source_filename) 39 40 def encode(self, params={}, target_dir=''): 41 """Copy a file to target_dir. 42 43 Parameters 44 ---------- 45 params : dict 46 keep empty, has no effect 47 48 target_dir : str 49 target directory, full path 50 """ 51 if not os.path.isdir(target_dir): 52 raise RuntimeError("Specified target directory does not exist:", target_dir) 53 shutil.copyfile(self.source_filename, os.path.join(target_dir, self.target_filename)) 54 55 def get_restart_dict(self): 56 return {"source_filename": self.source_filename, 57 "target_filename": self.target_filename} 58 59 def element_version(self): 60 return "0.1"
An Encoder to copy an input file to a simulation.
Parameters
- source_filename (str): a full path to some file that a simulation needs
- target_filename (str): a target filename inside the simulation directory
def
encode(self, params={}, target_dir=''):
40 def encode(self, params={}, target_dir=''): 41 """Copy a file to target_dir. 42 43 Parameters 44 ---------- 45 params : dict 46 keep empty, has no effect 47 48 target_dir : str 49 target directory, full path 50 """ 51 if not os.path.isdir(target_dir): 52 raise RuntimeError("Specified target directory does not exist:", target_dir) 53 shutil.copyfile(self.source_filename, os.path.join(target_dir, self.target_filename))
Copy a file to target_dir.
Parameters
- params (dict): keep empty, has no effect
- target_dir (str): target directory, full path