Commit f83648ac authored by MichelJuillard's avatar MichelJuillard
Browse files

adding Julia specific nocompile option to avoid recompiling

the model if it hasn't changed

function get_power_deriv is now in Dynamic and Static modules
parent c02422ec
Pipeline #5201 failed with stage
in 2 minutes and 38 seconds
module Dynare
using Plots
using GR
using Revise
gr()
......@@ -16,8 +17,6 @@ include("DynarePreprocessor.jl")
export dynare_preprocess
include("steady_state/SteadyState.jl")
export steady_state!
include("Utils.jl")
export get_power_deriv
include("dynare_table.jl")
include("reporting/report.jl")
include("graphics.jl")
......@@ -28,6 +27,14 @@ include("perturbations.jl")
export @dynare
mutable struct CommandLineOptions
compilemodule::Bool
function CommandLineOptions()
compilemodule = true
new(compilemodule)
end
end
macro dynare(modfilename, args...)
modfilename = string(modfilename)
if occursin(r"\.mod$", modfilename)
......@@ -35,8 +42,15 @@ macro dynare(modfilename, args...)
else
modname = modfilename
end
options = CommandLineOptions()
for (i, a) in enumerate(args)
if a == "nocompile"
options.compilemodule = false
deleteat!(args, i)
end
end
dynare_preprocess(modname*".mod", args)
context = parser(modname)
context = parser(modname, options)
return context
end
......
......@@ -27,7 +27,7 @@ context = Context(Dict{String, DynareSymbol}(),
)
)
function parser(modfilename)
function parser(modfilename, commandlineoptions)
modelstring = open(f -> read(f, String), modfilename*"/model/json/modfile.json")
modeljson = JSON.parse(modelstring)
......@@ -61,7 +61,8 @@ function parser(modfilename)
model_info.orig_maximum_exo_det_lag,
model_info.orig_maximum_exo_det_lead,
model_info.orig_maximum_lag,
model_info.orig_maximum_lead
model_info.orig_maximum_lead,
commandlineoptions.compilemodule
)
varobs = Vector{String}()
......
......@@ -99,8 +99,7 @@ function Model(modfilename, endogenous_nbr, lead_lag_incidence,
orig_maximum_endo_lag, orig_maximum_endo_lead,
orig_maximum_exo_lag, orig_maximum_exo_lead,
orig_maximum_exo_det_lag, orig_maximum_exo_det_lead,
orig_maximum_lag, orig_maximum_lead)
orig_maximum_lag, orig_maximum_lead, compileoption)
i_static = findall((lead_lag_incidence[1,:] .== 0) .& (lead_lag_incidence[3,:] .== 0))
p_static = lead_lag_incidence[2,i_static]
i_dyn = findall((lead_lag_incidence[1,:] .> 0) .| (lead_lag_incidence[3,:] .> 0))
......@@ -172,22 +171,27 @@ function Model(modfilename, endogenous_nbr, lead_lag_incidence,
findall(in(current_dynamic_indices), dynamic_indices)
exogenous_indices = (backward_number + current_number
+ forward_number .+ (1:exogenous_nbr))
dynamic! = load_dynare_function(modfilename*"Dynamic")
static! = load_dynare_function(modfilename*"Static")
dynamic! = load_dynare_function(modfilename*"Dynamic",
compileoption)
static! = load_dynare_function(modfilename*"Static",
compileoption)
if isfile(modfilename*"DynamicSetAuxiliarySeries")
set_dynamic_auxiliary_variables! =
load_dynare_function(modfilename*"DynamicSetAuxiliarySeries")
load_dynare_function(modfilename*"DynamicSetAuxiliarySeries",
compileoption)
else
set_dynamic_auxiliary_variables! = Nothing
end
if isfile(modfilename*"SetAuxiliarySeries")
set_auxiliary_variables! =
load_dynare_function(modfilename*"SetAuxiliarySeries")
load_dynare_function(modfilename*"SetAuxiliarySeries",
compileoption)
else
set_auxiliary_variables! = Nothing
end
if isfile(modfilename*"SteadyState2.jl")
steady_state! = load_dynare_function(modfilename*"SteadyState2")
steady_state! = load_dynare_function(modfilename*"SteadyState2",
compileoption)
else
steady_state! = nothing
end
......
using LinearAlgebra
using Revise
using Suppressor
export get_de, get_abc, inverse_order_of_dynare_decision_rule
function inverse_order_of_dynare_decision_rule(m::Model)
......@@ -28,11 +30,17 @@ function inverse_order_of_dynare_decision_rule(m::Model)
(inverse_order_var, inverse_order_states)
end
function load_dynare_function(modname::String)
push!(LOAD_PATH, dirname(modname))
name = basename(modname)
@suppress eval(Meta.parse("using "*name))
return(eval(Symbol(name)))
function load_dynare_function(modname::String, compileoption)
if compileoption
fun = readlines(modname*".jl")
return(eval(Meta.parse(join(fun, "\n"))))
else
push!(LOAD_PATH, dirname(modname))
name = basename(modname)
eval(Meta.parse("using "*name))
pop!(LOAD_PATH)
return(eval(Symbol(name)))
end
end
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment