Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generate(ast_tree: ast.Tree, model_name: str):
"""
:param ast_tree: AST to generate from
:param model_name: class to generate
:return: sympy source code for model
"""
component_ref = ast.ComponentRef.from_string(model_name)
ast_tree_new = copy.deepcopy(ast_tree)
ast_walker = TreeWalker()
flat_tree = flatten(ast_tree_new, component_ref)
sympy_gen = SympyGenerator()
ast_walker.walk(sympy_gen, flat_tree)
return sympy_gen.src[flat_tree]
def generate(ast_tree: ast.Tree, model_name: str, options: Dict[str, bool]=None) -> Model:
"""
:param ast_tree: AST to generate from
:param model_name: class to generate
:param options: dictionary of generator options
:return: casadi model
"""
options = _merge_default_options(options)
component_ref = ast.ComponentRef.from_string(model_name)
ast_walker = GeneratorWalker()
flat_tree = flatten(ast_tree, component_ref)
component_ref_tuple = component_ref.to_tuple()
casadi_gen = Generator(flat_tree, component_ref_tuple[-1], options)
ast_walker.walk(casadi_gen, flat_tree)
return casadi_gen.model
def generate(ast_tree: ast.Tree, model_name: str):
"""
:param ast_tree: AST to generate from
:param model_name: class to generate
:return: sympy source code for model
"""
component_ref = ast.ComponentRef.from_string(model_name)
ast_tree_new = copy.deepcopy(ast_tree)
ast_walker = TreeWalker()
flat_tree = flatten(ast_tree_new, component_ref)
gen = XmlGenerator()
ast_walker.walk(gen, flat_tree)
return etree.tostring(gen.xml[flat_tree], pretty_print=True).decode('utf-8')