From c2d47fb48ea6c054365e9151be09402b43581699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Mon, 19 Apr 2021 14:51:34 +0200 Subject: [PATCH] Julia: remove driver file The Julia code now uses the JSON output for retrieving the information that previously was in the driver file. --- src/DynamicModel.cc | 338 +++++++++++++++------------------ src/DynamicModel.hh | 4 +- src/EquationTags.cc | 40 ++-- src/EquationTags.hh | 6 +- src/ModFile.cc | 110 +---------- src/NumericalInitialization.cc | 11 +- src/NumericalInitialization.hh | 3 +- src/Statement.cc | 7 +- src/Statement.hh | 1 - src/SymbolTable.cc | 134 +------------ src/SymbolTable.hh | 4 +- 11 files changed, 172 insertions(+), 486 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 6cdc371c..0cc56b30 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -2527,67 +2527,67 @@ DynamicModel::includeExcludeEquations(const string &eqs, bool exclude_eqs) } void -DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, const string &modstruct, +DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, const vector<int> &state_var, bool estimation_present) const { for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++) { int block_size = blocks[blk].size; - output << modstruct << "block_structure.block(" << blk+1 << ").Simulation_Type = " << static_cast<int>(blocks[blk].simulation_type) << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").maximum_lag = " << blocks[blk].max_lag << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").maximum_lead = " << blocks[blk].max_lead << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").maximum_endo_lag = " << blocks[blk].max_endo_lag << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").maximum_endo_lead = " << blocks[blk].max_endo_lead << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").maximum_exo_lag = " << blocks[blk].max_exo_lag << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").maximum_exo_lead = " << blocks[blk].max_exo_lead << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").maximum_exo_det_lag = " << blocks[blk].max_exo_det_lag << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").maximum_exo_det_lead = " << blocks[blk].max_exo_det_lead << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").endo_nbr = " << block_size << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").mfs = " << blocks[blk].mfs_size << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").equation = ["; + output << "M_.block_structure.block(" << blk+1 << ").Simulation_Type = " << static_cast<int>(blocks[blk].simulation_type) << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").maximum_lag = " << blocks[blk].max_lag << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").maximum_lead = " << blocks[blk].max_lead << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").maximum_endo_lag = " << blocks[blk].max_endo_lag << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").maximum_endo_lead = " << blocks[blk].max_endo_lead << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").maximum_exo_lag = " << blocks[blk].max_exo_lag << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").maximum_exo_lead = " << blocks[blk].max_exo_lead << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").maximum_exo_det_lag = " << blocks[blk].max_exo_det_lag << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").maximum_exo_det_lead = " << blocks[blk].max_exo_det_lead << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").endo_nbr = " << block_size << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").mfs = " << blocks[blk].mfs_size << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").equation = ["; for (int eq = 0; eq < block_size; eq++) output << " " << getBlockEquationID(blk, eq)+1; output << "];" << endl - << modstruct << "block_structure.block(" << blk+1 << ").variable = ["; + << "M_.block_structure.block(" << blk+1 << ").variable = ["; for (int var = 0; var < block_size; var++) output << " " << getBlockVariableID(blk, var)+1; output << "];" << endl - << modstruct << "block_structure.block(" << blk+1 << ").exogenous = ["; + << "M_.block_structure.block(" << blk+1 << ").exogenous = ["; for (int exo : blocks_exo[blk]) output << " " << exo+1; output << "];" << endl - << modstruct << "block_structure.block(" << blk+1 << ").exo_nbr = " << blocks_exo[blk].size() << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").exogenous_det = ["; + << "M_.block_structure.block(" << blk+1 << ").exo_nbr = " << blocks_exo[blk].size() << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").exogenous_det = ["; for (int exo_det : blocks_exo_det[blk]) output << " " << exo_det+1; output << "];" << endl - << modstruct << "block_structure.block(" << blk+1 << ").exo_det_nbr = " << blocks_exo_det[blk].size() << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").other_endogenous = ["; + << "M_.block_structure.block(" << blk+1 << ").exo_det_nbr = " << blocks_exo_det[blk].size() << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").other_endogenous = ["; for (int other_endo : blocks_other_endo[blk]) output << " " << other_endo+1; output << "];" << endl - << modstruct << "block_structure.block(" << blk+1 << ").other_endogenous_block = ["; + << "M_.block_structure.block(" << blk+1 << ").other_endogenous_block = ["; for (int other_endo : blocks_other_endo[blk]) output << " " << endo2block[other_endo]+1; output << "];" << endl; - output << modstruct << "block_structure.block(" << blk+1 << ").tm1 = zeros(" << blocks_other_endo[blk].size() << ", " << state_var.size() << ");" << endl; + output << "M_.block_structure.block(" << blk+1 << ").tm1 = zeros(" << blocks_other_endo[blk].size() << ", " << state_var.size() << ");" << endl; int line = 1; for (auto other_endo : blocks_other_endo[blk]) { if (auto it = find(state_var.begin(), state_var.end(), other_endo); it != state_var.end()) - output << modstruct << "block_structure.block(" << blk+1 << ").tm1(" + output << "M_.block_structure.block(" << blk+1 << ").tm1(" << line << ", " << distance(state_var.begin(), it)+1 << ") = 1;" << endl; line++; } - output << modstruct << "block_structure.block(" << blk+1 << ").other_endo_nbr = " << blocks_other_endo[blk].size() << ";" << endl; + output << "M_.block_structure.block(" << blk+1 << ").other_endo_nbr = " << blocks_other_endo[blk].size() << ";" << endl; int count_lead_lag_incidence = 0; vector<int> local_state_var; - output << modstruct << "block_structure.block(" << blk+1 << ").lead_lag_incidence = [" << endl; + output << "M_.block_structure.block(" << blk+1 << ").lead_lag_incidence = [" << endl; for (int lag = -1; lag <= 1; lag++) { for (int var = 0; var < block_size; var++) @@ -2609,13 +2609,13 @@ DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, co } output << "];" << endl; - output << modstruct << "block_structure.block(" << blk+1 << ").sorted_col_dr_ghx = ["; + output << "M_.block_structure.block(" << blk+1 << ").sorted_col_dr_ghx = ["; for (int lsv : local_state_var) output << distance(state_var.begin(), find(state_var.begin(), state_var.end(), lsv))+1 << " "; output << "];" << endl; count_lead_lag_incidence = 0; - output << modstruct << "block_structure.block(" << blk+1 << ").lead_lag_incidence_other = [" << endl; + output << "M_.block_structure.block(" << blk+1 << ").lead_lag_incidence_other = [" << endl; for (int lag = -1; lag <= 1; lag++) { for (int other_endo : blocks_other_endo[blk]) @@ -2635,19 +2635,19 @@ DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, co } output << "];" << endl; - output << modstruct << "block_structure.block(" << blk+1 << ").n_static = " << blocks[blk].n_static << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").n_forward = " << blocks[blk].n_forward << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").n_backward = " << blocks[blk].n_backward << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").n_mixed = " << blocks[blk].n_mixed << ";" << endl - << modstruct << "block_structure.block(" << blk+1 << ").is_linear = " << (blocks[blk].linear ? "true" : "false" ) << ';' << endl - << modstruct << "block_structure.block(" << blk+1 << ").NNZDerivatives = " << blocks_derivatives[blk].size() << ';' << endl; + output << "M_.block_structure.block(" << blk+1 << ").n_static = " << blocks[blk].n_static << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").n_forward = " << blocks[blk].n_forward << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").n_backward = " << blocks[blk].n_backward << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").n_mixed = " << blocks[blk].n_mixed << ";" << endl + << "M_.block_structure.block(" << blk+1 << ").is_linear = " << (blocks[blk].linear ? "true" : "false" ) << ';' << endl + << "M_.block_structure.block(" << blk+1 << ").NNZDerivatives = " << blocks_derivatives[blk].size() << ';' << endl; } - output << modstruct << "block_structure.variable_reordered = ["; + output << "M_.block_structure.variable_reordered = ["; for (int i = 0; i < symbol_table.endo_nbr(); i++) output << " " << endo_idx_block2orig[i]+1; output << "];" << endl - << modstruct << "block_structure.equation_reordered = ["; + << "M_.block_structure.equation_reordered = ["; for (int i = 0; i < symbol_table.endo_nbr(); i++) output << " " << eq_idx_block2orig[i]+1; output << "];" << endl; @@ -2664,13 +2664,13 @@ DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, co } for (auto [lag, eq_var_set] : lag_row_incidence) { - output << modstruct << "block_structure.incidence(" << max_endo_lag+lag+1 << ").lead_lag = " << lag << ";" << endl - << modstruct << "block_structure.incidence(" << max_endo_lag+lag+1 << ").sparse_IM = [" << endl; + output << "M_.block_structure.incidence(" << max_endo_lag+lag+1 << ").lead_lag = " << lag << ";" << endl + << "M_.block_structure.incidence(" << max_endo_lag+lag+1 << ").sparse_IM = [" << endl; for (auto [eq, var] : eq_var_set) output << " " << eq+1 << " " << var+1 << ";" << endl; output << "];" << endl; } - output << modstruct << "block_structure.dyn_tmp_nbr = " << blocks_temporary_terms_idxs.size() << ';' << endl; + output << "M_.block_structure.dyn_tmp_nbr = " << blocks_temporary_terms_idxs.size() << ';' << endl; if (estimation_present) { @@ -2685,7 +2685,7 @@ DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, co n_obs--; int n = n_obs + n_state; - output << modstruct << "nobs_non_statevar = " << n_obs << ";" << endl; + output << "M_.nobs_non_statevar = " << n_obs << ";" << endl; int nb_diag = 0; vector<int> i_nz_state_var(n); @@ -2754,11 +2754,11 @@ DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, co i_nz_state_var[lp + i] = lp + nze; lp += nze; } - output << modstruct << "nz_state_var = ["; + output << "M_.nz_state_var = ["; for (int i = 0; i < lp; i++) output << i_nz_state_var[i] << " "; output << "];" << endl - << modstruct << "n_diag = " << nb_diag << ";" << endl; + << "M_.n_diag = " << nb_diag << ";" << endl; KF_index_file.write(reinterpret_cast<char *>(&nb_diag), sizeof(nb_diag)); using index_KF = pair<int, pair<int, int >>; @@ -2798,7 +2798,7 @@ DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, co } void -DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool block_decomposition, bool use_dll, bool estimation_present, bool compute_xrefs, bool julia) const +DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool block_decomposition, bool use_dll, bool estimation_present, bool compute_xrefs) const { /* Writing initialisation for M_.lead_lag_incidence matrix M_.lead_lag_incidence is a matrix with as many columns as there are @@ -2809,28 +2809,16 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl model at a given period. */ - string modstruct, outstruct; - if (julia) - { - modstruct = "model_."; - outstruct = "oo_."; - } - else - { - modstruct = "M_."; - outstruct = "oo_."; - } - - output << modstruct << "orig_maximum_endo_lag = " << max_endo_lag_orig << ";" << endl - << modstruct << "orig_maximum_endo_lead = " << max_endo_lead_orig << ";" << endl - << modstruct << "orig_maximum_exo_lag = " << max_exo_lag_orig << ";" << endl - << modstruct << "orig_maximum_exo_lead = " << max_exo_lead_orig << ";" << endl - << modstruct << "orig_maximum_exo_det_lag = " << max_exo_det_lag_orig << ";" << endl - << modstruct << "orig_maximum_exo_det_lead = " << max_exo_det_lead_orig << ";" << endl - << modstruct << "orig_maximum_lag = " << max_lag_orig << ";" << endl - << modstruct << "orig_maximum_lead = " << max_lead_orig << ";" << endl - << modstruct << "orig_maximum_lag_with_diffs_expanded = " << max_lag_with_diffs_expanded_orig << ";" << endl - << modstruct << "lead_lag_incidence = ["; + output << "M_.orig_maximum_endo_lag = " << max_endo_lag_orig << ";" << endl + << "M_.orig_maximum_endo_lead = " << max_endo_lead_orig << ";" << endl + << "M_.orig_maximum_exo_lag = " << max_exo_lag_orig << ";" << endl + << "M_.orig_maximum_exo_lead = " << max_exo_lead_orig << ";" << endl + << "M_.orig_maximum_exo_det_lag = " << max_exo_det_lag_orig << ";" << endl + << "M_.orig_maximum_exo_det_lead = " << max_exo_det_lead_orig << ";" << endl + << "M_.orig_maximum_lag = " << max_lag_orig << ";" << endl + << "M_.orig_maximum_lead = " << max_lead_orig << ";" << endl + << "M_.orig_maximum_lag_with_diffs_expanded = " << max_lag_with_diffs_expanded_orig << ";" << endl + << "M_.lead_lag_incidence = ["; // Loop on endogenous variables int nstatic = 0, nfwrd = 0, @@ -2882,63 +2870,45 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl output << ";"; } output << "]';" << endl; - output << modstruct << "nstatic = " << nstatic << ";" << endl - << modstruct << "nfwrd = " << nfwrd << ";" << endl - << modstruct << "npred = " << npred << ";" << endl - << modstruct << "nboth = " << nboth << ";" << endl - << modstruct << "nsfwrd = " << nfwrd+nboth << ";" << endl - << modstruct << "nspred = " << npred+nboth << ";" << endl - << modstruct << "ndynamic = " << npred+nboth+nfwrd << ";" << endl; - if (!julia) - { - output << modstruct << "dynamic_tmp_nbr = ["; - for (size_t i = 0; i < temporary_terms_derivatives.size(); i++) - output << temporary_terms_derivatives[i].size() + (i == 0 ? temporary_terms_mlv.size() : 0) << "; "; - output << "];" << endl; + output << "M_.nstatic = " << nstatic << ";" << endl + << "M_.nfwrd = " << nfwrd << ";" << endl + << "M_.npred = " << npred << ";" << endl + << "M_.nboth = " << nboth << ";" << endl + << "M_.nsfwrd = " << nfwrd+nboth << ";" << endl + << "M_.nspred = " << npred+nboth << ";" << endl + << "M_.ndynamic = " << npred+nboth+nfwrd << ";" << endl; + + output << "M_.dynamic_tmp_nbr = ["; + for (size_t i = 0; i < temporary_terms_derivatives.size(); i++) + output << temporary_terms_derivatives[i].size() + (i == 0 ? temporary_terms_mlv.size() : 0) << "; "; + output << "];" << endl; - /* Write mapping between model local variables and indices in the temporary - terms vector (dynare#1722) */ - output << modstruct << "model_local_variables_dynamic_tt_idxs = {" << endl; - for (auto [mlv, value] : temporary_terms_mlv) - output << " '" << symbol_table.getName(mlv->symb_id) << "', " - << temporary_terms_idxs.at(mlv)+1 << ';' << endl; - output << "};" << endl; - } + /* Write mapping between model local variables and indices in the temporary + terms vector (dynare#1722) */ + output << "M_.model_local_variables_dynamic_tt_idxs = {" << endl; + for (auto [mlv, value] : temporary_terms_mlv) + output << " '" << symbol_table.getName(mlv->symb_id) << "', " + << temporary_terms_idxs.at(mlv)+1 << ';' << endl; + output << "};" << endl; // Write equation tags - equation_tags.writeOutput(output, modstruct, julia); + equation_tags.writeOutput(output); // Write Occbin tags - equation_tags.writeOccbinOutput(output, modstruct, julia); + equation_tags.writeOccbinOutput(output); // Write mapping for variables and equations they are present in - if (!julia) - for (const auto &variable : variableMapping) - { - output << modstruct << "mapping." << symbol_table.getName(variable.first) << ".eqidx = ["; - for (auto equation : variable.second) - output << equation + 1 << " "; - output << "];" << endl; - } - else + for (const auto &variable : variableMapping) { - output << modstruct << "mapping = Dict(\n"; - for (const auto &variable : variableMapping) - { - output << " \"" - << symbol_table.getName(variable.first) - << "\" => ["; - for (auto equation : variable.second) - output << equation + 1 << ", "; - output << "]," << endl; - } - output << ")" << endl; + output << "M_.mapping." << symbol_table.getName(variable.first) << ".eqidx = ["; + for (auto equation : variable.second) + output << equation + 1 << " "; + output << "];" << endl; } - /* Say if static and dynamic models differ (because of [static] and [dynamic] equation tags) */ - output << modstruct << "static_and_dynamic_models_differ = " + output << "M_.static_and_dynamic_models_differ = " << (static_only_equations.size() > 0 ? "true" : "false") << ";" << endl; @@ -2950,7 +2920,7 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl has_external_function = true; break; } - output << modstruct << "has_external_function = " + output << "M_.has_external_function = " << (has_external_function ? "true" : "false") << ';' << endl; @@ -2971,64 +2941,56 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl // Write the block structure of the model if (block_decomposition) - writeBlockDriverOutput(output, basename, modstruct, state_var, estimation_present); + writeBlockDriverOutput(output, basename, state_var, estimation_present); - output << modstruct << "state_var = ["; + output << "M_.state_var = ["; for (int it : state_var) - output << it+1 << (julia ? "," : " "); + output << it+1 << " "; output << "];" << endl; // Writing initialization for some other variables - if (!julia) - output << modstruct << "exo_names_orig_ord = [1:" << symbol_table.exo_nbr() << "];" << endl; - else - output << modstruct << "exo_names_orig_ord = collect(1:" << symbol_table.exo_nbr() << ");" << endl; + output << "M_.exo_names_orig_ord = [1:" << symbol_table.exo_nbr() << "];" << endl; - output << modstruct << "maximum_lag = " << max_lag << ";" << endl - << modstruct << "maximum_lead = " << max_lead << ";" << endl; + output << "M_.maximum_lag = " << max_lag << ";" << endl + << "M_.maximum_lead = " << max_lead << ";" << endl; - output << modstruct << "maximum_endo_lag = " << max_endo_lag << ";" << endl - << modstruct << "maximum_endo_lead = " << max_endo_lead << ";" << endl - << outstruct << "steady_state = zeros(" << symbol_table.endo_nbr() << (julia ? ")" : ", 1);") << endl; + output << "M_.maximum_endo_lag = " << max_endo_lag << ";" << endl + << "M_.maximum_endo_lead = " << max_endo_lead << ";" << endl + << "oo_.steady_state = zeros(" << symbol_table.endo_nbr() << ", 1);" << endl; - output << modstruct << "maximum_exo_lag = " << max_exo_lag << ";" << endl - << modstruct << "maximum_exo_lead = " << max_exo_lead << ";" << endl - << outstruct << "exo_steady_state = zeros(" << symbol_table.exo_nbr() << (julia ? ")" : ", 1);") << endl; + output << "M_.maximum_exo_lag = " << max_exo_lag << ";" << endl + << "M_.maximum_exo_lead = " << max_exo_lead << ";" << endl + << "oo_.exo_steady_state = zeros(" << symbol_table.exo_nbr() << ", 1);" << endl; if (symbol_table.exo_det_nbr()) { - output << modstruct << "maximum_exo_det_lag = " << max_exo_det_lag << ";" << endl - << modstruct << "maximum_exo_det_lead = " << max_exo_det_lead << ";" << endl - << outstruct << "exo_det_steady_state = zeros(" << symbol_table.exo_det_nbr() << (julia ? ")" : ", 1);") << endl; + output << "M_.maximum_exo_det_lag = " << max_exo_det_lag << ";" << endl + << "M_.maximum_exo_det_lead = " << max_exo_det_lead << ";" << endl + << "oo_.exo_det_steady_state = zeros(" << symbol_table.exo_det_nbr() << ", 1);" << endl; } - output << modstruct << "params = " << (julia ? "fill(NaN, " : "NaN(") - << symbol_table.param_nbr() << (julia ? ")" : ", 1);") << endl; + output << "M_.params = " << "NaN(" << symbol_table.param_nbr() << ", 1);" << endl; - // FIXME: implement this for Julia - if (!julia) + string empty_cell = "cell(" + to_string(symbol_table.endo_nbr()) + ", 1)"; + output << "M_.endo_trends = struct('deflator', " << empty_cell + << ", 'log_deflator', " << empty_cell << ", 'growth_factor', " << empty_cell + << ", 'log_growth_factor', " << empty_cell << ");" << endl; + for (int i = 0; i < symbol_table.endo_nbr(); i++) { - string empty_cell = "cell(" + to_string(symbol_table.endo_nbr()) + ", 1)"; - output << modstruct << "endo_trends = struct('deflator', " << empty_cell - << ", 'log_deflator', " << empty_cell << ", 'growth_factor', " << empty_cell - << ", 'log_growth_factor', " << empty_cell << ");" << endl; - for (int i = 0; i < symbol_table.endo_nbr(); i++) + int symb_id = symbol_table.getID(SymbolType::endogenous, i); + if (auto it = nonstationary_symbols_map.find(symb_id); it != nonstationary_symbols_map.end()) { - int symb_id = symbol_table.getID(SymbolType::endogenous, i); - if (auto it = nonstationary_symbols_map.find(symb_id); it != nonstationary_symbols_map.end()) - { - auto [is_log, deflator] = it->second; - output << modstruct << "endo_trends(" << i << ")." - << (is_log ? "log_deflator" : "deflator") << " = '"; - deflator->writeJsonOutput(output, {}, {}); - output << "';" << endl; - - auto growth_factor = const_cast<DynamicModel *>(this)->AddDivide(deflator, deflator->decreaseLeadsLags(1))->removeTrendLeadLag(trend_symbols_map)->replaceTrendVar(); - output << modstruct << "endo_trends(" << i << ")." - << (is_log ? "log_growth_factor" : "growth_factor") << " = '"; - growth_factor->writeJsonOutput(output, {}, {}); - output << "';" << endl; - } + auto [is_log, deflator] = it->second; + output << "M_.endo_trends(" << i << ")." + << (is_log ? "log_deflator" : "deflator") << " = '"; + deflator->writeJsonOutput(output, {}, {}); + output << "';" << endl; + + auto growth_factor = const_cast<DynamicModel *>(this)->AddDivide(deflator, deflator->decreaseLeadsLags(1))->removeTrendLeadLag(trend_symbols_map)->replaceTrendVar(); + output << "M_.endo_trends(" << i << ")." + << (is_log ? "log_growth_factor" : "growth_factor") << " = '"; + growth_factor->writeJsonOutput(output, {}, {}); + output << "';" << endl; } } @@ -3037,7 +2999,7 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl // Write number of non-zero derivatives // Use -1 if the derivatives have not been computed - output << modstruct << (julia ? "nnzderivatives" : "NNZDerivatives") << " = ["; + output << "M_.NNZDerivatives = ["; for (int i = 1; i < static_cast<int>(NNZDerivatives.size()); i++) output << (i > computed_derivs_order ? -1 : NNZDerivatives[i]) << "; "; output << "];" << endl; @@ -3045,7 +3007,7 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl // Write Pac Model Consistent Expectation parameter info for (auto &it : pac_mce_alpha_symb_ids) { - output << modstruct << "pac." << it.first.first << ".equations." << it.first.second << ".mce.alpha = ["; + output << "M_.pac." << it.first.first << ".equations." << it.first.second << ".mce.alpha = ["; for (auto it : it.second) output << symbol_table.getTypeSpecificID(it) + 1 << " "; output << "];" << endl; @@ -3053,12 +3015,12 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl // Write Pac Model Consistent Expectation Z1 info for (auto &it : pac_mce_z1_symb_ids) - output << modstruct << "pac." << it.first.first << ".equations." << it.first.second << ".mce.z1 = " + output << "M_.pac." << it.first.first << ".equations." << it.first.second << ".mce.z1 = " << symbol_table.getTypeSpecificID(it.second) + 1 << ";" << endl; // Write Pac lag info for (auto &it : pac_eqtag_and_lag) - output << modstruct << "pac." << it.first.first << ".equations." << it.second.first << ".max_lag = " << it.second.second << ";" << endl; + output << "M_.pac." << it.first.first << ".equations." << it.second.first << ".max_lag = " << it.second.second << ";" << endl; // Write Pac equation tag info map<string, vector<pair<string, string>>> for_writing; @@ -3067,7 +3029,7 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl for (auto &it : for_writing) { - output << modstruct << "pac." << it.first << ".tag_map = ["; + output << "M_.pac." << it.first << ".tag_map = ["; for (auto &it1 : it.second) output << "{'" << it1.first << "', '" << it1.second << "'};"; output << "];" << endl; @@ -3076,17 +3038,17 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl for (auto &it : pac_model_info) { vector<int> lhs = get<0>(it.second); - output << modstruct << "pac." << it.first << ".lhs = ["; + output << "M_.pac." << it.first << ".lhs = ["; for (auto it : lhs) output << it + 1 << " "; output << "];" << endl; if (int growth_param_index = get<1>(it.second); growth_param_index >= 0) - output << modstruct << "pac." << it.first << ".growth_neutrality_param_index = " + output << "M_.pac." << it.first << ".growth_neutrality_param_index = " << symbol_table.getTypeSpecificID(growth_param_index) + 1 << ";" << endl; - output << modstruct << "pac." << it.first << ".auxiliary_model_type = '" << get<2>(it.second) << "';" << endl; + output << "M_.pac." << it.first << ".auxiliary_model_type = '" << get<2>(it.second) << "';" << endl; } for (auto &pit : pac_equation_info) @@ -3094,28 +3056,28 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl auto [lhs_pac_var, optim_share_index, ar_params_and_vars, ec_params_and_vars, non_optim_vars_params_and_constants, additive_vars_params_and_constants, optim_additive_vars_params_and_constants] = pit.second; string substruct = pit.first.first + ".equations." + pit.first.second + "."; - output << modstruct << "pac." << substruct << "lhs_var = " + output << "M_.pac." << substruct << "lhs_var = " << symbol_table.getTypeSpecificID(lhs_pac_var.first) + 1 << ";" << endl; if (optim_share_index >= 0) - output << modstruct << "pac." << substruct << "share_of_optimizing_agents_index = " + output << "M_.pac." << substruct << "share_of_optimizing_agents_index = " << symbol_table.getTypeSpecificID(optim_share_index) + 1 << ";" << endl; - output << modstruct << "pac." << substruct << "ec.params = " + output << "M_.pac." << substruct << "ec.params = " << symbol_table.getTypeSpecificID(ec_params_and_vars.first) + 1 << ";" << endl - << modstruct << "pac." << substruct << "ec.vars = ["; + << "M_.pac." << substruct << "ec.vars = ["; for (auto it : ec_params_and_vars.second) output << symbol_table.getTypeSpecificID(get<0>(it)) + 1 << " "; output << "];" << endl - << modstruct << "pac." << substruct << "ec.istarget = ["; + << "M_.pac." << substruct << "ec.istarget = ["; for (auto it : ec_params_and_vars.second) output << (get<1>(it) ? "true " : "false "); output << "];" << endl - << modstruct << "pac." << substruct << "ec.scale = ["; + << "M_.pac." << substruct << "ec.scale = ["; for (auto it : ec_params_and_vars.second) output << get<2>(it) << " "; output << "];" << endl - << modstruct << "pac." << substruct << "ec.isendo = ["; + << "M_.pac." << substruct << "ec.isendo = ["; for (auto it : ec_params_and_vars.second) switch (symbol_table.getType(get<0>(it))) { @@ -3130,32 +3092,32 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl exit(EXIT_FAILURE); } output << "];" << endl - << modstruct << "pac." << substruct << "ar.params = ["; + << "M_.pac." << substruct << "ar.params = ["; for (auto &[pid, vid, vlag] : ar_params_and_vars) output << (pid != -1 ? symbol_table.getTypeSpecificID(pid) + 1 : -1) << " "; output << "];" << endl - << modstruct << "pac." << substruct << "ar.vars = ["; + << "M_.pac." << substruct << "ar.vars = ["; for (auto &[pid, vid, vlag] : ar_params_and_vars) output << (vid != -1 ? symbol_table.getTypeSpecificID(vid) + 1 : -1) << " "; output << "];" << endl - << modstruct << "pac." << substruct << "ar.lags = ["; + << "M_.pac." << substruct << "ar.lags = ["; for (auto &[pid, vid, vlag] : ar_params_and_vars) output << vlag << " "; output << "];" << endl; if (!non_optim_vars_params_and_constants.empty()) { - output << modstruct << "pac." << substruct << "non_optimizing_behaviour.params = ["; + output << "M_.pac." << substruct << "non_optimizing_behaviour.params = ["; for (auto &it : non_optim_vars_params_and_constants) if (get<2>(it) >= 0) output << symbol_table.getTypeSpecificID(get<2>(it)) + 1 << " "; else output << "NaN "; output << "];" << endl - << modstruct << "pac." << substruct << "non_optimizing_behaviour.vars = ["; + << "M_.pac." << substruct << "non_optimizing_behaviour.vars = ["; for (auto &it : non_optim_vars_params_and_constants) output << symbol_table.getTypeSpecificID(get<0>(it)) + 1 << " "; output << "];" << endl - << modstruct << "pac." << substruct << "non_optimizing_behaviour.isendo = ["; + << "M_.pac." << substruct << "non_optimizing_behaviour.isendo = ["; for (auto &it : non_optim_vars_params_and_constants) switch (symbol_table.getType(get<0>(it))) { @@ -3170,29 +3132,29 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl exit(EXIT_FAILURE); } output << "];" << endl - << modstruct << "pac." << substruct << "non_optimizing_behaviour.lags = ["; + << "M_.pac." << substruct << "non_optimizing_behaviour.lags = ["; for (auto &it : non_optim_vars_params_and_constants) output << get<1>(it) << " "; output << "];" << endl - << modstruct << "pac." << substruct << "non_optimizing_behaviour.scaling_factor = ["; + << "M_.pac." << substruct << "non_optimizing_behaviour.scaling_factor = ["; for (auto &it : non_optim_vars_params_and_constants) output << get<3>(it) << " "; output << "];" << endl; } if (!additive_vars_params_and_constants.empty()) { - output << modstruct << "pac." << substruct << "additive.params = ["; + output << "M_.pac." << substruct << "additive.params = ["; for (auto &it : additive_vars_params_and_constants) if (get<2>(it) >= 0) output << symbol_table.getTypeSpecificID(get<2>(it)) + 1 << " "; else output << "NaN "; output << "];" << endl - << modstruct << "pac." << substruct << "additive.vars = ["; + << "M_.pac." << substruct << "additive.vars = ["; for (auto &it : additive_vars_params_and_constants) output << symbol_table.getTypeSpecificID(get<0>(it)) + 1 << " "; output << "];" << endl - << modstruct << "pac." << substruct << "additive.isendo = ["; + << "M_.pac." << substruct << "additive.isendo = ["; for (auto &it : additive_vars_params_and_constants) switch (symbol_table.getType(get<0>(it))) { @@ -3207,29 +3169,29 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl exit(EXIT_FAILURE); } output << "];" << endl - << modstruct << "pac." << substruct << "additive.lags = ["; + << "M_.pac." << substruct << "additive.lags = ["; for (auto &it : additive_vars_params_and_constants) output << get<1>(it) << " "; output << "];" << endl - << modstruct << "pac." << substruct << "additive.scaling_factor = ["; + << "M_.pac." << substruct << "additive.scaling_factor = ["; for (auto &it : additive_vars_params_and_constants) output << get<3>(it) << " "; output << "];" << endl; } if (!optim_additive_vars_params_and_constants.empty()) { - output << modstruct << "pac." << substruct << "optim_additive.params = ["; + output << "M_.pac." << substruct << "optim_additive.params = ["; for (auto &it : optim_additive_vars_params_and_constants) if (get<2>(it) >= 0) output << symbol_table.getTypeSpecificID(get<2>(it)) + 1 << " "; else output << "NaN "; output << "];" << endl - << modstruct << "pac." << substruct << "optim_additive.vars = ["; + << "M_.pac." << substruct << "optim_additive.vars = ["; for (auto &it : optim_additive_vars_params_and_constants) output << symbol_table.getTypeSpecificID(get<0>(it)) + 1 << " "; output << "];" << endl - << modstruct << "pac." << substruct << "optim_additive.isendo = ["; + << "M_.pac." << substruct << "optim_additive.isendo = ["; for (auto &it : optim_additive_vars_params_and_constants) switch (symbol_table.getType(get<0>(it))) { @@ -3244,23 +3206,23 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl exit(EXIT_FAILURE); } output << "];" << endl - << modstruct << "pac." << substruct << "optim_additive.lags = ["; + << "M_.pac." << substruct << "optim_additive.lags = ["; for (auto &it : optim_additive_vars_params_and_constants) output << get<1>(it) << " "; output << "];" << endl - << modstruct << "pac." << substruct << "optim_additive.scaling_factor = ["; + << "M_.pac." << substruct << "optim_additive.scaling_factor = ["; for (auto &it : optim_additive_vars_params_and_constants) output << get<3>(it) << " "; output << "];" << endl; } // Create empty h0 and h1 substructures that will be overwritten later if not empty - output << modstruct << "pac." << substruct << "h0_param_indices = [];" << endl - << modstruct << "pac." << substruct << "h1_param_indices = [];" << endl; + output << "M_.pac." << substruct << "h0_param_indices = [];" << endl + << "M_.pac." << substruct << "h1_param_indices = [];" << endl; } for (auto &it : pac_h0_indices) { - output << modstruct << "pac." << it.first.first << ".equations." << it.first.second << ".h0_param_indices = ["; + output << "M_.pac." << it.first.first << ".equations." << it.first.second << ".h0_param_indices = ["; for (auto it1 : it.second) output << symbol_table.getTypeSpecificID(it1) + 1 << " "; output << "];" << endl; @@ -3268,7 +3230,7 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl for (auto &it : pac_h1_indices) { - output << modstruct << "pac." << it.first.first << ".equations." << it.first.second << ".h1_param_indices = ["; + output << "M_.pac." << it.first.first << ".equations." << it.first.second << ".h1_param_indices = ["; for (auto it1 : it.second) output << symbol_table.getTypeSpecificID(it1) + 1 << " "; output << "];" << endl; diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 1c68bb87..d98b13c5 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -156,7 +156,7 @@ private: void writeAuxVarRecursiveDefinitions(ostream &output, ExprNodeOutputType output_type) const; // Write the block structure of the model in the driver file - void writeBlockDriverOutput(ostream &output, const string &basename, const string &modstruct, + void writeBlockDriverOutput(ostream &output, const string &basename, const vector<int> &state_var, bool estimation_present) const; // Used by determineBlockDerivativesType() @@ -300,7 +300,7 @@ public: void computingPass(bool jacobianExo, int derivsOrder, int paramsDerivsOrder, const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll, bool bytecode); //! Writes information about the dynamic model to the driver file - void writeDriverOutput(ostream &output, const string &basename, bool block, bool use_dll, bool estimation_present, bool compute_xrefs, bool julia) const; + void writeDriverOutput(ostream &output, const string &basename, bool block, bool use_dll, bool estimation_present, bool compute_xrefs) const; //! Write JSON AST void writeJsonAST(ostream &output) const; diff --git a/src/EquationTags.cc b/src/EquationTags.cc index d6077212..c86fd51a 100644 --- a/src/EquationTags.cc +++ b/src/EquationTags.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Dynare Team + * Copyright © 2020-2021 Dynare Team * * This file is part of Dynare. * @@ -76,37 +76,19 @@ EquationTags::writeCheckSumInfo(ostream &output) const } void -EquationTags::writeOutput(ostream &output, const string &modstruct, bool julia) const +EquationTags::writeOutput(ostream &output) const { - if (julia) - { - output << modstruct << "equation_tags = [" << endl; - for (const auto & [eqn, tags] : eqn_tags) - for (const auto & [key, value] : tags) - output << " EquationTag(" - << eqn + 1 << R"( , ")" - << key << R"(" , ")" << value << R"("))" << endl; - output << " ]" << endl; - } - else - { - output << modstruct << "equations_tags = {" << endl; - for (const auto & [eqn, tags] : eqn_tags) - { - for (const auto & [key, value] : tags) - output << " " << eqn + 1 << " , '" - << key << "' , '" << value << "' ;" << endl; - } - output << "};" << endl; - } + output << "M_.equations_tags = {" << endl; + for (const auto & [eqn, tags] : eqn_tags) + for (const auto & [key, value] : tags) + output << " " << eqn + 1 << " , '" + << key << "' , '" << value << "' ;" << endl; + output << "};" << endl; } void -EquationTags::writeOccbinOutput(ostream &output, const string &modstruct, bool julia) const +EquationTags::writeOccbinOutput(ostream &output) const { - if (julia) - return; - map<int, map<string, string>> occbin_options; for (const auto & [eqn, tags] : eqn_tags) for (const auto & [key, value] : tags) @@ -121,9 +103,9 @@ EquationTags::writeOccbinOutput(ostream &output, const string &modstruct, bool j { idx++; for (const auto & [key, value] : tags) - output << modstruct << "occbin.constraint(" << idx << ")." + output << "M_.occbin.constraint(" << idx << ")." << key << " = '" << value << "';" << endl; - output << modstruct << "occbin.constraint(" << idx << ").equation = " + output << "M_.occbin.constraint(" << idx << ").equation = " << eqn+1 << ";" << endl; } } diff --git a/src/EquationTags.hh b/src/EquationTags.hh index ddd1eec5..d573f8c0 100644 --- a/src/EquationTags.hh +++ b/src/EquationTags.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Dynare Team + * Copyright © 2020-2021 Dynare Team * * This file is part of Dynare. * @@ -111,8 +111,8 @@ public: //! Various functions to write equation tags void writeCheckSumInfo(ostream &output) const; - void writeOutput(ostream &output, const string &modstruct, bool julia) const; - void writeOccbinOutput(ostream &output, const string &modstruct, bool julia) const; + void writeOutput(ostream &output) const; + void writeOccbinOutput(ostream &output) const; void writeLatexOutput(ostream &output, int eqn) const; void writeJsonAST(ostream &output, const int eq) const; }; diff --git a/src/ModFile.cc b/src/ModFile.cc index 40a7b25f..d6bd0c28 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -1011,7 +1011,7 @@ ModFile::writeMOutput(const string &basename, bool clear_all, bool clear_global, if (dynamic_model.equation_number() > 0) { - dynamic_model.writeDriverOutput(mOutputFile, basename, block, use_dll, mod_file_struct.estimation_present, compute_xrefs, false); + dynamic_model.writeDriverOutput(mOutputFile, basename, block, use_dll, mod_file_struct.estimation_present, compute_xrefs); if (!no_static) static_model.writeDriverOutput(mOutputFile, block); } @@ -1139,88 +1139,8 @@ ModFile::writeMOutput(const string &basename, bool clear_all, bool clear_global, void ModFile::writeJuliaOutput(const string &basename) const { - ofstream jlOutputFile; - if (basename.size()) - { - string fname(basename); - fname += ".jl"; - jlOutputFile.open(fname, ios::out | ios::binary); - if (!jlOutputFile.is_open()) - { - cerr << "ERROR: Can't open file " << fname - << " for writing" << endl; - exit(EXIT_FAILURE); - } - } - else - { - cerr << "ERROR: Missing file name" << endl; - exit(EXIT_FAILURE); - } - - jlOutputFile << "module " << basename << endl - << "#" << endl - << "# NB: this file was automatically generated by Dynare" << endl - << "# from " << basename << ".mod" << endl - << "#" << endl << endl - << "using DynareModel" << endl - << "using DynareOptions" << endl - << "using DynareOutput" << endl << endl - << "using Utils" << endl - << "using SteadyState" << endl << endl - << "using " << basename << "Static" << endl - << "using " << basename << "Dynamic" << endl - << R"(if isfile(")" << basename << R"(SteadyState.jl"))" << endl - << " using " << basename << "SteadyState" << endl - << "end" << endl - << R"(if isfile(")" << basename << R"(SteadyState2.jl"))" << endl - << " using " << basename << "SteadyState2" << endl - << "end" << endl << endl - << "export model_, options_, oo_" << endl; - - // Write Output - jlOutputFile << endl - << "oo_ = dynare_output()" << endl - << R"(oo_.dynare_version = ")" << PACKAGE_VERSION << R"(")" << endl; - - // Write Options - jlOutputFile << endl - << "options_ = dynare_options()" << endl - << R"(options_.dynare_version = ")" << PACKAGE_VERSION << R"(")" << endl; - if (linear) - jlOutputFile << "options_.linear = true" << endl; - - // Write Model - jlOutputFile << endl - << "model_ = dynare_model()" << endl - << R"(model_.fname = ")" << basename << R"(")" << endl - << R"(model_.dynare_version = ")" << PACKAGE_VERSION << R"(")" << endl - << "model_.sigma_e = zeros(Float64, " << symbol_table.exo_nbr() << ", " - << symbol_table.exo_nbr() << ")" << endl - << "model_.correlation_matrix = ones(Float64, " << symbol_table.exo_nbr() << ", " - << symbol_table.exo_nbr() << ")" << endl - << "model_.orig_eq_nbr = " << mod_file_struct.orig_eq_nbr << endl - << "model_.eq_nbr = " << dynamic_model.equation_number() << endl - << "model_.ramsey_eq_nbr = " << mod_file_struct.ramsey_eq_nbr << endl; - - if (mod_file_struct.calibrated_measurement_errors) - jlOutputFile << "model_.h = zeros(Float64," - << symbol_table.observedVariablesNbr() << ", " - << symbol_table.observedVariablesNbr() << ");" << endl - << "model_.correlation_matrix_me = ones(Float64, " - << symbol_table.observedVariablesNbr() << ", " - << symbol_table.observedVariablesNbr() << ");" << endl; - else - jlOutputFile << "model_.h = zeros(Float64, 1, 1)" << endl - << "model_.correlation_matrix_me = ones(Float64, 1, 1)" << endl; - - cout << "Processing outputs ..." << endl; - symbol_table.writeJuliaOutput(jlOutputFile); - if (dynamic_model.equation_number() > 0) { - dynamic_model.writeDriverOutput(jlOutputFile, basename, false, false, - mod_file_struct.estimation_present, false, true); if (!no_static) { static_model.writeStaticFile(basename, false, false, false, "", {}, {}, true); @@ -1230,34 +1150,6 @@ ModFile::writeJuliaOutput(const string &basename) const dynamic_model.writeParamsDerivativesFile(basename, true); } steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present, true); - - // Print statements (includes parameter values) - for (const auto &statement : statements) - statement->writeJuliaOutput(jlOutputFile, basename); - - jlOutputFile << "model_.static = " << basename << "Static.static!" << endl - << "model_.dynamic = " << basename << "Dynamic.dynamic!" << endl - << "model_.temporaries.static = " << basename << "Static.tmp_nbr" << endl - << "model_.temporaries.dynamic = " << basename << "Dynamic.tmp_nbr" << endl - << R"(if isfile(")" << basename << R"(SteadyState.jl"))" << endl - << " model_.user_written_analytical_steady_state = true" << endl - << " model_.steady_state = " << basename << "SteadyState.steady_state!" << endl - << "end" << endl - << R"(if isfile(")" << basename << R"(SteadyState2.jl"))" << endl - << " model_.analytical_steady_state = true" << endl - << " model_.steady_state = " << basename << "SteadyState2.steady_state!" << endl - << "end" << endl - << R"(if isfile(")" << basename << R"(StaticParamsDerivs.jl"))" << endl - << " using " << basename << "StaticParamsDerivs" << endl - << " model_.static_params_derivs = " << basename << "StaticParamsDerivs.params_derivs" << endl - << "end" << endl - << R"(if isfile(")" << basename << R"(DynamicParamsDerivs.jl"))" << endl - << " using " << basename << "DynamicParamsDerivs" << endl - << " model_.dynamic_params_derivs = " << basename << "DynamicParamsDerivs.params_derivs" << endl - << "end" << endl - << "end" << endl; - jlOutputFile.close(); - cout << "done" << endl; } void diff --git a/src/NumericalInitialization.cc b/src/NumericalInitialization.cc index b044e293..9bf0103e 100644 --- a/src/NumericalInitialization.cc +++ b/src/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2020 Dynare Team + * Copyright © 2003-2021 Dynare Team * * This file is part of Dynare. * @@ -56,15 +56,6 @@ InitParamStatement::writeOutput(ostream &output, const string &basename, bool mi output << symbol_table.getName(symb_id) << " = M_.params(" << id << ");" << endl; } -void -InitParamStatement::writeJuliaOutput(ostream &output, const string &basename) -{ - int id = symbol_table.getTypeSpecificID(symb_id) + 1; - output << "model_.params[ " << id << " ] = "; - param_value->writeOutput(output); - output << endl; -} - void InitParamStatement::writeJsonOutput(ostream &output) const { diff --git a/src/NumericalInitialization.hh b/src/NumericalInitialization.hh index 6a114b7f..60dfd75c 100644 --- a/src/NumericalInitialization.hh +++ b/src/NumericalInitialization.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2019 Dynare Team + * Copyright © 2003-2021 Dynare Team * * This file is part of Dynare. * @@ -41,7 +41,6 @@ public: const SymbolTable &symbol_table_arg); void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override; void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override; - void writeJuliaOutput(ostream &output, const string &basename) override; void writeJsonOutput(ostream &output) const override; //! Fill eval context with parameter value void fillEvalContext(eval_context_t &eval_context) const; diff --git a/src/Statement.cc b/src/Statement.cc index 4e7afa1b..85c6d235 100644 --- a/src/Statement.cc +++ b/src/Statement.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2006-2020 Dynare Team + * Copyright © 2006-2021 Dynare Team * * This file is part of Dynare. * @@ -29,11 +29,6 @@ Statement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &wa { } -void -Statement::writeJuliaOutput(ostream &output, const string &basename) -{ -} - void Statement::computingPass() { diff --git a/src/Statement.hh b/src/Statement.hh index fd8b80ae..dc4cf190 100644 --- a/src/Statement.hh +++ b/src/Statement.hh @@ -171,7 +171,6 @@ public: \param basename is the name of the modfile (without extension) which can be used to build auxiliary files */ virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const = 0; - virtual void writeJuliaOutput(ostream &output, const string &basename); virtual void writeJsonOutput(ostream &output) const = 0; }; diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index 1a10f239..d0873ae6 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2020 Dynare Team + * Copyright © 2003-2021 Dynare Team * * This file is part of Dynare. * @@ -915,138 +915,6 @@ SymbolTable::getOrigEndogenous() const return origendogs; } -void -SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false) -{ - if (!frozen) - throw NotYetFrozenException(); - - output << "# Endogenous Variables" << endl - << "model_.endo = [" << endl; - if (endo_nbr() > 0) - for (int id = 0; id < endo_nbr(); id++) - output << R"( DynareModel.Endo(")" - << getName(endo_ids[id]) << R"(", raw")" - << getTeXName(endo_ids[id]) << R"(", ")" - << getLongName(endo_ids[id]) << R"("))" << endl; - output << " ]" << endl; - output << "model_.endo_nbr = " << endo_nbr() << ";" << endl; - - output << "# Exogenous Variables" << endl - << "model_.exo = [" << endl; - if (exo_nbr() > 0) - for (int id = 0; id < exo_nbr(); id++) - output << R"( DynareModel.Exo(")" - << getName(exo_ids[id]) << R"(", raw")" - << getTeXName(exo_ids[id]) << R"(", ")" - << getLongName(exo_ids[id]) << R"("))" << endl; - output << " ]" << endl; - output << "model_.exo_nbr = " << exo_nbr() << ";" << endl; - - if (exo_det_nbr() > 0) - { - output << "# Exogenous Deterministic Variables" << endl - << "model_.exo_det = [" << endl; - if (exo_det_nbr() > 0) - for (int id = 0; id < exo_det_nbr(); id++) - output << R"( DynareModel.ExoDet(")" - << getName(exo_det_ids[id]) << R"(", raw")" - << getTeXName(exo_det_ids[id]) << R"(", ")" - << getLongName(exo_det_ids[id]) << R"("))" << endl; - output << " ]" << endl; - output << "model_.exo_det_nbr = " << exo_det_nbr() << ";" << endl; - } - - output << "# Parameters" << endl - << "model_.param = [" << endl; - if (param_nbr() > 0) - for (int id = 0; id < param_nbr(); id++) - output << R"( DynareModel.Param(")" - << getName(param_ids[id]) << R"(", raw")" - << getTeXName(param_ids[id]) << R"(", ")" - << getLongName(param_ids[id]) << R"("))" << endl; - output << " ]" << endl; - output << "model_.param_nbr = " << param_nbr() << ";" << endl; - - output << "model_.orig_endo_nbr = " << orig_endo_nbr() << endl; - - if (aux_vars.size() > 0) - { - output << "# Auxiliary Variables" << endl - << "model_.aux_vars = [" << endl; - for (const auto &aux_var : aux_vars) - { - output << " DynareModel.AuxVars(" - << getTypeSpecificID(aux_var.get_symb_id()) + 1 << ", " - << aux_var.get_type_id() << ", "; - switch (aux_var.get_type()) - { - case AuxVarType::endoLead: - case AuxVarType::exoLead: - case AuxVarType::endoLag: - case AuxVarType::exoLag: - case AuxVarType::varModel: - output << getTypeSpecificID(aux_var.get_orig_symb_id()) + 1 << ", " - << aux_var.get_orig_lead_lag() << ", typemin(Int), string(), string()"; - break; - case AuxVarType::unaryOp: - if (aux_var.get_orig_symb_id() >= 0) - output << getTypeSpecificID(aux_var.get_orig_symb_id()) + 1 << ", " << aux_var.get_orig_lead_lag(); - else - output << "typemin(Int), typemin(Int)"; - output << ", typemin(Int), string(), " - << R"(")" << aux_var.get_unary_op() << R"(")" << endl; - break; - case AuxVarType::diff: - case AuxVarType::diffLag: - case AuxVarType::diffLead: - if (aux_var.get_orig_symb_id() >= 0) - output << getTypeSpecificID(aux_var.get_orig_symb_id()) + 1 << ", " - << aux_var.get_orig_lead_lag() << ", typemin(Int), string(), string()"; - break; - case AuxVarType::multiplier: - output << "typemin(Int), typemin(Int), " << aux_var.get_equation_number_for_multiplier() + 1 - << ", string(), string()"; - break; - case AuxVarType::diffForward: - output << getTypeSpecificID(aux_var.get_orig_symb_id())+1 << ", typemin(Int), typemin(Int), string(), string()"; - break; - case AuxVarType::expectation: - output << R"(typemin(Int), typemin(Int), typemin(Int), "\mathbb{E}_{t)" - << (aux_var.get_information_set() < 0 ? "" : "+") - << aux_var.get_information_set() << "}("; - aux_var.get_expr_node()->writeOutput(output, ExprNodeOutputType::latexDynamicModel); - output << R"lit()")lit"; - break; - default: - output << " typemin(Int), typemin(Int), typemin(Int), string(), string()"; - } - output << ")" << endl; - } - output << "]" << endl; - } - - if (predeterminedNbr() > 0) - { - output << "# Predetermined Variables" << endl - << "model_.pred_vars = [ " << endl; - for (int predetermined_variable : predetermined_variables) - output << " DynareModel.PredVars(" - << getTypeSpecificID(predetermined_variable)+1 << ")" << endl; - output << " ]" << endl; - } - - if (observedVariablesNbr() > 0) - { - output << "# Observed Variables" << endl - << "options_.obs_vars = [" << endl; - for (int varob : varobs) - output << " DynareModel.ObsVars(" - << getTypeSpecificID(varob)+1 << ")" << endl; - output << " ]" << endl; - } -} - void SymbolTable::writeJsonOutput(ostream &output) const { diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh index 71197111..d294d36b 100644 --- a/src/SymbolTable.hh +++ b/src/SymbolTable.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2020 Dynare Team + * Copyright © 2003-2021 Dynare Team * * This file is part of Dynare. * @@ -390,8 +390,6 @@ public: void writeOutput(ostream &output) const noexcept(false); //! Write JSON Output void writeJsonOutput(ostream &output) const; - //! Write Julia output of this class - void writeJuliaOutput(ostream &output) const noexcept(false); //! Mark a symbol as predetermined variable void markPredetermined(int symb_id) noexcept(false); //! Test if a given symbol is a predetermined variable -- GitLab