def load_input(self, filePath): """ Loads existing input file, with lattice """ assert os.path.exists(filePath), f'Input file does not exist: {filePath}' f = tools.full_path(filePath) self.original_path, self.input_file = os.path.split(f) # Get original path, name of main input self.input = { 'beam':None } d = self.input main = parsers.parse_main_inputfile(filePath, self.expand_paths, self.strict, self.fill_defaults) d['param'] = main if main['beamfile'] != '': fname = main['beamfile'] d['beam'] = parsers.parse_beam_file(main['beamfile'], verbose=self.verbose) # Use this new name main['beamfile'] = parsers.POSSIBLE_INPUT_FILES['beamfile'] else: d['beam'] = None if main['maginfile'] != '': self.load_lattice(filePath=main['maginfile'], verbose=self.verbose) # Use this new name main['maginfile'] = parsers.POSSIBLE_INPUT_FILES['maginfile'] else: d['lattice'] = None
def run_genesis(self, verbose=False, parse_output=True, timeout=None): # Check that binary exists self.genesis_bin = tools.full_path(self.genesis_bin) assert os.path.exists( self.genesis_bin ), 'Genesis binary does not exist: ' + self.genesis_bin # Clear old output self.output = {} run_info = self.output['run_info'] = {} t1 = time() run_info['start_time'] = t1 # Debugging self.vprint(f'Running genesis in {self.path}') # Write all input self.write_input() runscript = self.get_run_script() run_info['run_script'] = ' '.join(runscript) try: if timeout: res = tools.execute2(runscript, timeout=timeout, cwd=self.path) log = res['log'] self.error = res['error'] run_info['why_error'] = res['why_error'] else: # Interactive output, for Jupyter log = [] for path in tools.execute(runscript, cwd=self.path): self.vprint(path, end="") log.append(path) self.log = log self.error = False if parse_output: self.load_output() except Exception as ex: print('Run Aborted', ex) self.error = True run_info['why_error'] = str(ex) finally: run_info['run_time'] = time() - t1 run_info['run_error'] = self.error self.finished = True
def find_genesis2_executable(genesis_exe=None, verbose=False): """ Searches for the genesis2 executable. """ if genesis_exe: exe = tools.full_path(genesis_exe) if os.path.exists(exe): if verbose: print(f'Using user provided executable: {exe}') return exe else: raise ValueError(f'Genesis executable does not exist: {exe}') for exe in [tools.full_path('$GENESIS_BIN'), shutil.which('genesis2')]: if os.path.exists(exe): if verbose: print(f'Using found executable: {exe}') return exe raise ValueError('No Genesisi executable found')