def main(argv): # Name the experiment. experiment.name('test-shellcmds') fname = 'afile.txt' logger.log('# Testing globbing...') shargs = {'echo': True} # Wildcards don't need to be escaped with a `\' or quoted to protect them # from expansion by the host. We take care of that for you. container.run('ls *') # host and container interfaces should behave as identically as possible. host.run('ls *', **shargs) logger.emlog('# Testing redirection...') logger.log(F'# Adding text to {fname}:') host.run(F'echo "Some Text" | tee {fname}', **shargs) host.run(F'echo "More \'Text\'" >> {fname}', **shargs) logger.emlog(F'# The contents of {fname} are:') host.run(F'cat {fname}', **shargs) logger.emlog('# Testing quoting...') container.run('echo "Some \'Text\'"') logger.emlog('# Testing command chaining...') container.run('true && echo true!') container.run('false || echo false is good && echo true is good') logger.emlog('# Testing variable lifetimes within chained commands...') container.run('export FOO="bar" && ' 'test ! -z $FOO && ' 'echo "Looks good!" || ' 'exit 1') metadata.add_asset(metadata.FileAsset(fname))
def _populate_service_config(self) -> None: # Remove program from output since it is redundant and because we don't # know how it'll be parsed by the given program. tmpargs = copy.deepcopy(vars(self.args)) tmpargs.pop('program') self.confd['Configuration'] = tmpargs metadata.add_asset(metadata.YAMLDictAsset(self.confd, 'run'))
def report(self) -> None: ''' Generate csv report. ''' logger.emlog(F'# {self.config.args.name} Report') logger.log('creating report...\n') # Setup table table = utils.Table() sio = io.StringIO(newline=None) dataraw = csv.writer(sio) # Column header header = self.keywords dataraw.writerow(header) table.addrow(header) # Populate csv table. for index, entry in enumerate(self.data['results']): table.addrow(entry) # Terminal table. # Add command column to csv file. entry.append(self.data['commands'][index]) dataraw.writerow(entry) csvfname = self.csv_output metadata.add_asset(metadata.StringIOAsset(sio, csvfname)) table.emit() logger.log('')
def report(self): logger.emlog(F'# {experiment.name()} Report') header = [ 'solver_id', 'numpe', 'tottime', 'nx,ny,nz', 'px,py,pz', 'fom' ] data = zip(self.data['solver_id'], self.data['numpe'], self.data['tottime'], self.data['nxnynz'], self.data['pxpypz'], self.data['fom']) table = utils.Table() sio = io.StringIO(newline=None) dataw = csv.writer(sio) dataw.writerow([F'## {self.config.args.description}']) dataw.writerow(header) table.addrow(header, withrule=True) for solid, numpe, tott, nxyz, pxyz, fom in data: row = [solid, numpe, tott, nxyz, pxyz, fom] dataw.writerow(row) table.addrow(row) csvfname = self.config.args.csv_output metadata.add_asset(metadata.StringIOAsset(sio, csvfname)) table.emit() logger.log('')
def report(self): logger.emlog(F'# {experiment.name()} Report') header = ['numpe', 'tottime', 'cgh1', 'cgl2'] data = zip(self.data['command'], self.data['starttime'], self.data['numpe'], self.data['nthread'], self.data['tottime'], self.data['cgh1'], self.data['cgl2']) icapt_rds = None if utils.module_imported('icaptdb'): icapt_rds = icaptdb.RunDataStore(self.config.args) table = utils.Table() sio = io.StringIO(newline=None) dataw = csv.writer(sio) dataw.writerow([F'## {self.config.args.description}']) dataw.writerow(header) table.addrow(header, withrule=True) for cmd, stime, numpe, nthread, tott, cgh1, cgl2 in data: row = [numpe, tott, cgh1, cgl2] dataw.writerow(row) table.addrow(row) if icapt_rds is not None: icapt_rds.add(stime.strftime('%a %b %d %H:%M:%S %Y'), tott, numpe, nthread, cmd, [ FOMFactory.build('cgh1', cgh1), FOMFactory.build('cgl2', cgl2) ]) csvfname = self.config.args.csv_output metadata.add_asset(metadata.StringIOAsset(sio, csvfname)) table.emit() logger.log('')
def _emit_config(self) -> None: # First build up the dictionary containing the configuration used. self._populate_config() # Add to metadata assets stored to container image. metadata.add_asset(metadata.YAMLDictAsset(self.confd, 'environment')) # Then print it out in YAML format. utils.yamlp(self.confd, self.prog)
def report(self) -> None: ''' Generate csv report ''' logger.emlog(F'# {self.config.args.name} Report') logger.log('Creating report...') # Setup table. table = utils.Table() sio = io.StringIO(newline=None) dataraw = csv.writer(sio) # Column headers. columns = [] for label in self.keywords: columns.append(label) dataraw.writerow(columns) table.addrow(columns) # Populate table. for index, entry in enumerate(self.data['results']): table.addrow(entry) entry.append(self.data['commands'][index]) dataraw.writerow(entry) # Write table to csv ad display to terminal. csvname = self.config.args.csv_output metadata.add_asset(metadata.StringIOAsset(sio, csvname)) table.emit() logger.log('')
def report(self) -> None: ''' Generate report ''' logger.emlog(F'# {self.config.args.name} Report') logger.log('creating report...\n') # Setup Table table = utils.Table() sio = io.StringIO(newline=None) dataraw = csv.writer(sio) header = ['Time', 'KBytesXchng/Rank-Max', 'MB/S/Rank', 'Command'] dataraw.writerow(header) table.addrow(header) # Populate table. for index, entry in enumerate(self.data['results']): table.addrow(entry) entry.append(self.data['commands'][index]) dataraw.writerow(entry) # Write table to csv & display to terminal. csvname = self.config.args.csv_output metadata.add_asset(metadata.StringIOAsset(sio, csvname)) table.emit() logger.log('')
def main(argv): # Name the experiment. experiment.name('test-shellcmds') fname = 'afile.txt' logger.log('# Testing globbing...') shargs = {'echo': True} # Wildcards need to be escaped with a `\' or quoted to protect them from # expansion by the host. container.run('ls \\*') # shell and container interfaces should behave as identically as possible. host.run('ls \\*', **shargs) logger.emlog('# Testing redirection...') logger.log(F'# Adding text to {fname}:') container.run(F'echo "Some Text" | tee {fname}') container.run(F'echo "More \'Text\'" >> {fname}') logger.emlog(F'# The contents of {fname} are:') host.run(F'cat {fname}', **shargs) logger.emlog('# Testing quoting...') container.run('echo "Some \'Text\'"') logger.emlog('# Testing command chaining...') container.run('true && echo true!') container.run('false || echo false... && echo and done!') metadata.add_asset(metadata.FileAsset(fname))
def _add_container_metadata(self) -> None: ''' Adds container metadata to run metadata assets. ''' logger.emlog('# Looking for container metadata...') # Skip any image activators that do not have build metadata. if not cntrimg.activator().requires_img_activation(): iact = self.args.image_activator logger.log(F'# Note: the {iact} activator has no metadata\n') return imgdir = self.inflated_cntrimg_path # The subdirectory where container metadata are stored. buildl = os.path.join( imgdir, constants.METADATA_DIR, constants.SERVICE_LOG_NAME ) # Don't error out if the image doesn't have our metadata. if not os.path.exists(buildl): logger.log('# Note: container image provides no metadata\n') return logger.log(F'# Adding metadata from {imgdir}\n') mdatadir = 'container' metadata.add_asset(metadata.FileAsset(buildl, mdatadir))
def report(self) -> None: ''' Generate csv report from run iterations. ''' logger.emlog(F'# {experiment.name()} Report') # Setup table. table = utils.Table() sio = io.StringIO(newline=None) dataraw = csv.writer(sio) header = ['Cycle', 'Cstop', 'Time', 'Tstop', 'Hydro Cycle', 'Command'] dataraw.writerow(header) table.addrow(header) # Populate table. for index, entry in enumerate(self.data['results']): entry.append(self.data['commands'][index]) dataraw.writerow(entry) table.addrow(entry) # Write table to csv & display to terminal. csvname = self.config.args.csv_output metadata.add_asset(metadata.StringIOAsset(sio, csvname)) table.emit() logger.log('')
def _emit_build_spec(self) -> None: dockerf = self.config['spec'] # Add spec file to the metadata assets. metadata.add_asset(metadata.FileAsset(dockerf)) # Emit the contents of the spec file. logger.log('# Begin Spec Output') logger.log(utils.chomp(str().join(utils.cat(dockerf)))) logger.log('# End Spec Output')
def main(argv): logger.log('adding a file asset...') metadata.add_asset(metadata.FileAsset('some-metadata.txt')) logger.log('adding a yaml dict asset...') adict = dict() adict['Application'] = {'argv': argv} adict['System'] = {'whoami': host.whoami(), 'hostname': host.hostname()} metadata.add_asset(metadata.YAMLDictAsset(adict, 'yaml-metadata'))
def _emit_builder_info(self) -> None: ''' Emits builder information gathered at run-time. ''' binfo = dict() binfo['Builder'] = { 'which': host.which(self.buildc), 'version': host.capture('{} --version'.format(self.buildc)), } utils.yamlp(binfo, 'Builder') metadata.add_asset(metadata.YAMLDictAsset(binfo, 'builder'))
def _populate_env_config(self) -> None: # Host environment. self.confd['Host'] = { 'whoami': host.whoami(), 'kernel': host.kernel(), 'kernel_release': host.kernelrel(), 'hostname': host.hostname(), 'os_release': host.os_pretty_name() } # Do this so the YAML output has the 'Host' heading. hostd = {'Host': self.confd['Host']} metadata.add_asset(metadata.YAMLDictAsset(hostd, 'environment'))
def main(argv): logger.log('adding a file asset...') # adds an arbitrary metadata file to a subfolder: custom metadata.add_asset( metadata.FileAsset('some-metadata.txt', 'subdir-a/subdir-b')) logger.log('adding a yaml dict asset...') adict = dict() # collect metadata adict['Application'] = {'argv': argv} adict['System'] = {'whoami': host.whoami(), 'hostname': host.hostname()} # save metadata to file metadata.add_asset(metadata.YAMLDictAsset(adict, 'yaml-metadata'))
def tabulate(self, label): logger.log(F"#{'-'*79}") logger.log(F"# name: {self.name}") logger.log(F"# numpe: {self.numpe}") logger.log(F"# numt: {self.numt}") logger.log(F"# window_size: {self.window_size}") logger.log(F"# mode: {self.mode}") logger.log(F"#{'-'*79}") table = utils.Table() sio = io.StringIO(newline=None) dataw = csv.writer(sio) metad = [('numt', self.numt), ('window_size', self.window_size), ('mode', self.mode)] # Write metadata header to csv file. Is this the best way to do this? for coll in metad: key = coll[0] val = coll[1] if not val: continue dataw.writerow([F'##{key}', val]) dataw.writerow(self.metrics) table.addrow(self.metrics, withrule=True) for row in self.stats: table.addrow(row) dataw.writerow(row) table.emit() logger.log('\n') csvfname = F'{self.name}' csvfname += F'-{self.numpe}PE' if self.mode is not None: csvfname += F'-{self.mode.lower()}' csvfname += '.csv' opath = os.path.join(label.name, F'numpe-{label.numpe}', F'runid-{label.generation}') metadata.add_asset(metadata.StringIOAsset(sio, csvfname, opath))
def add_assets(self) -> None: ''' Backup input and output files in metadata (including snap files). ''' metadata.add_asset(metadata.FileAsset(self.config.args.input)) metadata.add_asset(metadata.FileAsset(self.snap_input)) metadata.add_asset(metadata.FileAsset(self.snap_output))
def parse_snapfile(self) -> None: ''' Collect time data from snap output file. ''' with open(self.snap_output) as out_file: lines = out_file.readlines() time_table = [] # Search for time table. for pos, line in enumerate(lines): if line.lstrip().startswith('keyword Timing Summary'): logger.log(F'Found time table on line: {pos}\n') time_table = lines[pos + 1:] break # Collect iteration results. results = [] for row in time_table: # trim white space, su trimmed = re.sub(r'[ ]{2,}', ':', row.strip()) # Skip empty or decorative if trimmed == '' or '*' in trimmed: continue label, value = trimmed.split(':') if label in self.keywords: results.append(value) # Add iteration results to experiment data. self.data['results'].append(results) # Save dictionary data. logger.log('\nAdding metadata file...') metadata.add_asset( metadata.YAMLDictAsset(self.data, 'timing-metadata')) return
def report(self): logger.emlog(F'# {experiment.name()} Report') header = ['NUMPE', 'NThread', 'Average Lookups/s', 'Total Lookups/s'] data = zip(self.data['numpe'], self.data['nthread'], self.data['alups'], self.data['tlups']) table = utils.Table() sio = io.StringIO(newline=None) dataw = csv.writer(sio) dataw.writerow([F'## {self.config.args.description}']) dataw.writerow(header) table.addrow(header, withrule=True) for numpe, nthread, alups, tlups in data: row = [numpe, nthread, alups, tlups] dataw.writerow(row) table.addrow(row) csvfname = self.config.args.csv_output metadata.add_asset(metadata.StringIOAsset(sio, csvfname)) table.emit() logger.log('')
def run(argv: List[str]) -> None: ''' Loads and executes the run program specified at argv[0], passing along all program-specific arguments to the program (argv). ''' argz = argv[0] # Stash the program. metadata.add_asset(metadata.FileAsset(argz)) # Import and run the specified program. argz passed twice for nicer # error messages when a user specifies a bogus program. spec = importlib.util.spec_from_file_location(argz, argz) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) # Save cwd so we can restore it after program execution. scwd = os.getcwd() try: # What's the specified program's cwd? pbase = os.path.dirname(argz) # cddir to base of given program so relative operations work # properly. os.chdir(pbase) mod.main(argv) finally: os.chdir(scwd)
def add_assets(self) -> None: ''' Backup metadata assets ''' metadata.add_asset(metadata.FileAsset(self.config.args.input))
def add_assets(self): metadata.add_asset(metadata.FileAsset(self.config.args.input))
def add_assets(self) -> None: ''' Backup input and output files in metadata ''' metadata.add_asset(metadata.FileAsset(self.config.args.input)) metadata.add_asset(metadata.FileAsset(self.config.args.bransonfile))
import io import re from bueno.public import container from bueno.public import experiment from bueno.public import logger from bueno.public import metadata from bueno.public import utils # Import extras try: import icaptdb except ImportError: pass else: metadata.add_asset(metadata.PythonModuleAsset(icaptdb)) class FOMFactory: @staticmethod def build(name, value): if name == 'cgh1': desc = 'CG (H1) total time' units = 's' return experiment.FOM(name, desc, units, value) if name == 'cgl2': desc = 'CG (L2) total time' units = 's' return experiment.FOM(name, desc, units, value) return None
def add_assets(self): if not utils.emptystr(self.config.args.input): metadata.add_asset(metadata.FileAsset(self.config.args.input))
def add_assets(self) -> None: ''' Select additional assets to copy ''' metadata.add_asset(metadata.FileAsset(self.config.args.input)) metadata.add_asset(metadata.FileAsset(self.pinfile))
from bueno.public import experiment from bueno.public import logger from bueno.public import metadata from bueno.public import utils try: import mymod from mypackage import mypackmod except ImportError: pass else: # Because bueno cannot easily determine what extra stuff was imported at # run-time, add the extras by hand to our run's metadata. metadata.add_asset(metadata.PythonModuleAsset(mymod)) metadata.add_asset(metadata.PythonModuleAsset(mypackmod)) def main(argv): experiment.name('hello-extras') logger.log('This is an example of how to use extras') # Use the extra modules we specified at run-time if they are loaded. if utils.module_imported('mymod'): mymod.say_hello() else: logger.log('*** NOTE: mymod is not imported ***') if utils.module_imported('mypackage'): mypackmod.say_hello() else: logger.log('*** NOTE: mypackmod is not imported ***')