你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 07:24:19 +08:00
Tidied help messages and args
这个提交包含在:
261
gprMax/gprMax.py
261
gprMax/gprMax.py
@@ -17,145 +17,144 @@
|
||||
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import gprMax.config as config
|
||||
|
||||
from .contexts import Context, MPIContext
|
||||
from .utilities import setup_logging
|
||||
from .contexts import Context, MPIContext, SPOTPYContext
|
||||
from .utilities import logging_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
level = 20
|
||||
setup_logging(level=level)
|
||||
# Arguments (used for API) and their default values (used for API and CLI)
|
||||
args_defaults = {'scenes': None,
|
||||
'inputfile': None,
|
||||
'outputfile': None,
|
||||
'n': 1,
|
||||
'task': None,
|
||||
'restart': None,
|
||||
'mpi': False,
|
||||
'gpu': None,
|
||||
'subgrid': False,
|
||||
'autotranslate': False,
|
||||
'geometry_only': False,
|
||||
'geometry_fixed': False,
|
||||
'write_processed': False,
|
||||
'log_level': 20,
|
||||
'log_file': False}
|
||||
|
||||
# Argument help messages (used for CLI argparse)
|
||||
help_msg = {'scenes': '(list, opt): List of the scenes to run the model. '
|
||||
'Multiple scene objects can given in order to run multiple '
|
||||
'simulation runs. Each scene must contain the essential '
|
||||
'simulation objects',
|
||||
'inputfile': '(str, opt): Input file path. Can also run simulation '
|
||||
'by providing an input file.',
|
||||
'outputfile': '(str, opt): File path to the output data file.',
|
||||
'n': '(int, req): Number of required simulation runs.',
|
||||
'task': '(int, opt): Task identifier (model number) when running '
|
||||
'simulation as a job array on Open Grid Scheduler/Grid '
|
||||
'Engine (http://gridscheduler.sourceforge.net/index.html). '
|
||||
'For further details see the parallel performance '
|
||||
'section of the User Guide.',
|
||||
'restart': '(int, opt): Model number to start/restart simulation '
|
||||
'from. It would typically be used to restart a series of '
|
||||
'models from a specific model number, with the n argument, '
|
||||
'e.g. to restart from A-scan 45 when creating a B-scan '
|
||||
'with 60 traces.',
|
||||
'mpi': '(bool, opt): Flag to use Message Passing Interface (MPI) '
|
||||
'task farm. This option is most usefully combined with n to '
|
||||
'allow individual models to be farmed out using a MPI task '
|
||||
'farm, e.g. to create a B-scan with 60 traces and use MPI to '
|
||||
'farm out each trace. For further details see the parallel '
|
||||
'performance section of the User Guide.',
|
||||
'gpu': '(list/bool, opt): Flag to use NVIDIA GPU or list of NVIDIA '
|
||||
'GPU device ID(s) for specific GPU card(s).',
|
||||
'subgrid': '(bool, opt): Flag to use sub-gridding.',
|
||||
'autotranslate': '(bool, opt): For sub-gridding - auto translate '
|
||||
'objects with main grid coordinates to their '
|
||||
'equivalent local grid coordinate within the '
|
||||
'subgrid. If this option is off users must specify '
|
||||
'sub-grid object point within the global subgrid space.',
|
||||
'geometry_only': '(bool, opt): Build a model and produce any '
|
||||
'geometry views but do not run the simulation.',
|
||||
'geometry_fixed': '(bool, opt): Run a series of models where the '
|
||||
'geometry does not change between models.',
|
||||
'write_processed': '(bool, opt): Writes another input file after '
|
||||
'any Python code (#python blocks) and in the '
|
||||
'original input file has been processed.',
|
||||
'log_level': '(int, opt): Level of logging to use.',
|
||||
'log_file': '(bool, opt): Write logging information to file.'}
|
||||
|
||||
|
||||
def run(
|
||||
scenes=None,
|
||||
inputfile=None,
|
||||
outputfile=None,
|
||||
n=1,
|
||||
task=None,
|
||||
restart=None,
|
||||
mpi=False,
|
||||
gpu=None,
|
||||
subgrid=False,
|
||||
autotranslate=False,
|
||||
geometry_only=False,
|
||||
geometry_fixed=False,
|
||||
write_processed=False
|
||||
):
|
||||
def run(scenes=args_defaults['scenes'],
|
||||
inputfile=args_defaults['inputfile'],
|
||||
outputfile=args_defaults['outputfile'],
|
||||
n=args_defaults['n'],
|
||||
task=args_defaults['task'],
|
||||
restart=args_defaults['restart'],
|
||||
mpi=args_defaults['mpi'],
|
||||
gpu=args_defaults['gpu'],
|
||||
subgrid=args_defaults['subgrid'],
|
||||
autotranslate=args_defaults['autotranslate'],
|
||||
geometry_only=args_defaults['geometry_only'],
|
||||
geometry_fixed=args_defaults['geometry_fixed'],
|
||||
write_processed=args_defaults['write_processed'],
|
||||
log_level=args_defaults['log_level'],
|
||||
log_file=args_defaults['log_file']
|
||||
):
|
||||
"""This is the main function for gprMax when entering using application
|
||||
programming interface (API). Run the simulation for the
|
||||
given list of scenes.
|
||||
|
||||
:param scenes: list of the scenes to run the model. Multiple scene objects
|
||||
can given in order to run multiple simulation runs. Each
|
||||
scene must contain the essential simulation objects
|
||||
:type scenes: list, optional
|
||||
|
||||
:param inputfile: input file path. Can also run simulation by providing an
|
||||
input file.
|
||||
:type inputfile: str, optional
|
||||
|
||||
:param outputfile: file path to the output data file.
|
||||
:type outputfile: str, non-optional
|
||||
|
||||
:param n: number of required simulation runs.
|
||||
:type n: int, non-optional
|
||||
|
||||
:param task: task identifier (model number) when running simulation as a
|
||||
job array on open grid scheduler/grid engine. For further
|
||||
details see the parallel performance section of the User Guide.
|
||||
:type task: int, optional
|
||||
|
||||
:param restart: model number to start/restart simulation from. It would
|
||||
typically be used to restart a series of models from a
|
||||
specific model number, with the n argument, e.g. to restart
|
||||
from A-scan 45 when creating a B-scan with 60 traces.
|
||||
:type restart: int, optional
|
||||
|
||||
:param mpi: flag to use Message Passing Interface (MPI) task farm. This
|
||||
option is most usefully combined with n to allow individual
|
||||
models to be farmed out using a MPI task farm, e.g. to create a
|
||||
B-scan with 60 traces and use MPI to farm out each trace.
|
||||
For further details see the parallel performance section of the
|
||||
User Guide.
|
||||
:type mpi: bool, optional
|
||||
|
||||
:param gpu: flag to use NVIDIA GPU or list of NVIDIA GPU device ID(s) for
|
||||
specific GPU card(s).
|
||||
:type gpu: list or bool, optional
|
||||
|
||||
:param subgrid: flag to use sub-gridding.
|
||||
:type subgrid: bool, optional
|
||||
|
||||
:param autotranslate: for sub-gridding - auto translate objects with main grid
|
||||
coordinates to their equivalent local grid coordinate
|
||||
within the subgrid. If this option is off users must
|
||||
specify sub-grid object point within the global
|
||||
subgrid space.
|
||||
:type autotranslate: bool, optional
|
||||
|
||||
:param geometry_only: build a model and produce any geometry views but do
|
||||
not run the simulation.
|
||||
:type geometry_only: bool, optional
|
||||
|
||||
:param geometry_fixed: run a series of models where the geometry does not
|
||||
change between models.
|
||||
:type geometry_fixed: bool, optional
|
||||
|
||||
:param write_processed: write another input file after any Python code and
|
||||
in the original input file has been processed.
|
||||
:type write_processed: bool, optional
|
||||
programming interface (API). Run the simulation for the given list of
|
||||
scenes.
|
||||
"""
|
||||
|
||||
class ImportArguments:
|
||||
pass
|
||||
|
||||
args = ImportArguments()
|
||||
|
||||
args.scenes = scenes
|
||||
args.subgrid = subgrid
|
||||
args.inputfile = inputfile
|
||||
args.outputfile = outputfile
|
||||
args.n = n
|
||||
args.task = task
|
||||
args.restart = restart
|
||||
args.mpi = mpi
|
||||
args.gpu = gpu
|
||||
args.autotranslate = autotranslate
|
||||
args.geometry_only = geometry_only
|
||||
args.geometry_fixed = geometry_fixed
|
||||
args.write_processed = write_processed
|
||||
args = argparse.Namespace(**{'scenes': scenes,
|
||||
'inputfile': inputfile,
|
||||
'outputfile': outputfile,
|
||||
'n': n,
|
||||
'task': task,
|
||||
'restart': restart,
|
||||
'mpi': mpi,
|
||||
'gpu': gpu,
|
||||
'subgrid': subgrid,
|
||||
'autotranslate': autotranslate,
|
||||
'geometry_only': geometry_only,
|
||||
'geometry_fixed': geometry_fixed,
|
||||
'write_processed': write_processed,
|
||||
'log_level': log_level,
|
||||
'log_file': log_file})
|
||||
|
||||
run_main(args)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function for gprMax when entering using the command line interface (CLI)."""
|
||||
def cli():
|
||||
"""Main function for gprMax when entering using the command line interface
|
||||
(CLI).
|
||||
"""
|
||||
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(prog='gprMax', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('inputfile',
|
||||
help='relative or absolute path to inputfile')
|
||||
parser.add_argument('-n', default=1, type=int,
|
||||
help='number of times to run the input file, e.g. to create a B-scan')
|
||||
parser.add_argument('-task', type=int,
|
||||
help='task identifier (model number) for job array on '
|
||||
'Open Grid Scheduler/Grid Engine (http://gridscheduler.sourceforge.net/index.html)')
|
||||
parser.add_argument('-r', '--restart', type=int,
|
||||
help='model number to restart from, e.g. when creating B-scan')
|
||||
parser.add_argument('-mpi', action='store_true', default=False,
|
||||
help='flag to enable MPI task farming')
|
||||
parser = argparse.ArgumentParser(prog='gprMax',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('inputfile', help=help_msg['inputfile'])
|
||||
parser.add_argument('-n', default=args_defaults['n'], type=int, help=help_msg['n'])
|
||||
parser.add_argument('-task', type=int, help=help_msg['task'])
|
||||
parser.add_argument('-r', '--restart', type=int, help=help_msg['restart'])
|
||||
parser.add_argument('-mpi', action='store_true', default=args_defaults['mpi'],
|
||||
help=help_msg['mpi'])
|
||||
parser.add_argument('-gpu', type=int, action='append', nargs='*',
|
||||
help='flag to use Nvidia GPU or option to give list of device ID(s)')
|
||||
parser.add_argument('--geometry-only', action='store_true', default=False,
|
||||
help='flag to only build model and produce geometry file(s)')
|
||||
parser.add_argument('--geometry-fixed', action='store_true', default=False,
|
||||
help='flag to not reprocess model geometry, e.g. for B-scans where the geometry is fixed')
|
||||
parser.add_argument('--write-processed', action='store_true', default=False,
|
||||
help='flag to write an input file after any Python code and include commands '
|
||||
'in the original input file have been processed')
|
||||
help=help_msg['gpu'])
|
||||
parser.add_argument('--geometry-only', action='store_true',
|
||||
default=args_defaults['geometry_only'],
|
||||
help=help_msg['geometry_only'])
|
||||
parser.add_argument('--geometry-fixed', action='store_true',
|
||||
default=args_defaults['geometry_fixed'],
|
||||
help=help_msg['geometry_fixed'])
|
||||
parser.add_argument('--write-processed', action='store_true',
|
||||
default=args_defaults['write_processed'],
|
||||
help=help_msg['write_processed'])
|
||||
parser.add_argument('--log-level', type=int,
|
||||
default=args_defaults['log_level'],
|
||||
help=help_msg['log_level'])
|
||||
parser.add_argument('--log-file', action='store_true',
|
||||
default=args_defaults['log_file'],
|
||||
help=help_msg['log_file'])
|
||||
args = parser.parse_args()
|
||||
|
||||
run_main(args)
|
||||
@@ -168,9 +167,21 @@ def run_main(args):
|
||||
args (Namespace): arguments from either API or CLI.
|
||||
"""
|
||||
|
||||
logging_config(level=args.log_level, log_file=args.log_file)
|
||||
|
||||
config.sim_config = config.SimulationConfig(args)
|
||||
if config.sim_config.args.mpi:
|
||||
|
||||
# If integrating with SPOTPY (https://github.com/thouska/spotpy) - extra
|
||||
# 'spotpy' attribute is added to args when called by SPOTPY
|
||||
if hasattr(args, 'spotpy'):
|
||||
if args.spotpy:
|
||||
context = SPOTPYContext()
|
||||
context.run(args.i)
|
||||
# MPI running with (OpenMP/CUDA)
|
||||
elif config.sim_config.args.mpi:
|
||||
context = MPIContext()
|
||||
context.run()
|
||||
# Standard running (OpenMP/CUDA)
|
||||
else:
|
||||
context = Context()
|
||||
context.run()
|
||||
context.run()
|
||||
|
在新工单中引用
屏蔽一个用户