Code generation

Sympy expressions can be converted to code strings using a cellmlmanip.printer.Printer.

class cellmlmanip.printer.Printer(symbol_function=None, derivative_function=None)[source]

Bases: Printer

Converts Sympy expressions to strings of Python code.

To use, create a Printer instance, and call its method doprint() with a Sympy expression as argument.

To extend this to other languages, create a Printer subclass, and override _function_names, _literal_names, or any of the _print_X methods as necessary.

Parameters:
  • symbol_function – A function that converts sympy.Symbols to strings (variable names).

  • derivative_function – A function that converts derivatives to strings.

doprint(expr)[source]

Returns printer’s representation for expr (as a string)

emptyPrinter(expr)[source]

Called by Printer as a last resort for unknown expressions.