From ddaedb5ee34758020fb56d113213210709a5883e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 17 May 2013 14:14:15 +0200 Subject: [PATCH 01/10] Document how functions with a kink are differentiated Also add a warning in the documentation and in the preprocessor about the usage of some functions (max, min, abs, sign, comparison operators) in a stochastic context. Closes #355 --- ModFile.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ModFile.cc b/ModFile.cc index 503c9e20..a966c353 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -250,6 +250,19 @@ ModFile::checkPass() cerr << "ERROR: marking equations as [static] or [dynamic] is not possible with ramsey_policy or discretionary_policy" << endl; exit(EXIT_FAILURE); } + + if (stochastic_statement_present && + (dynamic_model.isUnaryOpUsed(oSign) + || dynamic_model.isUnaryOpUsed(oAbs) + || dynamic_model.isBinaryOpUsed(oMax) + || dynamic_model.isBinaryOpUsed(oMin) + || dynamic_model.isBinaryOpUsed(oGreater) + || dynamic_model.isBinaryOpUsed(oLess) + || dynamic_model.isBinaryOpUsed(oGreaterEqual) + || dynamic_model.isBinaryOpUsed(oLessEqual) + || dynamic_model.isBinaryOpUsed(oEqualEqual) + || dynamic_model.isBinaryOpUsed(oDifferent))) + warnings << "WARNING: you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which is unsuitable for a stochastic context; see the reference manual, section about \"Expressions\", for more details." << endl; } void From 55a548282c740a5dbe57d2831c65bb26b531e54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 17 May 2013 16:51:34 +0200 Subject: [PATCH 02/10] Possibility of restricting differentiate_forward_vars to some variables Closes #351 --- DynamicModel.cc | 18 +++++++++--------- DynamicModel.hh | 11 ++++++++--- DynareBison.yy | 3 ++- ExprNode.cc | 32 +++++++++++++++++--------------- ExprNode.hh | 16 +++++++++------- ModFile.cc | 2 +- ModFile.hh | 6 ++++++ ParsingDriver.cc | 17 ++++++++++++++++- ParsingDriver.hh | 6 ++++-- 9 files changed, 72 insertions(+), 39 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 10ca5aa2..2dfba144 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3924,29 +3924,29 @@ DynamicModel::writeLatexFile(const string &basename) const void DynamicModel::substituteEndoLeadGreaterThanTwo(bool deterministic_model) { - substituteLeadLagInternal(avEndoLead, deterministic_model); + substituteLeadLagInternal(avEndoLead, deterministic_model, vector()); } void DynamicModel::substituteEndoLagGreaterThanTwo(bool deterministic_model) { - substituteLeadLagInternal(avEndoLag, deterministic_model); + substituteLeadLagInternal(avEndoLag, deterministic_model, vector()); } void DynamicModel::substituteExoLead(bool deterministic_model) { - substituteLeadLagInternal(avExoLead, deterministic_model); + substituteLeadLagInternal(avExoLead, deterministic_model, vector()); } void DynamicModel::substituteExoLag(bool deterministic_model) { - substituteLeadLagInternal(avExoLag, deterministic_model); + substituteLeadLagInternal(avExoLag, deterministic_model, vector()); } void -DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model) +DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model, const vector &subset) { ExprNode::subst_table_t subst_table; vector neweqs; @@ -3976,7 +3976,7 @@ DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model subst = value->substituteExoLag(subst_table, neweqs); break; case avDiffForward: - subst = value->differentiateForwardVars(subst_table, neweqs); + subst = value->differentiateForwardVars(subset, subst_table, neweqs); break; default: cerr << "DynamicModel::substituteLeadLagInternal: impossible case" << endl; @@ -4004,7 +4004,7 @@ DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model subst = equations[i]->substituteExoLag(subst_table, neweqs); break; case avDiffForward: - subst = equations[i]->differentiateForwardVars(subst_table, neweqs); + subst = equations[i]->differentiateForwardVars(subset, subst_table, neweqs); break; default: cerr << "DynamicModel::substituteLeadLagInternal: impossible case" << endl; @@ -4134,9 +4134,9 @@ DynamicModel::removeTrendVariableFromEquations() } void -DynamicModel::differentiateForwardVars() +DynamicModel::differentiateForwardVars(const vector &subset) { - substituteLeadLagInternal(avDiffForward, true); + substituteLeadLagInternal(avDiffForward, true, subset); } void diff --git a/DynamicModel.hh b/DynamicModel.hh index b3ca75c9..63ac665f 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -139,8 +139,11 @@ private: void collectBlockVariables(); //! Factorized code for substitutions of leads/lags - /*! \param[in] type determines which type of variables is concerned */ - void substituteLeadLagInternal(aux_var_t type, bool deterministic_model); + /*! \param[in] type determines which type of variables is concerned + \param[in] deterministic_model whether we are in a deterministic model (only for exogenous leads/lags) + \param[in] subset variables to which to apply the transformation (only for diff of forward vars) + */ + void substituteLeadLagInternal(aux_var_t type, bool deterministic_model, const vector &subset); private: //! Indicate if the temporary terms are computed for the overall model (true) or not (false). Default value true @@ -281,7 +284,9 @@ public: void removeTrendVariableFromEquations(); //! Transforms the model by creating aux vars for the diff of forward vars - void differentiateForwardVars(); + /*! If subset is empty, does the transformation for all fwrd vars; otherwise + restrict it to the vars in subset */ + void differentiateForwardVars(const vector &subset); //! Fills eval context with values of model local variables and auxiliary variables void fillEvalContext(eval_context_t &eval_context) const; diff --git a/DynareBison.yy b/DynareBison.yy index 92d49275..7bc5698f 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -568,7 +568,8 @@ model_options : BLOCK { driver.block(); } | BYTECODE { driver.byte_code(); } | USE_DLL { driver.use_dll(); } | NO_STATIC { driver.no_static();} - | DIFFERENTIATE_FORWARD_VARS { driver.differentiate_forward_vars(); } + | DIFFERENTIATE_FORWARD_VARS { driver.differentiate_forward_vars_all(); } + | DIFFERENTIATE_FORWARD_VARS EQUAL '(' symbol_list ')' { driver.differentiate_forward_vars_some(); } | o_linear ; diff --git a/ExprNode.cc b/ExprNode.cc index 59d26fa2..930ee3e0 100644 --- a/ExprNode.cc +++ b/ExprNode.cc @@ -431,7 +431,7 @@ NumConstNode::substituteExpectation(subst_table_t &subst_table, vector &neweqs) const +NumConstNode::differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const { return const_cast(this); } @@ -1225,14 +1225,16 @@ VariableNode::substituteExpectation(subst_table_t &subst_table, vector &neweqs) const +VariableNode::differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const { expr_t value; switch (type) { case eEndogenous: assert(lag <= 1); - if (lag <= 0) + if (lag <= 0 + || (subset.size() > 0 + && find(subset.begin(), subset.end(), datatree.symbol_table.getName(symb_id)) == subset.end())) return const_cast(this); else { @@ -1255,7 +1257,7 @@ VariableNode::differentiateForwardVars(subst_table_t &subst_table, vectormaxEndoLead() <= 0) return const_cast(this); else - return value->differentiateForwardVars(subst_table, neweqs); + return value->differentiateForwardVars(subset, subst_table, neweqs); default: return const_cast(this); } @@ -2339,9 +2341,9 @@ UnaryOpNode::substituteExpectation(subst_table_t &subst_table, vector &neweqs) const +UnaryOpNode::differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const { - expr_t argsubst = arg->differentiateForwardVars(subst_table, neweqs); + expr_t argsubst = arg->differentiateForwardVars(subset, subst_table, neweqs); return buildSimilarUnaryOpNode(argsubst, datatree); } @@ -3583,10 +3585,10 @@ BinaryOpNode::substituteExpectation(subst_table_t &subst_table, vector &neweqs) const +BinaryOpNode::differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const { - expr_t arg1subst = arg1->differentiateForwardVars(subst_table, neweqs); - expr_t arg2subst = arg2->differentiateForwardVars(subst_table, neweqs); + expr_t arg1subst = arg1->differentiateForwardVars(subset, subst_table, neweqs); + expr_t arg2subst = arg2->differentiateForwardVars(subset, subst_table, neweqs); return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree); } @@ -4200,11 +4202,11 @@ TrinaryOpNode::substituteExpectation(subst_table_t &subst_table, vector &neweqs) const +TrinaryOpNode::differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const { - expr_t arg1subst = arg1->differentiateForwardVars(subst_table, neweqs); - expr_t arg2subst = arg2->differentiateForwardVars(subst_table, neweqs); - expr_t arg3subst = arg3->differentiateForwardVars(subst_table, neweqs); + expr_t arg1subst = arg1->differentiateForwardVars(subset, subst_table, neweqs); + expr_t arg2subst = arg2->differentiateForwardVars(subset, subst_table, neweqs); + expr_t arg3subst = arg3->differentiateForwardVars(subset, subst_table, neweqs); return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree); } @@ -4765,11 +4767,11 @@ ExternalFunctionNode::substituteExpectation(subst_table_t &subst_table, vector &neweqs) const +ExternalFunctionNode::differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const { vector arguments_subst; for (vector::const_iterator it = arguments.begin(); it != arguments.end(); it++) - arguments_subst.push_back((*it)->differentiateForwardVars(subst_table, neweqs)); + arguments_subst.push_back((*it)->differentiateForwardVars(subset, subst_table, neweqs)); return buildSimilarExternalFunctionNode(arguments_subst, datatree); } diff --git a/ExprNode.hh b/ExprNode.hh index 7ba4ccc2..917643f1 100644 --- a/ExprNode.hh +++ b/ExprNode.hh @@ -361,11 +361,13 @@ public: //! Constructs a new expression where forward variables (supposed to be at most in t+1) have been replaced by themselves at t, plus a new aux var representing their (time) differentiate /*! + \param[in] subset variables to which to limit the transformation; transform + all fwrd vars if empty \param[in,out] subst_table Map used to store mapping between a given forward variable and the aux var that contains its differentiate \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. */ - virtual expr_t differentiateForwardVars(subst_table_t &subst_table, vector &neweqs) const = 0; + virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const = 0; //! Return true if the nodeID is a numerical constant equal to value and false otherwise /*! @@ -452,7 +454,7 @@ public: virtual expr_t substituteExoLag(subst_table_t &subst_table, vector &neweqs) const; virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; - virtual expr_t differentiateForwardVars(subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; virtual bool isNumConstNodeEqualTo(double value) const; virtual bool containsEndogenous(void) const; virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const; @@ -514,7 +516,7 @@ public: virtual expr_t substituteExoLag(subst_table_t &subst_table, vector &neweqs) const; virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; - virtual expr_t differentiateForwardVars(subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; virtual bool isNumConstNodeEqualTo(double value) const; virtual bool containsEndogenous(void) const; virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const; @@ -591,7 +593,7 @@ public: virtual expr_t substituteExoLag(subst_table_t &subst_table, vector &neweqs) const; virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; - virtual expr_t differentiateForwardVars(subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; virtual bool isNumConstNodeEqualTo(double value) const; virtual bool containsEndogenous(void) const; virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const; @@ -681,7 +683,7 @@ public: virtual expr_t substituteExoLag(subst_table_t &subst_table, vector &neweqs) const; virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; - virtual expr_t differentiateForwardVars(subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; virtual bool isNumConstNodeEqualTo(double value) const; virtual bool containsEndogenous(void) const; virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const; @@ -751,7 +753,7 @@ public: virtual expr_t substituteExoLag(subst_table_t &subst_table, vector &neweqs) const; virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; - virtual expr_t differentiateForwardVars(subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; virtual bool isNumConstNodeEqualTo(double value) const; virtual bool containsEndogenous(void) const; virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const; @@ -825,7 +827,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; - virtual expr_t differentiateForwardVars(subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; virtual bool isNumConstNodeEqualTo(double value) const; virtual bool containsEndogenous(void) const; virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const; diff --git a/ModFile.cc b/ModFile.cc index a966c353..86296273 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -322,7 +322,7 @@ ModFile::transformPass() } if (differentiate_forward_vars) - dynamic_model.differentiateForwardVars(); + dynamic_model.differentiateForwardVars(differentiate_forward_vars_subset); if (mod_file_struct.dsge_var_estimated || !mod_file_struct.dsge_var_calibrated.empty()) try diff --git a/ModFile.hh b/ModFile.hh index ceba97b1..d2784d1a 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -78,6 +78,12 @@ public: //! Is the 'differentiate_forward_vars' option used? bool differentiate_forward_vars; + /*! If the 'differentiate_forward_vars' option is used, contains the set of + endogenous with respect to which to do the transformation; + if empty, means that the transformation must be applied to all endos + with a lead */ + vector differentiate_forward_vars_subset; + //! Are nonstationary variables present ? bool nonstationary_variables; diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 2d8d4fa9..9747b640 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -494,11 +494,26 @@ ParsingDriver::byte_code() } void -ParsingDriver::differentiate_forward_vars() +ParsingDriver::differentiate_forward_vars_all() { mod_file->differentiate_forward_vars = true; } +void +ParsingDriver::differentiate_forward_vars_some() +{ + mod_file->differentiate_forward_vars = true; + mod_file->differentiate_forward_vars_subset = symbol_list.get_symbols(); + for (vector::const_iterator it = mod_file->differentiate_forward_vars_subset.begin(); + it != mod_file->differentiate_forward_vars_subset.end(); ++it) + { + check_symbol_existence(*it); + if (mod_file->symbol_table.getType(*it) != eEndogenous) + error("Symbol " + *it + " is not an endogenous"); + } + symbol_list.clear(); +} + void ParsingDriver::cutoff(string *value) { diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 7da190a2..6d3fda9f 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -245,8 +245,10 @@ public: void byte_code(); //! the static model is not computed void no_static(); - //! the differentiate_forward_vars option is enabled - void differentiate_forward_vars(); + //! the differentiate_forward_vars option is enabled (for all vars) + void differentiate_forward_vars_all(); + //! the differentiate_forward_vars option is enabled (for a subset of vars) + void differentiate_forward_vars_some(); //! cutoff option of model block void cutoff(string *value); //! mfs option of model block From 6d7242b6e8caccc4b74c3c881b75d92bcdd9de8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 24 May 2013 12:13:32 +0200 Subject: [PATCH 03/10] Add mode_check_{neighbourhood_size,symmetric_plots} in preprocessor and manual Closes #320 --- DynareBison.yy | 6 +++++- DynareFlex.ll | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 7bc5698f..0f28e3c4 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -112,7 +112,7 @@ class ParsingDriver; %token LABELS LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LYAPUNOV %token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT %token MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN MINIMAL_SOLVING_PERIODS SOLVE_MAXIT -%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN +%token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN %token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS %token NAME %token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS @@ -1513,6 +1513,8 @@ estimation_options : o_datafile | o_mode_file | o_mode_compute | o_mode_check + | o_mode_check_neighbourhood_size + | o_mode_check_symmetric_plots | o_prior_trunc | o_mh_mode | o_mh_nblocks @@ -2336,6 +2338,8 @@ o_mode_file : MODE_FILE EQUAL filename { driver.option_str("mode_file", $3); }; o_mode_compute : MODE_COMPUTE EQUAL INT_NUMBER { driver.option_num("mode_compute", $3); }; | MODE_COMPUTE EQUAL symbol { driver.option_str("mode_compute", $3); }; o_mode_check : MODE_CHECK { driver.option_num("mode_check", "1"); }; +o_mode_check_neighbourhood_size : MODE_CHECK_NEIGHBOURHOOD_SIZE EQUAL signed_number_w_inf { driver.option_num("mode_check_neighbourhood_size", $3); }; +o_mode_check_symmetric_plots : MODE_CHECK_SYMMETRIC_PLOTS EQUAL INT_NUMBER { driver.option_num("mode_check_symmetric_plots", $3); }; o_prior_trunc : PRIOR_TRUNC EQUAL non_negative_number { driver.option_num("prior_trunc", $3); }; o_mh_mode : MH_MODE EQUAL INT_NUMBER { driver.option_num("mh_mode", $3); }; o_mh_nblocks : MH_NBLOCKS EQUAL INT_NUMBER { driver.option_num("mh_nblck", $3); }; diff --git a/DynareFlex.ll b/DynareFlex.ll index 8a8f1f4a..f7da0149 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -239,6 +239,8 @@ string eofbuff; mode_file {return token::MODE_FILE;} mode_compute {return token::MODE_COMPUTE;} mode_check {return token::MODE_CHECK;} +mode_check_neighbourhood_size {return token::MODE_CHECK_NEIGHBOURHOOD_SIZE;} +mode_check_symmetric_plots {return token::MODE_CHECK_SYMMETRIC_PLOTS;} prior_trunc {return token::PRIOR_TRUNC;} mh_mode {return token::MH_MODE;} mh_nblocks {return token::MH_NBLOCKS;} From e8353673feaa22de51630ebcd8cbae03b550902d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 27 May 2013 17:07:15 +0200 Subject: [PATCH 04/10] Add interface and doc to use_univariate_filters_if_singularity_is_detected option Closes #414 --- DynareBison.yy | 4 +++- DynareFlex.ll | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 0f28e3c4..98274dc7 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -128,7 +128,7 @@ class ParsingDriver; %token STDERR STEADY STOCH_SIMUL SURPRISE SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME %token TEX RAMSEY_POLICY PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL %token TEX_NAME -%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE +%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED %token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES %token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL %token XLS_SHEET XLS_RANGE @@ -1563,6 +1563,7 @@ estimation_options : o_datafile | o_analytic_derivation | o_ar | o_endogenous_prior + | o_use_univariate_filters_if_singularity_is_detected ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -2656,6 +2657,7 @@ o_data_obs_nbr : DATA_OBS_NBR EQUAL INT_NUMBER { driver.option_num("ms.forecast_ o_discretionary_tol: DISCRETIONARY_TOL EQUAL non_negative_number { driver.option_num("discretionary_tol",$3); }; o_analytic_derivation : ANALYTIC_DERIVATION { driver.option_num("analytic_derivation", "1"); } o_endogenous_prior : ENDOGENOUS_PRIOR { driver.option_num("endogenous_prior", "1"); } +o_use_univariate_filters_if_singularity_is_detected : USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED EQUAL INT_NUMBER { driver.option_num("use_univariate_filters_if_singularity_is_detected", $3); } range : symbol ':' symbol { diff --git a/DynareFlex.ll b/DynareFlex.ll index f7da0149..4ac323d8 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -309,6 +309,7 @@ string eofbuff; square_root_solver {return token::SQUARE_ROOT_SOLVER;} cycle_reduction {return token::CYCLE_REDUCTION;} logarithmic_reduction {return token::LOGARITHMIC_REDUCTION;} +use_univariate_filters_if_singularity_is_detected {return token::USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED;} default {return token::DEFAULT;} alpha { yylval->string_val = new string(yytext); From 0474406e3b3030695364069cbba9c4d53b40bb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 27 May 2013 17:31:41 +0200 Subject: [PATCH 05/10] Revert "Reset oo_.{exo_}steady_state to zero before endval" This reverts commit cf146ec4e50b83bb17f6890b936d8d89e7ef6664. --- NumericalInitialization.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 3b74bf32..1c26d74f 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 Dynare Team + * Copyright (C) 2003-2012 Dynare Team * * This file is part of Dynare. * @@ -245,9 +245,7 @@ EndValStatement::writeOutput(ostream &output, const string &basename) const << "%" << endl; // Writing endval block to set terminal values for variables output << "ys0_= oo_.steady_state;" << endl - << "ex0_ = oo_.exo_steady_state;" << endl - << "oo_.steady_state = zeros(size(ys0_));" << endl - << "oo_.exo_steady_state = zeros(size(ex0_));" << endl; + << "ex0_ = oo_.exo_steady_state;" << endl; writeInitValues(output); } From feb6147467d51432ce1a21434c0574484b154d9f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 30 May 2013 15:21:08 +0200 Subject: [PATCH 06/10] preprocessor: config file: remove redundant check --- ConfigFile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConfigFile.cc b/ConfigFile.cc index 2d0e3499..c0c17857 100644 --- a/ConfigFile.cc +++ b/ConfigFile.cc @@ -517,7 +517,7 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const exit(EXIT_FAILURE); } #if defined(_WIN32) || defined(__CYGWIN32__) - if (it->second->userName.empty() || it->second->password.empty()) + if (it->second->password.empty()) { cerr << "ERROR (node " << it->first << "): the Password option must be passed under Windows for every remote node." << endl; exit(EXIT_FAILURE); From 55de45a0bb72efe372adb580434d12bf06012078 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 30 May 2013 15:29:27 +0200 Subject: [PATCH 07/10] preprocessor: config file: if on Windows machine and operatingSystem is empty, then check to see if password or remoteDrive is empty. otherwise, don't check --- ConfigFile.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ConfigFile.cc b/ConfigFile.cc index c0c17857..61ebf2e4 100644 --- a/ConfigFile.cc +++ b/ConfigFile.cc @@ -517,15 +517,18 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const exit(EXIT_FAILURE); } #if defined(_WIN32) || defined(__CYGWIN32__) - if (it->second->password.empty()) + if (it->second->operatingSystem.empty()) { - cerr << "ERROR (node " << it->first << "): the Password option must be passed under Windows for every remote node." << endl; - exit(EXIT_FAILURE); - } - if (it->second->remoteDrive.empty()) - { - cerr << "ERROR (node " << it->first << "): the RemoteDrive option must be passed under Windows for every remote node." << endl; - exit(EXIT_FAILURE); + if (it->second->password.empty()) + { + cerr << "ERROR (node " << it->first << "): the Password option must be passed under Windows for every remote node." << endl; + exit(EXIT_FAILURE); + } + if (it->second->remoteDrive.empty()) + { + cerr << "ERROR (node " << it->first << "): the RemoteDrive option must be passed under Windows for every remote node." << endl; + exit(EXIT_FAILURE); + } } #endif if (it->second->remoteDirectory.empty()) From c10a371bb55896269fc3f56835a4f40c22661c79 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 30 May 2013 15:30:38 +0200 Subject: [PATCH 08/10] preprocessor: config file: if creating windows node from unix machine, check to see if the password or remoteDrive are empty --- ConfigFile.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ConfigFile.cc b/ConfigFile.cc index 61ebf2e4..72260b34 100644 --- a/ConfigFile.cc +++ b/ConfigFile.cc @@ -516,6 +516,19 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const cerr << "ERROR (node " << it->first << "): the UserName option must be passed for every remote node." << endl; exit(EXIT_FAILURE); } + if (it->second->operatingSystem.compare("windows") == 0) + { + if (it->second->password.empty()) + { + cerr << "ERROR (node " << it->first << "): the Password option must be passed under Windows for every remote node." << endl; + exit(EXIT_FAILURE); + } + if (it->second->remoteDrive.empty()) + { + cerr << "ERROR (node " << it->first << "): the RemoteDrive option must be passed under Windows for every remote node." << endl; + exit(EXIT_FAILURE); + } + } #if defined(_WIN32) || defined(__CYGWIN32__) if (it->second->operatingSystem.empty()) { From a595a83b16d1c58ad649584f2d5488fef02dbcaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 31 May 2013 14:47:28 +0200 Subject: [PATCH 09/10] Add new option parallel_local_files to model block Ref #389 --- DynareBison.yy | 9 ++++++++- DynareFlex.ll | 1 + ModFile.cc | 15 +++++++++++++++ ModFile.hh | 4 ++++ ParsingDriver.cc | 8 ++++++++ ParsingDriver.hh | 4 +++- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/DynareBison.yy b/DynareBison.yy index 98274dc7..9a3bca1b 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -118,7 +118,7 @@ class ParsingDriver; %token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS %token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF %token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED -%token PARAMETERS PARAMETER_SET PARTIAL_INFORMATION PERFECT_FORESIGHT PERIODS PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE +%token PARALLEL_LOCAL_FILES PARAMETERS PARAMETER_SET PARTIAL_INFORMATION PERFECT_FORESIGHT PERIODS PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE %token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN PRUNING %token QUOTED_STRING %token QZ_CRITERIUM FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE @@ -571,6 +571,7 @@ model_options : BLOCK { driver.block(); } | DIFFERENTIATE_FORWARD_VARS { driver.differentiate_forward_vars_all(); } | DIFFERENTIATE_FORWARD_VARS EQUAL '(' symbol_list ')' { driver.differentiate_forward_vars_some(); } | o_linear + | PARALLEL_LOCAL_FILES EQUAL '(' parallel_local_filename_list ')' ; model_options_list : model_options_list COMMA model_options @@ -1678,6 +1679,12 @@ filename : symbol | QUOTED_STRING ; +parallel_local_filename_list : filename + { driver.add_parallel_local_file($1); } + | parallel_local_filename_list COMMA filename + { driver.add_parallel_local_file($3); } + ; + mc_filename_list : filename { driver.add_mc_filename($1); } | filename '(' non_negative_number ')' diff --git a/DynareFlex.ll b/DynareFlex.ll index 4ac323d8..626d4b13 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -570,6 +570,7 @@ string eofbuff; all_values_required {return token::ALL_VALUES_REQUIRED;} no_static {return token::NO_STATIC;} differentiate_forward_vars {return token::DIFFERENTIATE_FORWARD_VARS;} +parallel_local_files {return token::PARALLEL_LOCAL_FILES;} linear {return token::LINEAR;} diff --git a/ModFile.cc b/ModFile.cc index 86296273..d8a6e2c1 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -531,6 +531,21 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b << "options_.bytecode=" << byte_code << ";" << endl << "options_.use_dll=" << use_dll << ";" << endl; + if (parallel_local_files.size() > 0) + { + mOutputFile << "options_.parallel_info.local_files = {" << endl; + for (size_t i = 0; i < parallel_local_files.size(); i++) + { + size_t j = parallel_local_files[i].find_last_of("/\\"); + if (j == string::npos) + mOutputFile << "'', '" << parallel_local_files[i] << "';" << endl; + else + mOutputFile << "'" << parallel_local_files[i].substr(0, j+1) << "', '" + << parallel_local_files[i].substr(j+1, string::npos) << "';" << endl; + } + mOutputFile << "};" << endl; + } + config_file.writeCluster(mOutputFile); if (byte_code) diff --git a/ModFile.hh b/ModFile.hh index d2784d1a..aa7ccc61 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -94,6 +94,10 @@ public: //! Stores the original number of equations in the model_block int ramsey_policy_orig_eqn_nbr; + //! Stores the list of extra files to be transefered during a parallel run + /*! (i.e. option parallel_local_files of model block) */ + vector parallel_local_files; + private: //! List of statements vector statements; diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 9747b640..a5f34563 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -2541,3 +2541,11 @@ ParsingDriver::model_diagnostics() { mod_file->addStatement(new ModelDiagnosticsStatement()); } + +void +ParsingDriver::add_parallel_local_file(string *filename) +{ + mod_file->parallel_local_files.push_back(*filename); + delete filename; +} + diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 6d3fda9f..1ab71514 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -117,7 +117,7 @@ private: OptionsList options_list; //! Temporary storage for trend elements ObservationTrendsStatement::trend_elements_t trend_elements; - //! Temporary storage for filename list of ModelComparison + //! Temporary storage for filename list of ModelComparison (contains weights) ModelComparisonStatement::filename_list_t filename_list; //! Temporary storage for list of EstimationParams (from estimated_params* statements) vector estim_params_list; @@ -648,6 +648,8 @@ public: void process_graph_format_option(); //! Model diagnostics void model_diagnostics(); + //! Processing the parallel_local_files option + void add_parallel_local_file(string *filename); }; #endif // ! PARSING_DRIVER_HH From e84ad24f6e4405e11def8d9e2544a838d1f8a026 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 31 May 2013 18:19:12 +0200 Subject: [PATCH 10/10] preprocessor: pretty print error info --- ParsingDriver.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ParsingDriver.cc b/ParsingDriver.cc index a5f34563..39c24023 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -105,7 +105,16 @@ ParsingDriver::parse(istream &in, bool debug) void ParsingDriver::error(const Dynare::parser::location_type &l, const string &m) { - cerr << "ERROR: " << l << ": " << m << endl; + cerr << "ERROR: " << *l.begin.filename << ": line " << l.begin.line; + if (l.begin.line == l.end.line) + if (l.begin.column == l.end.column - 1) + cerr << ", col " << l.begin.column; + else + cerr << ", cols " << l.begin.column << "-" << l.end.column - 1; + else + cerr << ", col " << l.begin.column << " -" + << " line " << l.end.line << ", col " << l.end.column - 1; + cerr << ": " << m << endl; exit(EXIT_FAILURE); }