Skip to content
Snippets Groups Projects

introduce command line options: `exclude_eqs` and `include_eqs`

Merged Houtan Bastani requested to merge houtanb/preprocessor:exclude_eqs into master
2 unresolved threads

Allows for the inclusion/exclusion of a set of equations, specified either on the command line or in a text file.

If the equation has a single endogenous variable on the LHS, then the equation is moved. If not, if the equation has an endogenous tag then that variable is removed along with this equation. If not, then an error is thrown.

As a command line argument, exclude_eqs can take the form (same syntax for include_eqs):

  • exclude_eqs=eq1 to remove all equations declared as [name=eq1]`
  • exclude_eqs=[eq 1, eq 2] to remove all equations declared as [name=eq 1] or [name=eq 2]
  • exclude_eqs=[tagname=X] to remove all equations declared as [tagname=X]
  • exclude_eqs=[tagname=(X, Y)] to remove all equations declared as [tagname=X] or [tagname=Y]

When declared in a file, the file should be of the form:

eq 1
eq 2

to remove all equations declared as [name=eq 1] or [name=eq 2].

It should be of the form:

tagname=
X
Y

to remove all equations declared as [tagname=X] or [tagname=Y].

Merge request reports

Checking pipeline status.

Merged by Sébastien VillemotSébastien Villemot 5 years ago (Nov 26, 2019 3:04pm UTC)

Loading

Pipeline #2449 passed

Pipeline passed for 8be9efa4 on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
1963 for (size_t i = 0; i < equations.size(); i++)
1964 if (tag_eqns.find(i) == tag_eqns.end())
1965 eqns.insert(i);
1966
1967 // remove from equations, equations_lineno, equation_tags, equation_tags_xref
1968 vector<BinaryOpNode *> new_eqns;
1969 vector<int> new_equations_lineno;
1970 map<int, int> old_eqn_num_2_new;
1971 for (size_t i = 0; i < equations.size(); i++)
1972 if (eqns.find(i) != eqns.end())
1973 {
1974 set<pair<int, int>> result;
1975 equations[i]->arg1->collectDynamicVariables(SymbolType::endogenous, result);
1976 if (result.size() == 1)
1977 excluded_vars.push_back(result.begin()->first);
1978 else
  • 1988 if (!endog_found)
    1989 {
    1990 cerr << "ERROR: Equation " << i
    1991 << " has been excluded but does not have a single variable on LHS or `endogenous` tag" << endl;
    1992 exit(EXIT_FAILURE);
    1993 }
    1994 }
    1995 }
    1996 else
    1997 {
    1998 new_eqns.emplace_back(equations[i]);
    1999 old_eqn_num_2_new[i] = new_eqns.size() - 1;
    2000 new_equations_lineno.emplace_back(equations_lineno[i]);
    2001 }
    2002 int n_excl = equations.size() - new_eqns.size();
    2003
    • I think you should check that a given variable is not excluded two times. Said otherwise, you can either check that excluded_vars is composed of distinct elements, or you can convert it to a std::set and check that it has size n_excl (but it's more difficult to give a meaningful error message in the latter case, because you can't easily determine which endogenous is repeated).

    • Please register or sign in to reply
  • Houtan Bastani added 6 commits

    added 6 commits

    Compare with previous version

  • Houtan Bastani added 1 commit

    added 1 commit

    • 0ff7a9d2 - introduce command line options: `exclude_eqs` and `include_eqs`

    Compare with previous version

  • mentioned in commit 8be9efa4

  • Please register or sign in to reply
    Loading