scripts/sgdml_error_flattened_model.py
def parse_arguments():
	'''Parses arguments

	Mostly equivalent/copied from cli.py file

	Returns:
		args -- dictionary
	'''

	def _add_argument_dataset(parser, help='path to dataset file'):
		parser.add_argument(
			'dataset',
			metavar='<dataset_file>',
			type=lambda x: io.is_file_type(x, 'dataset'),
			help=help,
		)

	def _add_argument_sample_size(parser, subset_str):
		parser.add_argument(
			'n_%s' % subset_str,
			metavar='<n_%s>' % subset_str,
			type=io.is_strict_pos_int,
			help='%s sample size' % subset_str,
		)

	def _add_argument_dir_with_file_type(parser, type, or_file=False):
		parser.add_argument(
			'%s_dir' % type,
			metavar='<%s_dir%s>' % (type, '_or_file' if or_file else ''),
			type=lambda x: io.is_dir_with_file_type(x, type, or_file=or_file),
			help='path to %s directory%s' % (type, ' or file' if or_file else ''),
		)
   
	parser = argparse.ArgumentParser()
	parser.add_argument(
		'--version',
		action='version',
		version='%(prog)s '
		+ __version__
		+ ' [python '
		+ '.'.join(map(str, sys.version_info[:3]))
		+ ']',
	)

	parser.add_argument(
		'-o',
		'--overwrite',
		dest='overwrite',
		action='store_true',
		help='overwrite existing files',
	)

	parser.add_argument(
		'-p',
		'--max_processes',
		metavar='<max_processes>',
		type=io.is_strict_pos_int,
		help='limit the number of processes for this application',
	)

	parser.add_argument(
		'--torch',
		dest='use_torch',
		action='store_true',
		help='use PyTorch for validation and test',
	)
	
	_add_argument_dataset(parser)
	_add_argument_sample_size(parser, 'train_init')
	_add_argument_sample_size(parser, 'train_final')

	parser.add_argument(
		'n_steps',
		metavar='<n_steps>',
		type=io.is_strict_pos_int,
		help='number of steps',
	)

	_add_argument_sample_size(parser, 'valid')

	parser.add_argument(
		'-v',
		'--validation_dataset',
		metavar='<validation_dataset_file>',
		dest='valid_dataset',
		type=lambda x: io.is_file_type(x, 'dataset'),
		help='path to validation dataset file',
	)

	parser.add_argument(
		'-s',
		'--sig',
		metavar=('<s1>', '<s2>'),
		dest='sigs',
		type=io.parse_list_or_range,
		help='integer list and/or range <start>:[<step>:]<stop> for the kernel hyper-parameter sigma',
		nargs='+',
	)

	parser.add_argument(
		'--task_dir',
		metavar='<task_dir>',
		dest='task_dir',
		help='user-defined task output dir name',
	)

	group = parser.add_mutually_exclusive_group()
	group.add_argument(
		'--gdml',
		action='store_true',
		help='don\'t include symmetries in the model (GDML)',
	)
	group.add_argument(
		'--cprsn',
		dest='use_cprsn',
		action='store_true',
		help='compress kernel matrix along symmetric degrees of freedom',
	)

	group = parser.add_mutually_exclusive_group()
	group.add_argument(
		'--no_E',
		dest='use_E',
		action='store_false',
		help='only reconstruct force field w/o potential energy surface',
	)
	group.add_argument(
		'--E_cstr',
		dest='use_E_cstr',
		action='store_true',
		help='include the energy constraints in the kernel',
	)

	parser.add_argument(
		'n_test',
		metavar='<n_test>',
		type=io.is_strict_pos_int,
		help='test sample size',
		nargs='?',
		default=None,
	)

	parser.add_argument(
		'--model_file',
		metavar='<model_file>',
		dest='model_file',
		help='user-defined model output file name',
	)


	group = parser.add_mutually_exclusive_group()
	group.add_argument(
		'--cg',
		dest='use_cg',
		action='store_true',
		help='use iterative solver (conjugate gradient) with Nystroem preconditioner',
		#help=argparse.SUPPRESS
	)
	group.add_argument(
		'--fk',
		dest='use_fk',
		action='store_true',
		help='use iterative solver (conjugate gradient) with Nystroem approximation',
		#help=argparse.SUPPRESS
	)

	args = parser.parse_args()

	# post-processing for optional sig argument
	if 'sigs' in args and args.sigs is not None:
		args.sigs = np.hstack(
			args.sigs
		).tolist()  # flatten list, if (part of it) was generated using the range syntax
		args.sigs = sorted(list(set(args.sigs)))  # remove potential duplicates

	# post-processing for optional model output file argument
	if 'model_file' in args and args.model_file is not None:
		if not args.model_file.endswith('.npz'):
			args.model_file += '.npz'

	_print_splash()

	# check PyTorch GPU support
	if 'use_torch' in args and args.use_torch:
		try:
			import torch
		except ImportError:
			pass
		else:
			if not torch.cuda.is_available():
				print(
					ui.warn_str('\n[WARN]')
					+ ' Your PyTorch installation does not support GPU computation!'
					+ '\n       We recommend running CPU calculations without \'--torch\' for improved performance.'
				)

	# replace solver flags with keyword
	args = vars(args)
	args['solver'] = 'analytic'
	if 'use_cg' in args and args['use_cg']:
		args['solver'] = 'cg'
	elif 'use_fk' in args and args['use_fk']:
		args['solver'] = 'fk'
	args.pop('use_cg', None)
	args.pop('use_fk', None)

	return args
Parses arguments

	Mostly equivalent/copied from cli.py file

	Returns:
		args -- dictionary
	
Parses arguments
Mostly equivalent/copied from cli.py file
Parses arguments Mostly equivalent / copied from cli . py file
def parse_arguments():
	def _add_argument_dataset(parser, help='path to dataset file'):
		parser.add_argument(
			'dataset',
			metavar='<dataset_file>',
			type=lambda x: io.is_file_type(x, 'dataset'),
			help=help,
		)
	def _add_argument_sample_size(parser, subset_str):
		parser.add_argument(
			'n_%s' % subset_str,
			metavar='<n_%s>' % subset_str,
			type=io.is_strict_pos_int,
			help='%s sample size' % subset_str,
		)
	def _add_argument_dir_with_file_type(parser, type, or_file=False):
		parser.add_argument(
			'%s_dir' % type,
			metavar='<%s_dir%s>' % (type, '_or_file' if or_file else ''),
			type=lambda x: io.is_dir_with_file_type(x, type, or_file=or_file),
			help='path to %s directory%s' % (type, ' or file' if or_file else ''),
		)
	parser = argparse.ArgumentParser()
	parser.add_argument(
		'--version',
		action='version',
		version='%(prog)s '
		+ __version__
		+ ' [python '
		+ '.'.join(map(str, sys.version_info[:3]))
		+ ']',
	)
	parser.add_argument(
		'-o',
		'--overwrite',
		dest='overwrite',
		action='store_true',
		help='overwrite existing files',
	)
	parser.add_argument(
		'-p',
		'--max_processes',
		metavar='<max_processes>',
		type=io.is_strict_pos_int,
		help='limit the number of processes for this application',
	)
	parser.add_argument(
		'--torch',
		dest='use_torch',
		action='store_true',
		help='use PyTorch for validation and test',
	)
	_add_argument_dataset(parser)
	_add_argument_sample_size(parser, 'train_init')
	_add_argument_sample_size(parser, 'train_final')
	parser.add_argument(
		'n_steps',
		metavar='<n_steps>',
		type=io.is_strict_pos_int,
		help='number of steps',
	)
	_add_argument_sample_size(parser, 'valid')
	parser.add_argument(
		'-v',
		'--validation_dataset',
		metavar='<validation_dataset_file>',
		dest='valid_dataset',
		type=lambda x: io.is_file_type(x, 'dataset'),
		help='path to validation dataset file',
	)
	parser.add_argument(
		'-s',
		'--sig',
		metavar=('<s1>', '<s2>'),
		dest='sigs',
		type=io.parse_list_or_range,
		help='integer list and/or range <start>:[<step>:]<stop> for the kernel hyper-parameter sigma',
		nargs='+',
	)
	parser.add_argument(
		'--task_dir',
		metavar='<task_dir>',
		dest='task_dir',
		help='user-defined task output dir name',
	)
	group = parser.add_mutually_exclusive_group()
	group.add_argument(
		'--gdml',
		action='store_true',
		help='don\'t include symmetries in the model (GDML)',
	)
	group.add_argument(
		'--cprsn',
		dest='use_cprsn',
		action='store_true',
		help='compress kernel matrix along symmetric degrees of freedom',
	)
	group = parser.add_mutually_exclusive_group()
	group.add_argument(
		'--no_E',
		dest='use_E',
		action='store_false',
		help='only reconstruct force field w/o potential energy surface',
	)
	group.add_argument(
		'--E_cstr',
		dest='use_E_cstr',
		action='store_true',
		help='include the energy constraints in the kernel',
	)
	parser.add_argument(
		'n_test',
		metavar='<n_test>',
		type=io.is_strict_pos_int,
		help='test sample size',
		nargs='?',
		default=None,
	)
	parser.add_argument(
		'--model_file',
		metavar='<model_file>',
		dest='model_file',
		help='user-defined model output file name',
	)
	group = parser.add_mutually_exclusive_group()
	group.add_argument(
		'--cg',
		dest='use_cg',
		action='store_true',
		help='use iterative solver (conjugate gradient) with Nystroem preconditioner',
	)
	group.add_argument(
		'--fk',
		dest='use_fk',
		action='store_true',
		help='use iterative solver (conjugate gradient) with Nystroem approximation',
	)
	args = parser.parse_args()
	if 'sigs' in args and args.sigs is not None:
		args.sigs = np.hstack(
			args.sigs
		).tolist()  
		args.sigs = sorted(list(set(args.sigs)))  
	if 'model_file' in args and args.model_file is not None:
		if not args.model_file.endswith('.npz'):
			args.model_file += '.npz'
	_print_splash()
	if 'use_torch' in args and args.use_torch:
		try:
			import torch
		except ImportError:
			pass
		else:
			if not torch.cuda.is_available():
				print(
					ui.warn_str('\n[WARN]')
					+ ' Your PyTorch installation does not support GPU computation!'
					+ '\n       We recommend running CPU calculations without \'--torch\' for improved performance.'
				)
	args = vars(args)
	args['solver'] = 'analytic'
	if 'use_cg' in args and args['use_cg']:
		args['solver'] = 'cg'
	elif 'use_fk' in args and args['use_fk']:
		args['solver'] = 'fk'
	args.pop('use_cg', None)
	args.pop('use_fk', None)
	return args
def parse_arguments ( ) : def _add_argument_dataset ( parser , help = 'path to dataset file' ) : parser . add_argument ( 'dataset' , metavar = '<dataset_file>' , type = lambda x : io . is_file_type ( x , 'dataset' ) , help = help , ) def _add_argument_sample_size ( parser , subset_str ) : parser . add_argument ( 'n_%s' % subset_str , metavar = '<n_%s>' % subset_str , type = io . is_strict_pos_int , help = '%s sample size' % subset_str , ) def _add_argument_dir_with_file_type ( parser , type , or_file = False ) : parser . add_argument ( '%s_dir' % type , metavar = '<%s_dir%s>' % ( type , '_or_file' if or_file else '' ) , type = lambda x : io . is_dir_with_file_type ( x , type , or_file = or_file ) , help = 'path to %s directory%s' % ( type , ' or file' if or_file else '' ) , ) parser = argparse . ArgumentParser ( ) parser . add_argument ( '--version' , action = 'version' , version = '%(prog)s ' + __version__ + ' [python ' + '.' . join ( map ( str , sys . version_info [ : 3 ] ) ) + ']' , ) parser . add_argument ( '-o' , '--overwrite' , dest = 'overwrite' , action = 'store_true' , help = 'overwrite existing files' , ) parser . add_argument ( '-p' , '--max_processes' , metavar = '<max_processes>' , type = io . is_strict_pos_int , help = 'limit the number of processes for this application' , ) parser . add_argument ( '--torch' , dest = 'use_torch' , action = 'store_true' , help = 'use PyTorch for validation and test' , ) _add_argument_dataset ( parser ) _add_argument_sample_size ( parser , 'train_init' ) _add_argument_sample_size ( parser , 'train_final' ) parser . add_argument ( 'n_steps' , metavar = '<n_steps>' , type = io . is_strict_pos_int , help = 'number of steps' , ) _add_argument_sample_size ( parser , 'valid' ) parser . add_argument ( '-v' , '--validation_dataset' , metavar = '<validation_dataset_file>' , dest = 'valid_dataset' , type = lambda x : io . is_file_type ( x , 'dataset' ) , help = 'path to validation dataset file' , ) parser . add_argument ( '-s' , '--sig' , metavar = ( '<s1>' , '<s2>' ) , dest = 'sigs' , type = io . parse_list_or_range , help = 'integer list and/or range <start>:[<step>:]<stop> for the kernel hyper-parameter sigma' , nargs = '+' , ) parser . add_argument ( '--task_dir' , metavar = '<task_dir>' , dest = 'task_dir' , help = 'user-defined task output dir name' , ) group = parser . add_mutually_exclusive_group ( ) group . add_argument ( '--gdml' , action = 'store_true' , help = 'don\'t include symmetries in the model (GDML)' , ) group . add_argument ( '--cprsn' , dest = 'use_cprsn' , action = 'store_true' , help = 'compress kernel matrix along symmetric degrees of freedom' , ) group = parser . add_mutually_exclusive_group ( ) group . add_argument ( '--no_E' , dest = 'use_E' , action = 'store_false' , help = 'only reconstruct force field w/o potential energy surface' , ) group . add_argument ( '--E_cstr' , dest = 'use_E_cstr' , action = 'store_true' , help = 'include the energy constraints in the kernel' , ) parser . add_argument ( 'n_test' , metavar = '<n_test>' , type = io . is_strict_pos_int , help = 'test sample size' , nargs = '?' , default = None , ) parser . add_argument ( '--model_file' , metavar = '<model_file>' , dest = 'model_file' , help = 'user-defined model output file name' , ) group = parser . add_mutually_exclusive_group ( ) group . add_argument ( '--cg' , dest = 'use_cg' , action = 'store_true' , help = 'use iterative solver (conjugate gradient) with Nystroem preconditioner' , ) group . add_argument ( '--fk' , dest = 'use_fk' , action = 'store_true' , help = 'use iterative solver (conjugate gradient) with Nystroem approximation' , ) args = parser . parse_args ( ) if 'sigs' in args and args . sigs is not None : args . sigs = np . hstack ( args . sigs ) . tolist ( ) args . sigs = sorted ( list ( set ( args . sigs ) ) ) if 'model_file' in args and args . model_file is not None : if not args . model_file . endswith ( '.npz' ) : args . model_file += '.npz' _print_splash ( ) if 'use_torch' in args and args . use_torch : try : import torch except ImportError : pass else : if not torch . cuda . is_available ( ) : print ( ui . warn_str ( '\n[WARN]' ) + ' Your PyTorch installation does not support GPU computation!' + '\n       We recommend running CPU calculations without \'--torch\' for improved performance.' ) args = vars ( args ) args [ 'solver' ] = 'analytic' if 'use_cg' in args and args [ 'use_cg' ] : args [ 'solver' ] = 'cg' elif 'use_fk' in args and args [ 'use_fk' ] : args [ 'solver' ] = 'fk' args . pop ( 'use_cg' , None ) args . pop ( 'use_fk' , None ) return args
Parses arguments
Mostly equivalent/copied from cli.py file
Parses arguments Mostly equivalent / copied from cli . py file
'''Parses arguments

	Mostly equivalent/copied from cli.py file

	Returns:
		args -- dictionary
	''' #help=argparse.SUPPRESS #help=argparse.SUPPRESS # post-processing for optional sig argument # flatten list, if (part of it) was generated using the range syntax # remove potential duplicates # post-processing for optional model output file argument # check PyTorch GPU support # replace solver flags with keyword
None