def main(): """ Driver function that parses command line arguments and passes them to the execute function. """ # Parse the command-line arguments (requires the argparse module) args = parse_command_line_arguments() # Initialize the logging system (resets the RMG.log file) level = logging.INFO if args.debug: level = 0 elif args.verbose: level = logging.DEBUG elif args.quiet: level = logging.WARNING kwargs = { 'restart': args.restart, 'walltime': args.walltime, 'log': level, 'maxproc': args.maxproc, 'kineticsdatastore': args.kineticsdatastore } initialize_log(level, os.path.join(args.output_directory, 'RMG.log')) rmg = RMG(input_file=args.file, output_directory=args.output_directory) # Add output listeners: rmg.attach(ChemkinWriter(args.output_directory)) rmg.attach(OutputHTMLWriter(args.output_directory)) execute(rmg, **kwargs)
def main(): # Parse the command-line arguments (requires the argparse module) args = parse_command_line_arguments() if args.postprocess: logging.info( "Postprocessing the profiler statistics (will be appended to RMG.log)" ) else: # Initialize the logging system (resets the RMG.log file) level = logging.INFO if args.debug: level = 0 elif args.verbose: level = logging.DEBUG elif args.quiet: level = logging.WARNING initialize_log(level, os.path.join(args.output_directory, 'RMG.log')) logging.info(rmgpy.settings.report()) kwargs = { 'restart': args.restart, 'walltime': args.walltime, 'maxproc': args.maxproc, 'kineticsdatastore': args.kineticsdatastore } if args.profile: import cProfile global_vars = {} local_vars = { 'inputFile': args.file, 'output_dir': args.output_directory, 'kwargs': kwargs, 'RMG': RMG } command = """rmg = RMG(input_file=inputFile, output_directory=output_dir); rmg.execute(**kwargs)""" stats_file = os.path.join(args.output_directory, 'RMG.profile') print("Running under cProfile") if not args.postprocess: # actually run the program! cProfile.runctx(command, global_vars, local_vars, stats_file) # postprocess the stats log_file = os.path.join(args.output_directory, 'RMG.log') process_profile_stats(stats_file, log_file) make_profile_graph(stats_file) else: rmg = RMG(input_file=args.file, output_directory=args.output_directory) rmg.execute(**kwargs)
def test_parse_command_line_non_defaults(self): """ Test user command line inputs into rmg.py """ # Acquire arguments args = parse_command_line_arguments(['other_name.py', '-d', '-o', '/test/output/dir/', '-r', 'test/seed/', '-P', '-t', '01:20:33:45', '-k', '-i', '100']) # Test expected values self.assertEqual(args.walltime, '01:20:33:45') self.assertEqual(args.output_directory, '/test/output/dir/') self.assertEqual(args.debug, True) self.assertEqual(args.file, 'other_name.py') self.assertEqual(args.maxiter, 100) self.assertEqual(args.kineticsdatastore, True) self.assertEqual(args.postprocess, True) self.assertEqual(args.profile, True) self.assertEqual(args.restart, 'test/seed/')
def test_parse_command_line_arguments_defaults(self): """ Test the default values for the parseCommandLineArguments module """ # Acquire default arguments args = parse_command_line_arguments(['input.py']) # Test default values self.assertEqual(args.walltime, '00:00:00:00') self.assertEqual(args.output_directory, os.path.abspath(os.path.dirname('./'))) self.assertEqual(args.debug, False) self.assertEqual(args.file, 'input.py') self.assertEqual(args.kineticsdatastore, False) self.assertEqual(args.postprocess, False) self.assertEqual(args.profile, False) self.assertEqual(args.quiet, False) self.assertEqual(args.restart, '') self.assertEqual(args.verbose, False)