def test_optstr(self): base0, base1, p = default_params(sp) self.assertEqual( p.optstr(), " --a.abla sin --a.abli 123 --b.bblal 987 " "--b.bling akjh --other 0.1239 --something_very_long 3", ) p.parse_args(["--a.abla", "cos", "--b.bling", "smada"]) self.assertEqual(p.a.abla, "cos") self.assertEqual(p.b.bling, "smada") with self.assertRaises(ValueError) as cm: p.parse_args(["--other", "-1"]) self.assertEqual( six.text_type(cm.exception), ("Trying to set 'other' while parsing " + "command line, but Illegal value 'other': -1.0 " + b"\xe2\x88\x89 (0, 10]".decode("utf-8")), ) p = ParameterDict(list=[1, 2, 3, 4, 5]) p.parse_args(["--list", "-1", "1", "2"]) self.assertEqual(p.list, [-1, 1, 2])
def main(): import os import sys generation_params = CUDACodeGenerator.default_parameters() params = ParameterDict( list_timings=Param( False, description="If true timings for reading " "and evaluating the model is listed.", ), system_headers=Param( True, description="If true system " "headers needed to compile moudle is " "included.", ), output=Param("", description="Specify output file name"), **dict((name, param) for name, param in list(generation_params.items()) if name not in ["class_code"]), ) params.parse_args(usage="usage: %prog FILE [options]") # sys.argv[2:]) if len(sys.argv) < 2: raise RuntimeError("Expected a single gotran file argument") if not os.path.isfile(sys.argv[1]): raise IOError("Expected the argument to be a file") file_name = sys.argv[1] gotran2cuda(file_name, params)
def main(): generation_params = parameters.generation.copy() params = ParameterDict( list_timings=Param( False, description="If true timings for reading " "and evaluating the model is listed.", ), output=Param("", description="Specify output file name"), import_inside_functions=Param( False, description="Perform imports inside functions", ), namespace=OptionParam( "math", ["math", "np", "numpy", "ufl"], description="The math namespace of the generated code", ), **generation_params, ) params.parse_args(usage="usage: %prog FILE [options]") # sys.argv[2:]) if len(sys.argv) < 2: raise RuntimeError("Expected a single gotran file argument") if not os.path.isfile(sys.argv[1]): raise IOError("Expected the argument to be a file") file_name = sys.argv[1] gotran2py(file_name, params)
def main(): params = ParameterDict(flat_view=Param( True, description="List all objects in a flat view"), ) params.parse_args(usage="usage: %prog FILE [options]") if len(sys.argv) < 2: raise RuntimeError("Expected a single gotran file argument") if not os.path.isfile(sys.argv[1]): raise IOError("Expected the argument to be a file") file_name = sys.argv[1] gotranprobe(file_name, params)
def main(): params = ParameterDict(output=Param( "", description="Specify output file name"), **DOLFINCodeGenerator.default_parameters()) params.parse_args(usage="usage: %prog FILE [options]") # sys.argv[2:]) if len(sys.argv) < 2: raise RuntimeError("Expected a single gotran file argument") if not os.path.isfile(sys.argv[1]): raise IOError("Expected the argument to be a file") file_name = sys.argv[1] gotran2dolfin(file_name, params)
def main(): params = _default_latex_params() params = ParameterDict( sympy_contraction=Param( True, description="If True sympy contraction" " will be used, turning (V-3)/2 into V/2-3/2", ), **params, ) params.parse_args(usage="usage: %prog FILE [options]") if len(sys.argv) < 2: raise RuntimeError("Expected a single gotran file argument") if not os.path.isfile(sys.argv[1]): raise IOError("Expected the argument to be a file") filename = sys.argv[1] gotran2latex(filename, params)
def main(): import os import sys params = ParameterDict( components=Param( [""], description="List all components that will be " "exported.", ), name=Param("", description="Specify name of exported ODE."), ) params.parse_args(usage="usage: %prog FILE [options]") if len(sys.argv) < 2: raise RuntimeError("Expected a single gotran file argument") if not os.path.isfile(sys.argv[1]): raise IOError("Expected the argument to be a file") file_name = sys.argv[1] gotranexport(file_name, params)
def main(): generation_params = MatlabCodeGenerator.default_parameters() params = ParameterDict( list_timings=Param( False, description="If true timings for reading " "and evaluating the model is listed.", ), output=Param("", description="Specify output file name"), **generation_params, ) params.parse_args(usage="usage: %prog FILE [options]") # sys.argv[2:]) if len(sys.argv) < 2: raise RuntimeError("Expected a single gotran file argument") if not os.path.isfile(sys.argv[1]): raise IOError("Expected the argument to be a file") file_name = sys.argv[1] gotran2matlab(file_name, params)
def main(): import os import sys body_params = parameters.generation.code.body.copy() code_params = ParameterDict( language=OptionParam("C", ["Python", "C"]), body_repr=dict.__getitem__(body_params, "representation"), use_cse=dict.__getitem__(body_params, "use_cse"), optimize_exprs=dict.__getitem__(body_params, "optimize_exprs"), generate_jacobian=Param( False, description="Generate and use analytic " "jacobian when integrating.", ), ) steady_state = ParameterDict( solve=Param( False, description="If true scipy.optimize.root is used " "to find a steady state for a given parameters.", ), method=OptionParam( "hybr", [ "hybr", "lm", "broyden1", "broyden2", "anderson", "linearmixing", "diagbroyden", "excitingmixing", "krylov", ], ), tol=ScalarParam(1e-5, description="Tolerance for root finding algorithm."), ) solver = OptionParam( "scipy", ["scipy"] + list(parameters.generation.solvers.keys()), description="The solver that will be used to " "integrate the ODE.", ) params = ParameterDict( solver=solver, steady_state=steady_state, parameters=Param([""], description="Set parameter of model"), init_conditions=Param([""], description="Set initial condition of model"), tstop=ScalarParam(100.0, gt=0, description="Time for stopping simulation"), dt=ScalarParam(0.1, gt=0, description="Timestep for plotting."), plot_y=Param(["V"], description="States or monitored to plot on the y axis."), plot_x=Param( "time", description="Values used for the x axis. Can be time " "and any valid plot_y variable.", ), model_arguments=Param([""], description="Set model arguments of the model"), code=code_params, save_results=Param( False, description="If True the results will be " "saved to a 'results.csv' file.", ), basename=Param( "results", description="The basename of the results " "file if the 'save_results' options is True.", ), ) params.parse_args(usage="usage: %prog FILE [options]") if len(sys.argv) < 2: error("Expected a single gotran file argument.") if not os.path.isfile(sys.argv[1]): error("Expected the argument to be a file.", exception=IOError) file_name = sys.argv[1] gotranrun(file_name, params)