def add_jobs(self): """Comment""" # Create main directory for simulation jobs if it doesn't exists self.jobsdir_abspath = self.abspath + '_BATCH' util.tmp_dir('create', self.jobsdir_abspath) # Create directory to store jobs results in main project directory # if it doesn't already exists self.resultsdir_abspath = os.path.join(self.jobsdir_abspath, 'Results') util.tmp_dir('create', self.resultsdir_abspath) # Remove any previously created job self.jobs = [] # Then, add jobs if self._batch: njob = len(self.sample) if self.temp_relpaths: # Get list of all parameters found in template files self.get_parameterlist('templatefiles') self.get_parameterlist('sample') # Check if template files and jobs file contain the same list # of parameters. Raise an error if not if set(self.temp_params).issubset(self.samp_params): for jobID in range(1, njob+1): self.jobs.append(BPSJob(self, jobID)) print("\n%d jobs added to BPSProject instance" % njob) else: print("\nMismatch between template and sample file" + " parameters!\nNo jobs added to BPSproject instance") else: for jobID in range(1, njob+1): self.jobs.append(BPSJob(self, jobID)) print("\n%d jobs added to BPSProject instance" % njob) else: print("\nBPS project not a batch run. Jobs can't be added")
def add_jobs(self): """Add simulation jobs to BPSProject Simulation jobs are created and added to BPSProject only when this function is called. This makes it possible to transform the sample loaded from an external source (done automatically when BPSProject class is initialized if a sample file is found in project directory) prior to creating and adding jobs to the BPSProject. This can come in handy is the variables in your sample differ from the parameters you need for your model. Args: No args Returns: Warning messages if sample parameters don't match parameters found in template files """ # Create main directory for simulation jobs if it doesn't exists self.jobsdir_abspath = os.path.join(self.abspath, '../_pybps_simulations') util.tmp_dir('create', self.jobsdir_abspath) # Create directory to store jobs results in main project directory # if it doesn't already exists self.resultsdir_abspath = os.path.join(self.abspath, '../_pybps_results') util.tmp_dir('create', self.resultsdir_abspath) # Remove any previously created job self.jobs = [] # Then, add jobs if self._batch: njob = len(self.sample) # Get list of all parameters found in template files self.get_parameterlist('tempfile') self.get_parameterlist('sample') if self.valid_check == True: # Check if template files and jobs file contain the same list # of parameters. Raise an error if not if set(self.temp_params).issubset(self.samp_params): for jobID in range(self.startJobID, self.startJobID + njob): self.jobs.append(BPSJob(self, jobID)) print("\n%d jobs added to BPSProject instance" % njob) else: print("\nMismatch between template and sample file" + " parameters!\nNo jobs added to BPSproject instance") else: for jobID in (self.startJobID, self.startJobID + njob): self.jobs.append(BPSJob(self, jobID)) print("\n%d jobs added to BPSProject instance" % njob) else: print("\nBPS project not a batch run. Jobs can't be added")
def add_jobs(self): """Add simulation jobs to BPSProject Simulation jobs are created and added to BPSProject only when this function is called. This makes it possible to transform the sample loaded from an external source (done automatically when BPSProject class is initialized if a sample file is found in project directory) prior to creating and adding jobs to the BPSProject. This can come in handy is the variables in your sample differ from the parameters you need for your model. Args: No args Returns: Warning messages if sample parameters don't match parameters found in template files """ # Create main directory for simulation jobs if it doesn't exists self.jobsdir_abspath = self.abspath + '_BATCH' util.tmp_dir('create', self.jobsdir_abspath) # Create directory to store jobs results in main project directory # if it doesn't already exists self.resultsdir_abspath = os.path.join(self.jobsdir_abspath, 'Results') util.tmp_dir('create', self.resultsdir_abspath) # Remove any previously created job self.jobs = [] # Then, add jobs if self._batch: njob = len(self.sample) # Get list of all parameters found in template files self.get_parameterlist('tempfile') self.get_parameterlist('sample') if self.valid_check == True: # Check if template files and jobs file contain the same list # of parameters. Raise an error if not if set(self.temp_params).issubset(self.samp_params): for jobID in range(self.startJobID, self.startJobID + njob): self.jobs.append(BPSJob(self, jobID)) print("\n%d jobs added to BPSProject instance" % njob) else: print("\nMismatch between template and sample file" + " parameters!\nNo jobs added to BPSproject instance") else: for jobID in (self.startJobID, self.startJobID + njob): self.jobs.append(BPSJob(self, jobID)) print("\n%d jobs added to BPSProject instance" % njob) else: print("\nBPS project not a batch run. Jobs can't be added")
def close(self): """Close job by copying result and log files to main results folder and delete temporary job folder""" # Parse info about simulation run from TRNSYS lst and log files if self.simtool == 'TRNSYS': # Get TRNSYS error/warning count from log file log_fname = os.path.splitext(self.model_relpath)[0] + '.log' log_abspath = os.path.join(self.abspath, log_fname) self.runsumdict = trnsys_post.parse_log(log_abspath) # Save jobID and simulation time in run summary dict self.runsumdict['JobID'] = self.seriesID + '_' + self.jobID self.runsumdict['SimulTime(sec)'] = self.simtime # Create a subfolder in main results folder to store simulation results simresdir_abspath = os.path.join(self.resultsdir_abspath, self.seriesID + '_' + self.jobID) util.tmp_dir('create', simresdir_abspath) # Get extensions of results files results_ext = self.config['resultfile_extensions'] results_ext = results_ext.split(',') # Get list of paths to job results files jobresfile_abspathlist = util.get_file_paths(results_ext, self.abspath) # Copy job results files to simulation results folder for jobresfile_abspath in jobresfile_abspathlist: copy(jobresfile_abspath, simresdir_abspath) # Get extensions of log files log_ext = self.config['logfile_extensions'] log_ext = log_ext.split(',') # Get list of paths to job log files joblogfile_abspathlist = util.get_file_paths(log_ext, self.abspath) # Copy log files to simulation results folder for joblogfile_abspath in joblogfile_abspathlist: copy(joblogfile_abspath, simresdir_abspath) # Remove temporary simulation folder util.tmp_dir('remove', self.abspath)
def close(self): """Close job by copying results and log file to main results directory and removing temporary job directory""" # Parse info about simulation run from TRNSYS lst and log files if self.simtool == 'TRNSYS': # Get TRNSYS error/warning count from log file log_fname = os.path.splitext(self.model_relpath)[0]+'.log' log_abspath = os.path.join(self.abspath, log_fname) self.runsumdict = trnsys_post.parse_log(log_abspath) # Save jobID and simulation time in run summary dict self.runsumdict['JobID'] = self.seriesID + '_' + '%0*d' % (5, self.jobID) self.runsumdict['SimulTime(sec)'] = self.simtime # Create a subfolder in main results folder to store simulation results simresdir_abspath = os.path.join(self.resultsdir_abspath, self.seriesID + '_' + '%0*d' % (5, self.jobID)) util.tmp_dir('create', simresdir_abspath) # Get extensions of results files results_ext = self.config['resultfile_extensions'] results_ext = results_ext.split(',') # Get list of paths to job results files jobresfile_abspathlist = util.get_file_paths(results_ext, self.abspath) # Copy job results files to simulation results folder for jobresfile_abspath in jobresfile_abspathlist: copy(jobresfile_abspath, simresdir_abspath) # Get extensions of log files log_ext = self.config['logfile_extensions'] log_ext = log_ext.split(',') # Get list of paths to job log files joblogfile_abspathlist = util.get_file_paths(log_ext, self.abspath) # Copy log files to simulation results folder for joblogfile_abspath in joblogfile_abspathlist: copy(joblogfile_abspath, simresdir_abspath) # Remove temporary simulation folder util.tmp_dir('remove', self.abspath)