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(): 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 default_parameters(): # Start with a modified subset of the global parameters default_params = CUDACodeGenerator.default_parameters().copy() return ParameterDict( code=default_params.code, solvers=default_params.solvers, solver=OptionParam( "explicit_euler", list(default_params.solvers.keys()), description="Default solver type", ), block_size=ScalarParam( 256, ge=1, description="Number of threads per CUDA block", ), ode_substeps=ScalarParam( 1, ge=1, description="Number of ODE steps to compute per " "forward function call", ), nvcc=Param("nvcc", description="Command to run nvcc compiler"), gpu_arch=TypelessParam( None, description="The name of the class of nVidia GPU " "architectures for which the CUDA input must " "be compiled", ), gpu_code=TypelessParam( None, description="The names of nVidia GPUs to generate code " "for", ), keep_cuda_code=Param( False, description="If true, CUDA compiler output is kept, and a" "line indicating its location in the file " "system is printed for debugging purposes", ), cuda_cache_dir=TypelessParam( None, description="Directory for compiler caching. Has a " "sensible per-user default. If False, caching " "is disabled.", ), # no_extern_c=Param( # False, # description=""), # cuda_include_dirs=Param( # [""], # description="Additional CUDA include directories"), nvcc_options=Param([""], description="Additional nvcc options"), )
def default_parameters(): default_params = parameters.generation.code.copy() state_repr = dict.__getitem__(default_params.states, "representation") body_repr = dict.__getitem__(default_params.body, "representation") use_cse = dict.__getitem__(default_params.body, "use_cse") optimize_exprs = dict.__getitem__(default_params.body, "optimize_exprs") return ParameterDict(state_repr=state_repr.copy(), body_repr=body_repr.copy(), use_cse=use_cse.copy(), optimize_exprs=optimize_exprs.copy(), generate_jacobian = Param(\ False, description="Generate analytic jacobian "\ "when integrating."),\ generate_lu_factorization = Param(\ False, description="Generate analytic lu" \ "factorization of jacobian when integrating."),\ generate_forward_backward_subst = Param(\ False, description="Generate analytic forward" \ "backward substituion of factorized jacobian when "\ "integrating."),\ )
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(): 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(): import os import sys 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"), **JuliaCodeGenerator.default_parameters(), ) 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] gotran2julia(file_name, params)
def test_name_assign(self): with self.assertRaises(ValueError) as cm: p0 = Param(45, name="jada") p0.name = "bada" self.assertEqual( str(cm.exception), "Cannot set name attribute of " "Param, it is already set to 'jada'", ) p0 = Param(45) p0.name = "bada" self.assertEqual(p0.name, "bada") with self.assertRaises(ValueError) as cm: p0 = Param(45) p0.name = "bada" p0.name = "snada" self.assertEqual( str(cm.exception), "Cannot set name attribute of " "Param, it is already set to 'bada'", )
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 test_init(self): with self.assertRaises(TypeError) as cm: Param(45, 56) self.assertEqual( str(cm.exception), "expected 'str' (got '56' " "which is 'int') as the 'name' argument", ) self.assertEqual(repr(Param(45, "jada")), "Param(45, name='jada')") self.assertEqual(str(Param(45, "jada")), "45") self.assertEqual( repr(Param(45)), repr(Param(45, "jada").copy(include_name=False)), ) self.assertEqual( repr(Param(45, description="BADA")), "Param(45, description='BADA')", )
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)
def test_assign(self): with self.assertRaises(TypeError) as cm: p = Param(45, "bada") p.value = "jada" self.assertEqual( str(cm.exception), "expected 'int' while " "setting parameter 'bada'", ) with self.assertRaises(TypeError) as cm: p = Param("jada", "bada") p.value = 45 self.assertEqual( str(cm.exception), "expected 'str' while " "setting parameter 'bada'", ) with self.assertRaises(ValueError) as cm: p = Param("jada", "bada") p.name = "snaba" self.assertEqual( str(cm.exception), "Cannot set name attribute of " "Param, it is already set to 'bada'", ) p0 = Param(45, "bada") p1 = Param("jada", "snada") p0.value = 56 self.assertEqual(p0.value, 56) p1.value = "bada" self.assertEqual(p1.value, "bada")
def test_equal(self): p0 = Param("snada", "bada") p1 = Param("snada", "bada") self.assertTrue(p0 == p1) p0.value = "bada" self.assertTrue(p0 != p1)
# # You should have received a copy of the GNU Lesser General Public License # along with Gotran. If not, see <http://www.gnu.org/licenses/>. __all__ = ["parameters"] from modelparameters.parameterdict import ParameterDict # ModelParameter imports from modelparameters.parameters import OptionParam, Param, ScalarParam parameters = ParameterDict( # Generation parameters generation=ParameterDict( class_code=Param( False, description="If true methods are contained " "inside a class", ), # Code generation parameters code=ParameterDict( # Float precision float_precision=OptionParam( "double", ["double", "single"], description="Float precision in generated " "code.", ), # Parameter for default argument order default_arguments=OptionParam( "stp", ["tsp", "stp", "spt", "ts", "st"], description="Default input argument order: " "s=states, p=parameters, t=time",
def _default_latex_params(): """ Initializes default parameters. """ params = dict() # Specify output file params["output"] = Param("", description="Specify LaTeX output file") # Set number of columns per page # FIXME: ScalarParam might cause parse_args() to crash due to non-ASCII # symbols. # params["page_columns"] = ScalarParam( # 1, ge=1, description="Set number of columns per page in " # "LaTeX document") params["page_columns"] = Param( 1, description="Set number of columns per page in " "LaTeX document", ) # Set equation font size # FIXME: ScalarParam might cause parse_args() to crash due to non-ASCII # symbols. # params["font_size"] = ScalarParam( # 10, ge=1, description="Set global font size for LaTeX document") params["font_size"] = Param( 10.0, description="Set global font size for LaTeX document", ) # Set font size for mathematical expressions. # FIXME: ScalarParam might cause parse_args() to crash due to non-ASCII # symbols. # params["math_font_size"] = ScalarParam( # 1, ge=1, description="Set font size for mathematical " # "expressions in LaTeX document. Uses global font size if left " # "blank") params["math_font_size"] = Param( 0.0, description="Set font size for mathematical expressions in " "LaTeX document. Uses global font size if left blank", ) # Toggle bold equation labels params["bold_equation_labels"] = Param( True, description="Give equation labels a bold typeface in " "LaTeX document", ) # If set to False, does not generate the preamble params["preamble"] = Param( True, description="If set to False, LaTeX document will be " "be generated without the preamble", ) # If set to true, sets document to a landscape page layout params["landscape"] = Param( False, description="Set LaTeX document to landscape layout", ) # Latex separator between factors in products params["mul_symbol"] = Param( "dot", description="Multiplication symbol for Sympy LatexPrinter", ) # Flag to enable page numbers params["page_numbers"] = Param(True, description="Enable page numbers") # Flag to disable state table (currently unused) # params["no_state_descriptions"] = Param( # False, description="Disable table column for state descriptions") # Flag to disable parameter table (currently unused) # params["no_parameter_descriptions"] = Param( # False, description="Disable table column for parameter descriptions") # Set headline types for States, Parameters and Components params["section_type"] = Param( "section", description="Section type (e.g. 'section', 'subsection')", ) # Set page margins params["margins"] = Param( "", description="Set page margins (e.g. '0.75in'). Uses LaTeX " "defaults if left blank", ) # Set column seperator distance params["columnsep"] = Param( "", description="Set column separator distance (e.g. '0.25cm'). " "Uses LaTeX default if left blank", ) # Set column separator line width params["columnseprule"] = Param( "", description="Set column separator line width (e.g. '0.2pt'). " "Uses LaTeX default if left blank", ) # Flag to let the code generator attempt automatically converting # state and parameter names in descriptions to math-mode params["auto_format_description"] = Param( False, description="Automatically format state and parameter " "descriptions", ) # Flag to toggle numbering style for equations. params["equation_subnumbering"] = Param( True, description="Use component-wise equation subnumbering", ) params["parameter_description_cell_style"] = Param( "l", description="Set description cell type for the parameter table. " "Use 'X' for long descriptions, or 'p{5cm}' to set a fixed 5 cm", ) params["state_description_cell_style"] = Param( "l", description="Set description cell type for the state table. " "Use 'X' for long descriptions, or 'p{5cm}' to set a fixed 5 cm", ) # Return the ParameterDict return ParameterDict(**params)