def run_sample(smp: sample.Sample, run_dir: Text, summary_file: Optional[Text] = None): """Runs the given sample in the given directory. Args: smp: Sample to run. run_dir: Directory to run the sample in. The directory should exist and be empty. summary_file: The (optional) file to append sample summary. Raises: sample_runner.SampleError: on any non-zero status from the sample runner. """ _write_to_file(run_dir, 'sample.x', smp.input_text) _write_to_file(run_dir, 'options.json', smp.options.to_json()) if smp.args_batch: _write_to_file(run_dir, 'args.txt', sample.args_batch_to_text(smp.args_batch)) # Create a script named 'run.sh' for rerunning the sample. args = [ SAMPLE_RUNNER_MAIN_PATH, '--logtostderr', '--input_file=sample.x', '--options_file=options.json' ] if smp.args_batch: args.append('--args_file=args.txt') args.append(run_dir) _write_to_file( run_dir, 'run.sh', f'#!/bin/sh\n\n{subprocess.list2cmdline(args)}\n', executable=True) start = time.time() logging.vlog(1, 'Starting to run sample') logging.vlog(2, smp.input_text) runner = sample_runner.SampleRunner(run_dir) runner.run_from_files('sample.x', 'options.json', 'args.txt') logging.vlog(1, 'Completed running sample, elapsed: %0.2fs', time.time() - start) if summary_file: _write_ir_summaries(run_dir, summary_file)
def run(self, smp: sample.Sample): """Runs the given sample. Args: smp: Sample to run. Raises: SampleError: If an error was encountered. """ if smp.options.input_is_dslx: input_filename = self._write_file('sample.x', smp.input_text) else: input_filename = self._write_file('sample.ir', smp.input_text) json_options_filename = self._write_file('options.json', smp.options.to_json()) args_filename = None if smp.args_batch is not None: args_filename = self._write_file( 'args.txt', sample.args_batch_to_text(smp.args_batch)) self.run_from_files(input_filename, json_options_filename, args_filename)