User Guide
nmodl::visitor::SympyReplaceSolutionsVisitor Class Reference

Replace statements in node with pre_solve_statements, tmp_statements, and solutions. More...

Detailed Description

Replace statements in node with pre_solve_statements, tmp_statements, and solutions.

The goal is to replace statements with solutions in place. In this way we can allow (to some extent) the use of control flow blocks and assignments. pre_solve_statements are added in front of the replaced statements in case their variable needs updating. StatementDispenser keeps track of what needs updating. Let's start with some nomenclature:

  • statement: a line in the .mod file. It can be a diff_eq_expression, binary_expression, or linEquation
  • old_Statement: line in the staementBlock that must be replaced with the solution
  • solution_statements/ new_statement: a nmodl-statement (always binary expression) provided by sympy that assigns a variable
  • pre_solve_Statements: statements that update the variables (i.e. x = old_x)
  • tmp_statements: assignment of temporary variables in the solution generated by sympy in case –cse. (i.e. \( tmp = f (...) \)

We employ a multi-step approach:

  • try to replace the old_statements (not binary_expressions) and in "assignment form: \_form#8@_fakenl" with the corresponding solution matching by variable (i.e. x in \( x = f(...) \))
  • try to replace the old_Statements with a greedy approach. When we find a diff_eq_expression/linEquation that needs replacing we take the next solution that was not yet used
  • add all the remaining solutions at the end

Let's finish with an example (that are usually better than blabbling around).

Imagine we have this derivative block in the ast (before SympyReplaceSolutionsVisitor passes):

DERIVATIVE d {
LOCAL a, old_x, old_y, old_z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7
b = 1
x' = x + y + a + b
if ( x == 0) {
a = a + 1
# x = x + 1 // this would be an error. Explained later
}
y' = x + y + a
z' = y + a
x = x + 1
}

where SympySolverVisitor already added variables in the LOCAL declaration.

Sympy solver visitor also provides:

  • pre-solve statements:
old_x = x
old_y = y
old_z = z
  • tmp statements:
tmp0 = 2.0*dt
tmp1 = 1.0/(tmp0-1.0)
tmp2 = pow(dt, 2)
tmp3 = b*tmp2
tmp4 = dt*old_x
tmp5 = a*dt
tmp6 = dt*old_y
tmp7 = tmp5+tmp6
  • solutions:
x = -tmp1*(b*dt+old_x-tmp3-tmp4+tmp7)
y = -tmp1*(old_y+tmp3+tmp4+tmp5-tmp6)
z = -tmp1*(-a*tmp2+b*pow(dt, 3)+old_x*tmp2-old_y*tmp2-old_z*tmp0+old_z+tmp7)

SympySolveVisitor works in this way:

DERIVATIVE d { // nothing to do
LOCAL a, old_x, old_y, old_z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7 // nothing to do
b = 1 // initial statement, nothing to do
x' = x + y + a + b -> old_x = x // before printing this solution let's
old_y = y // flush the pre solve statements
old_z = z // mark down that we did this
tmp0 = 2.0*dt // we also flush the tmp statements
tmp1 = 1.0/(tmp0-1.0)
tmp2 = pow(dt, 2)
tmp3 = b*tmp2
tmp4 = dt*old_x
tmp5 = a*dt
tmp6 = dt*old_y
tmp7 = tmp5+tmp6
x = -tmp1*(b*dt+old_x-tmp3-tmp4+tmp7) // finally, the solution
if ( x == 0) { // nothing to do
a = a + 1 // mark down the tmp statements and pre solve statements
// that contain 'a' in the rhs as in need for an update
// x = x + 1 // the same as before but for 'x'. In particular a pre
// solve statement is marked for updating. This will
// produce an error later in the code
} // nothing to do
y' = x + y + a -> // old_x = x // here, if 'x = x + 1' were not commented, the
// code would try to print this line an throw an
// error since the pre solve statements were already
// printed once
tmp5 = a*dt // flush the tmp statements that need updating. In
tmp7 = tmp5+tmp6 // our example, all the tmp statements that
// directly or indirectly depend on a
// for performance, we print only the ones that need updating
z' = y + a -> z = -tmp1*(-a*tmp2+b*pow(dt, 3)+old_x*tmp2-old_y*tmp2-old_z*tmp0+old_z+tmp7)
// nothing is marked for updating (among pre solve statements and tmp
// statements): just print the solution
x = x + 1 // nothing to do
} // nothing to do

Last notes:

For linEquations or NonLinEquations association of the solution with a particular statement could be impossible. For example \( ~ x + y = 0 \) does not have a simple variable in the lhs. Thus, an association with a particular solution statement is not possible. Thus we do 2 runs where we first match everything we can by value and then we associate everything we can in a greedy way.

For large system of equations the code sets up the J matrix and F vector to be sent to eigen for the Newton method which will solve a bunch of J x = F for each time step). In this case it is always safe to replace greedy because sympy does not sort the equations in the matrix/vector. In addition, cse is disabled by default. Thus, there is a 1:1 correspondence of an equation of the original mod file and a row of the matrix and an element of F. So if we have:

LINEAR lin {
~ x = ...
a = a + 1
~ y = ...
~ z = ...
~ w = ...
}

We get the vector F and matrix J

F = [0, J = [0, 4, 8, 12,
1, 1, 5, 9, 13,
2, 2, 6, 10, 14,
3] 3, 7, 11, 15]

Where the numbers indicate their column-wise index. The solution replacement becomes:

~ x = ... -> F[0] = ...
J[0] = ...
J[4] = ...
J[8] = ...
J[12] = ...
a = a + 1
~ y = ... -> ...

Definition at line 212 of file sympy_replace_solutions_visitor.hpp.

#include <sympy_replace_solutions_visitor.hpp>

Inheritance diagram for nmodl::visitor::SympyReplaceSolutionsVisitor:
nmodl::visitor::AstVisitor nmodl::visitor::Visitor

Classes

struct  InterleavesCounter
 Count interleaves of assignment statement inside the system of equations. More...
 
struct  StatementDispenser
 Sorts and maps statements to variables keeping track of what needs updating. More...
 

Public Types

enum  ReplacePolicy { ReplacePolicy::VALUE = 0, ReplacePolicy::GREEDY = 1 }
 

Public Member Functions

 SympyReplaceSolutionsVisitor ()=delete
 Empty ctor. More...
 
 SympyReplaceSolutionsVisitor (const std::vector< std::string > &pre_solve_statements, const std::vector< std::string > &solutions, const std::unordered_set< ast::Statement * > &to_be_removed, const ReplacePolicy policy, size_t n_next_equations, const std::string &tmp_unique_prefix)
 Default constructor. More...
 
int replaced_statements_begin () const
 idx (in the new statementVector) of the first statement that was added. More...
 
int replaced_statements_end () const
 idx (in the new statementVector) of the last statement that was added. More...
 
void visit_statement_block (ast::StatementBlock &node) override
 visit node of type ast::StatementBlock More...
 
void visit_diff_eq_expression (ast::DiffEqExpression &node) override
 visit node of type ast::DiffEqExpression More...
 
void visit_lin_equation (ast::LinEquation &node) override
 visit node of type ast::LinEquation More...
 
void visit_non_lin_equation (ast::NonLinEquation &node) override
 visit node of type ast::NonLinEquation More...
 
void visit_binary_expression (ast::BinaryExpression &node) override
 visit node of type ast::BinaryExpression More...
 
- Public Member Functions inherited from nmodl::visitor::AstVisitor
void visit_node (ast::Node &node) override
 visit node of type ast::Node More...
 
void visit_statement (ast::Statement &node) override
 visit node of type ast::Statement More...
 
void visit_expression (ast::Expression &node) override
 visit node of type ast::Expression More...
 
void visit_block (ast::Block &node) override
 visit node of type ast::Block More...
 
void visit_identifier (ast::Identifier &node) override
 visit node of type ast::Identifier More...
 
void visit_number (ast::Number &node) override
 visit node of type ast::Number More...
 
void visit_string (ast::String &node) override
 visit node of type ast::String More...
 
void visit_integer (ast::Integer &node) override
 visit node of type ast::Integer More...
 
void visit_float (ast::Float &node) override
 visit node of type ast::Float More...
 
void visit_double (ast::Double &node) override
 visit node of type ast::Double More...
 
void visit_boolean (ast::Boolean &node) override
 visit node of type ast::Boolean More...
 
void visit_name (ast::Name &node) override
 visit node of type ast::Name More...
 
void visit_prime_name (ast::PrimeName &node) override
 visit node of type ast::PrimeName More...
 
void visit_indexed_name (ast::IndexedName &node) override
 visit node of type ast::IndexedName More...
 
void visit_var_name (ast::VarName &node) override
 visit node of type ast::VarName More...
 
void visit_argument (ast::Argument &node) override
 visit node of type ast::Argument More...
 
void visit_react_var_name (ast::ReactVarName &node) override
 visit node of type ast::ReactVarName More...
 
void visit_read_ion_var (ast::ReadIonVar &node) override
 visit node of type ast::ReadIonVar More...
 
void visit_write_ion_var (ast::WriteIonVar &node) override
 visit node of type ast::WriteIonVar More...
 
void visit_nonspecific_cur_var (ast::NonspecificCurVar &node) override
 visit node of type ast::NonspecificCurVar More...
 
void visit_electrode_cur_var (ast::ElectrodeCurVar &node) override
 visit node of type ast::ElectrodeCurVar More...
 
void visit_range_var (ast::RangeVar &node) override
 visit node of type ast::RangeVar More...
 
void visit_global_var (ast::GlobalVar &node) override
 visit node of type ast::GlobalVar More...
 
void visit_pointer_var (ast::PointerVar &node) override
 visit node of type ast::PointerVar More...
 
void visit_random_var (ast::RandomVar &node) override
 visit node of type ast::RandomVar More...
 
void visit_bbcore_pointer_var (ast::BbcorePointerVar &node) override
 visit node of type ast::BbcorePointerVar More...
 
void visit_extern_var (ast::ExternVar &node) override
 visit node of type ast::ExternVar More...
 
void visit_param_block (ast::ParamBlock &node) override
 visit node of type ast::ParamBlock More...
 
void visit_independent_block (ast::IndependentBlock &node) override
 visit node of type ast::IndependentBlock More...
 
void visit_assigned_block (ast::AssignedBlock &node) override
 visit node of type ast::AssignedBlock More...
 
void visit_state_block (ast::StateBlock &node) override
 visit node of type ast::StateBlock More...
 
void visit_initial_block (ast::InitialBlock &node) override
 visit node of type ast::InitialBlock More...
 
void visit_constructor_block (ast::ConstructorBlock &node) override
 visit node of type ast::ConstructorBlock More...
 
void visit_destructor_block (ast::DestructorBlock &node) override
 visit node of type ast::DestructorBlock More...
 
void visit_statement_block (ast::StatementBlock &node) override
 visit node of type ast::StatementBlock More...
 
void visit_derivative_block (ast::DerivativeBlock &node) override
 visit node of type ast::DerivativeBlock More...
 
void visit_linear_block (ast::LinearBlock &node) override
 visit node of type ast::LinearBlock More...
 
void visit_non_linear_block (ast::NonLinearBlock &node) override
 visit node of type ast::NonLinearBlock More...
 
void visit_discrete_block (ast::DiscreteBlock &node) override
 visit node of type ast::DiscreteBlock More...
 
void visit_function_table_block (ast::FunctionTableBlock &node) override
 visit node of type ast::FunctionTableBlock More...
 
void visit_function_block (ast::FunctionBlock &node) override
 visit node of type ast::FunctionBlock More...
 
void visit_procedure_block (ast::ProcedureBlock &node) override
 visit node of type ast::ProcedureBlock More...
 
void visit_net_receive_block (ast::NetReceiveBlock &node) override
 visit node of type ast::NetReceiveBlock More...
 
void visit_solve_block (ast::SolveBlock &node) override
 visit node of type ast::SolveBlock More...
 
void visit_breakpoint_block (ast::BreakpointBlock &node) override
 visit node of type ast::BreakpointBlock More...
 
void visit_before_block (ast::BeforeBlock &node) override
 visit node of type ast::BeforeBlock More...
 
void visit_after_block (ast::AfterBlock &node) override
 visit node of type ast::AfterBlock More...
 
void visit_ba_block (ast::BABlock &node) override
 visit node of type ast::BABlock More...
 
void visit_for_netcon (ast::ForNetcon &node) override
 visit node of type ast::ForNetcon More...
 
void visit_kinetic_block (ast::KineticBlock &node) override
 visit node of type ast::KineticBlock More...
 
void visit_unit_block (ast::UnitBlock &node) override
 visit node of type ast::UnitBlock More...
 
void visit_constant_block (ast::ConstantBlock &node) override
 visit node of type ast::ConstantBlock More...
 
void visit_neuron_block (ast::NeuronBlock &node) override
 visit node of type ast::NeuronBlock More...
 
void visit_unit (ast::Unit &node) override
 visit node of type ast::Unit More...
 
void visit_double_unit (ast::DoubleUnit &node) override
 visit node of type ast::DoubleUnit More...
 
void visit_local_var (ast::LocalVar &node) override
 visit node of type ast::LocalVar More...
 
void visit_limits (ast::Limits &node) override
 visit node of type ast::Limits More...
 
void visit_number_range (ast::NumberRange &node) override
 visit node of type ast::NumberRange More...
 
void visit_constant_var (ast::ConstantVar &node) override
 visit node of type ast::ConstantVar More...
 
void visit_binary_operator (ast::BinaryOperator &node) override
 visit node of type ast::BinaryOperator More...
 
void visit_unary_operator (ast::UnaryOperator &node) override
 visit node of type ast::UnaryOperator More...
 
void visit_reaction_operator (ast::ReactionOperator &node) override
 visit node of type ast::ReactionOperator More...
 
void visit_paren_expression (ast::ParenExpression &node) override
 visit node of type ast::ParenExpression More...
 
void visit_binary_expression (ast::BinaryExpression &node) override
 visit node of type ast::BinaryExpression More...
 
void visit_diff_eq_expression (ast::DiffEqExpression &node) override
 visit node of type ast::DiffEqExpression More...
 
void visit_unary_expression (ast::UnaryExpression &node) override
 visit node of type ast::UnaryExpression More...
 
void visit_non_lin_equation (ast::NonLinEquation &node) override
 visit node of type ast::NonLinEquation More...
 
void visit_lin_equation (ast::LinEquation &node) override
 visit node of type ast::LinEquation More...
 
void visit_function_call (ast::FunctionCall &node) override
 visit node of type ast::FunctionCall More...
 
void visit_watch (ast::Watch &node) override
 visit node of type ast::Watch More...
 
void visit_ba_block_type (ast::BABlockType &node) override
 visit node of type ast::BABlockType More...
 
void visit_unit_def (ast::UnitDef &node) override
 visit node of type ast::UnitDef More...
 
void visit_factor_def (ast::FactorDef &node) override
 visit node of type ast::FactorDef More...
 
void visit_valence (ast::Valence &node) override
 visit node of type ast::Valence More...
 
void visit_unit_state (ast::UnitState &node) override
 visit node of type ast::UnitState More...
 
void visit_local_list_statement (ast::LocalListStatement &node) override
 visit node of type ast::LocalListStatement More...
 
void visit_model (ast::Model &node) override
 visit node of type ast::Model More...
 
void visit_define (ast::Define &node) override
 visit node of type ast::Define More...
 
void visit_include (ast::Include &node) override
 visit node of type ast::Include More...
 
void visit_param_assign (ast::ParamAssign &node) override
 visit node of type ast::ParamAssign More...
 
void visit_assigned_definition (ast::AssignedDefinition &node) override
 visit node of type ast::AssignedDefinition More...
 
void visit_conductance_hint (ast::ConductanceHint &node) override
 visit node of type ast::ConductanceHint More...
 
void visit_expression_statement (ast::ExpressionStatement &node) override
 visit node of type ast::ExpressionStatement More...
 
void visit_protect_statement (ast::ProtectStatement &node) override
 visit node of type ast::ProtectStatement More...
 
void visit_from_statement (ast::FromStatement &node) override
 visit node of type ast::FromStatement More...
 
void visit_while_statement (ast::WhileStatement &node) override
 visit node of type ast::WhileStatement More...
 
void visit_if_statement (ast::IfStatement &node) override
 visit node of type ast::IfStatement More...
 
void visit_else_if_statement (ast::ElseIfStatement &node) override
 visit node of type ast::ElseIfStatement More...
 
void visit_else_statement (ast::ElseStatement &node) override
 visit node of type ast::ElseStatement More...
 
void visit_watch_statement (ast::WatchStatement &node) override
 visit node of type ast::WatchStatement More...
 
void visit_mutex_lock (ast::MutexLock &node) override
 visit node of type ast::MutexLock More...
 
void visit_mutex_unlock (ast::MutexUnlock &node) override
 visit node of type ast::MutexUnlock More...
 
void visit_conserve (ast::Conserve &node) override
 visit node of type ast::Conserve More...
 
void visit_compartment (ast::Compartment &node) override
 visit node of type ast::Compartment More...
 
void visit_lon_difuse (ast::LonDifuse &node) override
 visit node of type ast::LonDifuse More...
 
void visit_reaction_statement (ast::ReactionStatement &node) override
 visit node of type ast::ReactionStatement More...
 
void visit_lag_statement (ast::LagStatement &node) override
 visit node of type ast::LagStatement More...
 
void visit_constant_statement (ast::ConstantStatement &node) override
 visit node of type ast::ConstantStatement More...
 
void visit_table_statement (ast::TableStatement &node) override
 visit node of type ast::TableStatement More...
 
void visit_suffix (ast::Suffix &node) override
 visit node of type ast::Suffix More...
 
void visit_useion (ast::Useion &node) override
 visit node of type ast::Useion More...
 
void visit_nonspecific (ast::Nonspecific &node) override
 visit node of type ast::Nonspecific More...
 
void visit_electrode_current (ast::ElectrodeCurrent &node) override
 visit node of type ast::ElectrodeCurrent More...
 
void visit_range (ast::Range &node) override
 visit node of type ast::Range More...
 
void visit_global (ast::Global &node) override
 visit node of type ast::Global More...
 
void visit_random_var_list (ast::RandomVarList &node) override
 visit node of type ast::RandomVarList More...
 
void visit_pointer (ast::Pointer &node) override
 visit node of type ast::Pointer More...
 
void visit_bbcore_pointer (ast::BbcorePointer &node) override
 visit node of type ast::BbcorePointer More...
 
void visit_external (ast::External &node) override
 visit node of type ast::External More...
 
void visit_thread_safe (ast::ThreadSafe &node) override
 visit node of type ast::ThreadSafe More...
 
void visit_verbatim (ast::Verbatim &node) override
 visit node of type ast::Verbatim More...
 
void visit_line_comment (ast::LineComment &node) override
 visit node of type ast::LineComment More...
 
void visit_block_comment (ast::BlockComment &node) override
 visit node of type ast::BlockComment More...
 
void visit_ontology_statement (ast::OntologyStatement &node) override
 visit node of type ast::OntologyStatement More...
 
void visit_program (ast::Program &node) override
 visit node of type ast::Program More...
 
void visit_nrn_state_block (ast::NrnStateBlock &node) override
 visit node of type ast::NrnStateBlock More...
 
void visit_eigen_newton_solver_block (ast::EigenNewtonSolverBlock &node) override
 visit node of type ast::EigenNewtonSolverBlock More...
 
void visit_eigen_linear_solver_block (ast::EigenLinearSolverBlock &node) override
 visit node of type ast::EigenLinearSolverBlock More...
 
void visit_wrapped_expression (ast::WrappedExpression &node) override
 visit node of type ast::WrappedExpression More...
 
void visit_derivimplicit_callback (ast::DerivimplicitCallback &node) override
 visit node of type ast::DerivimplicitCallback More...
 
void visit_solution_expression (ast::SolutionExpression &node) override
 visit node of type ast::SolutionExpression More...
 
void visit_update_dt (ast::UpdateDt &node) override
 visit node of type ast::UpdateDt More...
 
- Public Member Functions inherited from nmodl::visitor::Visitor
virtual ~Visitor ()=default
 

Private Member Functions

void try_replace_tagged_statement (const ast::Node &node, std::shared_ptr< ast::Expression > get_lhs(const ast::Node &node), std::shared_ptr< ast::Expression > get_rhs(const ast::Node &node))
 Try to replace a statement. More...
 

Private Attributes

StatementDispenser pre_solve_statements
 Update state variable statements (i.e. \(old_x = x \)) More...
 
StatementDispenser tmp_statements
 tmp statements that appear with –cse (i.e. \(tmp0 = a \)) More...
 
StatementDispenser solution_statements
 solutions that we want to replace More...
 
std::unordered_map< std::shared_ptr< ast::Statement >, ast::StatementVectorreplacements
 Replacements found by the visitor. More...
 
bool is_top_level_statement_block = true
 Used to notify to visit_statement_block was called by the user (or another visitor) or re-called in a nested block. More...
 
ReplacePolicy policy
 Replacement policy used by the various visitors. More...
 
size_t n_next_equations
 Number of solutions that match each old_statement with the greedy policy. More...
 
const std::unordered_set< ast::Statement * > * to_be_removed
 group of old statements that need replacing More...
 
InterleavesCounter interleaves_counter
 counts how many times the solution statements are interleaved with assignment expressions More...
 
std::pair< int, int > replaced_statements_range = {-1, -1}
 {begin index, end index} of the added statements. -1 means that it is invalid More...
 

Member Enumeration Documentation

◆ ReplacePolicy

Enumerator
VALUE 

Replace statements matching by lhs varName.

GREEDY 

Replace statements greedily.

Definition at line 214 of file sympy_replace_solutions_visitor.hpp.

Constructor & Destructor Documentation

◆ SympyReplaceSolutionsVisitor() [1/2]

nmodl::visitor::SympyReplaceSolutionsVisitor::SympyReplaceSolutionsVisitor ( )
delete

Empty ctor.

◆ SympyReplaceSolutionsVisitor() [2/2]

nmodl::visitor::SympyReplaceSolutionsVisitor::SympyReplaceSolutionsVisitor ( const std::vector< std::string > &  pre_solve_statements,
const std::vector< std::string > &  solutions,
const std::unordered_set< ast::Statement * > &  to_be_removed,
const ReplacePolicy  policy,
size_t  n_next_equations,
const std::string &  tmp_unique_prefix 
)

Default constructor.

Definition at line 34 of file sympy_replace_solutions_visitor.cpp.

Member Function Documentation

◆ replaced_statements_begin()

int nmodl::visitor::SympyReplaceSolutionsVisitor::replaced_statements_begin ( ) const
inline

idx (in the new statementVector) of the first statement that was added.

-1 if nothing was added

Definition at line 231 of file sympy_replace_solutions_visitor.hpp.

◆ replaced_statements_end()

int nmodl::visitor::SympyReplaceSolutionsVisitor::replaced_statements_end ( ) const
inline

idx (in the new statementVector) of the last statement that was added.

-1 if nothing was added

Definition at line 236 of file sympy_replace_solutions_visitor.hpp.

◆ try_replace_tagged_statement()

void nmodl::visitor::SympyReplaceSolutionsVisitor::try_replace_tagged_statement ( const ast::Node node,
std::shared_ptr< ast::Expression >   get_lhsconst ast::Node &node,
std::shared_ptr< ast::Expression >   get_rhsconst ast::Node &node 
)
private

Try to replace a statement.

Parameters
nodeit can be Diff_Eq_Expression/LinEquation/NonLinEquation
get_lhsmethod with witch we may get the lhs (in case we need it)
get_rhsmethod with witch we may get the rhs (in case we need it)

Definition at line 162 of file sympy_replace_solutions_visitor.cpp.

◆ visit_binary_expression()

void nmodl::visitor::SympyReplaceSolutionsVisitor::visit_binary_expression ( ast::BinaryExpression node)
overridevirtual

visit node of type ast::BinaryExpression

Implements nmodl::visitor::Visitor.

Definition at line 254 of file sympy_replace_solutions_visitor.cpp.

◆ visit_diff_eq_expression()

void nmodl::visitor::SympyReplaceSolutionsVisitor::visit_diff_eq_expression ( ast::DiffEqExpression node)
overridevirtual

visit node of type ast::DiffEqExpression

Implements nmodl::visitor::Visitor.

Definition at line 213 of file sympy_replace_solutions_visitor.cpp.

◆ visit_lin_equation()

void nmodl::visitor::SympyReplaceSolutionsVisitor::visit_lin_equation ( ast::LinEquation node)
overridevirtual

visit node of type ast::LinEquation

Implements nmodl::visitor::Visitor.

Definition at line 226 of file sympy_replace_solutions_visitor.cpp.

◆ visit_non_lin_equation()

void nmodl::visitor::SympyReplaceSolutionsVisitor::visit_non_lin_equation ( ast::NonLinEquation node)
overridevirtual

visit node of type ast::NonLinEquation

Implements nmodl::visitor::Visitor.

Definition at line 240 of file sympy_replace_solutions_visitor.cpp.

◆ visit_statement_block()

void nmodl::visitor::SympyReplaceSolutionsVisitor::visit_statement_block ( ast::StatementBlock node)
overridevirtual

visit node of type ast::StatementBlock

Implements nmodl::visitor::Visitor.

Definition at line 64 of file sympy_replace_solutions_visitor.cpp.

Member Data Documentation

◆ interleaves_counter

InterleavesCounter nmodl::visitor::SympyReplaceSolutionsVisitor::interleaves_counter
private

counts how many times the solution statements are interleaved with assignment expressions

Definition at line 493 of file sympy_replace_solutions_visitor.hpp.

◆ is_top_level_statement_block

bool nmodl::visitor::SympyReplaceSolutionsVisitor::is_top_level_statement_block = true
private

Used to notify to visit_statement_block was called by the user (or another visitor) or re-called in a nested block.

Definition at line 481 of file sympy_replace_solutions_visitor.hpp.

◆ n_next_equations

size_t nmodl::visitor::SympyReplaceSolutionsVisitor::n_next_equations
private

Number of solutions that match each old_statement with the greedy policy.

Definition at line 487 of file sympy_replace_solutions_visitor.hpp.

◆ policy

ReplacePolicy nmodl::visitor::SympyReplaceSolutionsVisitor::policy
private

Replacement policy used by the various visitors.

Definition at line 484 of file sympy_replace_solutions_visitor.hpp.

◆ pre_solve_statements

StatementDispenser nmodl::visitor::SympyReplaceSolutionsVisitor::pre_solve_statements
private

Update state variable statements (i.e. \(old_x = x \))

Definition at line 462 of file sympy_replace_solutions_visitor.hpp.

◆ replaced_statements_range

std::pair<int, int> nmodl::visitor::SympyReplaceSolutionsVisitor::replaced_statements_range = {-1, -1}
private

{begin index, end index} of the added statements. -1 means that it is invalid

Definition at line 496 of file sympy_replace_solutions_visitor.hpp.

◆ replacements

std::unordered_map<std::shared_ptr<ast::Statement>, ast::StatementVector> nmodl::visitor::SympyReplaceSolutionsVisitor::replacements
private

Replacements found by the visitor.

The keys are the old_statements that need replacing with the new ones (the value). Since there are pre_solve_statements and tmp_statements; it is in general a replacement of 1 : n statements

Definition at line 477 of file sympy_replace_solutions_visitor.hpp.

◆ solution_statements

StatementDispenser nmodl::visitor::SympyReplaceSolutionsVisitor::solution_statements
private

solutions that we want to replace

Definition at line 468 of file sympy_replace_solutions_visitor.hpp.

◆ tmp_statements

StatementDispenser nmodl::visitor::SympyReplaceSolutionsVisitor::tmp_statements
private

tmp statements that appear with –cse (i.e. \(tmp0 = a \))

Definition at line 465 of file sympy_replace_solutions_visitor.hpp.

◆ to_be_removed

const std::unordered_set<ast::Statement*>* nmodl::visitor::SympyReplaceSolutionsVisitor::to_be_removed
private

group of old statements that need replacing

Definition at line 490 of file sympy_replace_solutions_visitor.hpp.


The documentation for this class was generated from the following files: