equation

classes.equation

Handling Equations and Expressions

Attributes

Name Description
E
coupling_variables
lambda_symbol

Functions

Name Description
add_spaces_around_operators
build_dependency_graph Builds a directed graph of dependencies from the eq_dict using SymPy.
conditionals2piecewise
convert_ifelse_to_np_where Convert a sympy.pycode output string from a simple if-else format to a numpy where format.
convert_numpy_where_to_sympy Converts a numpy.where expression to a sympy Piecewise expression.
dependency_tree
extract_parts_from_numpy_where Extracts the condition, if_true, and if_false parts from a numpy.where or where expression string.
generate_global_coupling_function Generate the global coupling function based on given pre and post expressions.
get_latex_equation
get_symbolic_coupling Get the symbolic coupling expressions for the given coupling function.
piecewise2julia Convert a sympy Piecewise expression to a Julia ifelse expression string.
piecewise2numpy Convert a sympy Piecewise expression to an equivalent nested numpy.where expression.
rename_uppercase_variables
render_latex_equations
replace_H
replace_acronyms
set_specific_symbols_to_zero
sort_equations_by_dependencies
sub_equation
substitute_function_in_state_equations
symbolic_conditions
symbolic_differential_equations
symbolic_model_equations
symbolic_model_functions
symbolic_topological_sort
sympify_value
topological_sort Performs topological sorting on the dependency graph.
topological_sort_equations
unify_coupling_terms
update_class_relationships
update_mathematical_relationships

add_spaces_around_operators

classes.equation.add_spaces_around_operators(expression)

build_dependency_graph

classes.equation.build_dependency_graph(eq_dict)

Builds a directed graph of dependencies from the eq_dict using SymPy.

conditionals2piecewise

classes.equation.conditionals2piecewise(metadata_equation)

convert_ifelse_to_np_where

classes.equation.convert_ifelse_to_np_where(code_str)

Convert a sympy.pycode output string from a simple if-else format to a numpy where format.

code_str (str): A string representing a sympy.pycode output, e.g., “((-0.1*z**7) if (z < 0) else (0))“.

Returns: str: Converted string using np.where, e.g., “np.where(z < 0, -0.1*z**7, 0)“.

convert_numpy_where_to_sympy

classes.equation.convert_numpy_where_to_sympy(python_string)

Converts a numpy.where expression to a sympy Piecewise expression. Args: - condition_str: The condition string. - if_true_str: The expression if the condition is True. - if_false_str: The expression if the condition is False. Returns: - A sympy Piecewise expression.

dependency_tree

classes.equation.dependency_tree(equations)

extract_parts_from_numpy_where

classes.equation.extract_parts_from_numpy_where(python_string)

Extracts the condition, if_true, and if_false parts from a numpy.where or where expression string. Args: - python_string: A string in the format “numpy.where(condition, if_true, if_false)” or “where(condition, if_true, if_false)” Returns: - A tuple containing the condition, if_true, and if_false parts as strings.

generate_global_coupling_function

classes.equation.generate_global_coupling_function(
    pre_expr,
    post_expr,
    j_index_start=0,
)

Generate the global coupling function based on given pre and post expressions.

:param pre_expr: The ‘pre’ sympy expression involving x_i and x_j. :param post_expr: The ‘post’ sympy expression involving gx. :return: The global coupling function as a sympy expression.

get_latex_equation

classes.equation.get_latex_equation(model, func_dict='all', mul_symbol='dot')

get_symbolic_coupling

classes.equation.get_symbolic_coupling(coupling_function)

Get the symbolic coupling expressions for the given coupling function.

Parameters

Name Type Description Default
coupling_function str or CouplingFunction The coupling function to retrieve symbolic expressions for. required

Returns

Name Type Description
dict dict A dictionary containing the symbolic expressions for the pre and post functions. The keys are ‘pre’ and ‘post’, and the values are SymPy expressions.

Raises

Name Type Description
SomeException Description of the exception raised, if any.

piecewise2julia

classes.equation.piecewise2julia(piecewise_expr)

Convert a sympy Piecewise expression to a Julia ifelse expression string.

Parameters: piecewise_expr (sympy.Piecewise): A sympy Piecewise object.

Returns: str: A Julia-compatible string representing the Piecewise expression using nested ifelse.

piecewise2numpy

classes.equation.piecewise2numpy(piecewise_expr, fully_qualified_modules=False)

Convert a sympy Piecewise expression to an equivalent nested numpy.where expression.

Parameters

Name Type Description Default
piecewise_expr Piecewise A sympy Piecewise expression. required

Returns

Name Type Description
str str A string representing the equivalent numpy.where statement.

rename_uppercase_variables

classes.equation.rename_uppercase_variables(input_equation)

render_latex_equations

classes.equation.render_latex_equations(
    model,
    odes_first=True,
    evaluate=False,
    separator='\\text{where }',
    markdown=False,
    subs=None,
)

replace_H

classes.equation.replace_H(eq_dict)

replace_acronyms

classes.equation.replace_acronyms(key, cls)

set_specific_symbols_to_zero

classes.equation.set_specific_symbols_to_zero(
    equation_str,
    symbols_to_zero=coupling_variables,
)

sort_equations_by_dependencies

classes.equation.sort_equations_by_dependencies(equations)

sub_equation

classes.equation.sub_equation(eq, model)

substitute_function_in_state_equations

classes.equation.substitute_function_in_state_equations(sv_eqs, funcs)

symbolic_conditions

classes.equation.symbolic_conditions(NMM, zero_coupling=False, **kwargs)

symbolic_differential_equations

classes.equation.symbolic_differential_equations(
    NMM,
    zero_coupling=False,
    **kwargs,
)

symbolic_model_equations

classes.equation.symbolic_model_equations(NMM, zero_coupling=False, **kwargs)

symbolic_model_functions

classes.equation.symbolic_model_functions(NMM, zero_coupling=False, **kwargs)

symbolic_topological_sort

classes.equation.symbolic_topological_sort(equations)

sympify_value

classes.equation.sympify_value(v, acronym='', evaluate=False)

topological_sort

classes.equation.topological_sort(graph)

Performs topological sorting on the dependency graph.

topological_sort_equations

classes.equation.topological_sort_equations(variable_dict, dependency_tree)

unify_coupling_terms

classes.equation.unify_coupling_terms(eq_string)

update_class_relationships

classes.equation.update_class_relationships(s_cls, k_cls)

update_mathematical_relationships

classes.equation.update_mathematical_relationships(model)