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: sympy.printing.printer.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.

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

  • derivative_function – A function that converts derivatives to strings.


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


Called by Printer as a last resort for unknown expressions.