From 9e37e5864a359d75caf27d0e3aca3f85a302c4ad Mon Sep 17 00:00:00 2001 From: Sai Suraj Date: Tue, 18 Apr 2023 18:12:16 +0530 Subject: [PATCH] Reformatted some code in a few more files. --- .../gssi_400_over_fractal_subsurface.py | 8 ++++--- gprMax/contexts.py | 22 ++++++++----------- gprMax/model_build_run.py | 15 ++++++------- setup.py | 8 +++---- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/examples/subgrids/gssi_400_over_fractal_subsurface.py b/examples/subgrids/gssi_400_over_fractal_subsurface.py index 0ed7ae67..9a4546a8 100644 --- a/examples/subgrids/gssi_400_over_fractal_subsurface.py +++ b/examples/subgrids/gssi_400_over_fractal_subsurface.py @@ -102,9 +102,11 @@ halfspace = gprMax.Box(p1=(0, 0, 0), p2=(x, y, antenna_p[2]), material_id='soil' scene.add(halfspace) for i in range(1, 51): - snap = gprMax.Snapshot(p1=(0, y / 2, 0), p2=(x, y / 2 + dl, z), dl=(dl, dl, dl), - filename=Path(*parts[:-1], parts[-1] + '_' + str(i)).name, - time=i * tw / 50) + snap = gprMax.Snapshot(p1=(0, y / 2, 0), + p2=(x, y / 2 + dl, z), + dl=(dl, dl, dl), + filename=Path(*parts[:-1], f'{parts[-1]}_{str(i)}').name, + time=i * tw / 50,) scene.add(snap) # create a geometry view of the main grid and the sub grid stitched together diff --git a/gprMax/contexts.py b/gprMax/contexts.py index f0e3c952..fbde3698 100644 --- a/gprMax/contexts.py +++ b/gprMax/contexts.py @@ -92,7 +92,7 @@ class Context: def print_logo_copyright(self): """Prints gprMax logo, version, and copyright/licencing information.""" - logo_copyright = logo(__version__ + ' (' + codename + ')') + logo_copyright = logo(f'{__version__} ({codename})') logger.basic(logo_copyright) def print_sim_time_taken(self): @@ -164,19 +164,15 @@ class MPIContext(Context): executor = self.MPIExecutor(self._run_model, comm=self.comm) # Check GPU resources versus number of MPI tasks - if executor.is_master(): - if config.sim_config.general['solver'] == 'cuda': - if executor.size - 1 > len(config.sim_config.devices['devs']): - logger.exception('Not enough GPU resources for number of ' - 'MPI tasks requested. Number of MPI tasks ' - 'should be equal to number of GPUs + 1.') - raise ValueError - - # Create job list - jobs = [] - for i in self.model_range: - jobs.append({'i': i}) + if (executor.is_master() and + config.sim_config.general['solver'] == 'cuda' and + executor.size - 1 > len(config.sim_config.devices['devs'])): + logger.exception('Not enough GPU resources for number of ' + 'MPI tasks requested. Number of MPI tasks ' + 'should be equal to number of GPUs + 1.') + raise ValueError + jobs = [{'i': i} for i in self.model_range] # Send the workers to their work loop executor.start() if executor.is_master(): diff --git a/gprMax/model_build_run.py b/gprMax/model_build_run.py index 4fd1191d..19a4753d 100644 --- a/gprMax/model_build_run.py +++ b/gprMax/model_build_run.py @@ -73,7 +73,7 @@ class ModelBuildRun: self.p = psutil.Process() # Normal model reading/building process; bypassed if geometry information to be reused - self.build_geometry() if not config.get_model_config().reuse_geometry else self.reuse_geometry() + self.reuse_geometry() if config.get_model_config().reuse_geometry else self.build_geometry() logger.info(f'\nOutput directory: {config.get_model_config().output_file_path.parent.resolve()}') @@ -109,11 +109,11 @@ class ModelBuildRun: # Write files for any geometry views and geometry object outputs gvs = G.geometryviews + [gv for sg in G.subgrids for gv in sg.geometryviews] - if not (gvs or G.geometryobjectswrite) and config.sim_config.args.geometry_only: + if (not gvs and not G.geometryobjectswrite and config.sim_config.args.geometry_only): logger.exception('\nNo geometry views or geometry objects found.') raise ValueError save_geometry_views(gvs) - + if G.geometryobjectswrite: logger.info('') for i, go in enumerate(G.geometryobjectswrite): @@ -271,8 +271,7 @@ class ModelBuildRun: logger.warning(f"You have specified more threads ({config.get_model_config().ompthreads}) " f"than available physical CPU cores ({config.sim_config.hostinfo['physicalcores']}). " f"This may lead to degraded performance.") - # Print information about any compute device, e.g. GPU, in use - elif config.sim_config.general['solver'] == 'cuda' or config.sim_config.general['solver'] == 'opencl': + elif config.sim_config.general['solver'] in ['cuda', 'opencl']: if config.sim_config.general['solver'] == 'opencl': solvername = 'OpenCL' platformname = ' on ' + ' '.join(config.get_model_config().device['dev'].platform.name.split()) @@ -338,11 +337,11 @@ class GridBuilder: pbar.close() def tm_grid_update(self): - if '2D TMx' == config.get_model_config().mode: + if config.get_model_config().mode == '2D TMx': self.grid.tmx() - elif '2D TMy' == config.get_model_config().mode: + elif config.get_model_config().mode == '2D TMy': self.grid.tmy() - elif '2D TMz' == config.get_model_config().mode: + elif config.get_model_config().mode == '2D TMz': self.grid.tmz() def update_voltage_source_materials(self): diff --git a/setup.py b/setup.py index 44bfa294..8f3acf4f 100644 --- a/setup.py +++ b/setup.py @@ -134,12 +134,12 @@ if 'cleanall' in sys.argv: for file in cythonfiles: filebase = os.path.splitext(file)[0] # Remove Cython C files - if os.path.isfile(filebase + '.c'): + if os.path.isfile(f'{filebase}.c'): try: - os.remove(filebase + '.c') - print(f'Removed: {filebase + ".c"}') + os.remove(f'{filebase}.c') + print(f'Removed: {filebase}.c') except OSError: - print(f'Could not remove: {filebase + ".c"}') + print(f'Could not remove: {filebase}.c') # Remove compiled Cython modules libfile = (glob.glob(os.path.join(os.getcwd(), os.path.splitext(file)[0]) + '*.pyd') +