QuantEcon / lecture-julia.myst

Lecture source for "Quantitative Economics with Julia"
https://julia.quantecon.org/intro.html
52 stars 43 forks source link

Update the packages/etc. for Julia 1.9 #249

Closed jlperla closed 1 year ago

jlperla commented 1 year ago

After that we will need to update the continuous integration stuff.

Jonah-Heyl commented 1 year ago

I have run the full lecture suit with julia 1.9. There were not any major issues. A few notes are that in "14. Geometric Series for Elementary Economics" there was an issue with the latex compile with the symbolics package (I think this is due to my local set up though). In "20. Krylov Methods and Matrix Conditioning" the "OrdinaryDiffEq.FunctionMap" package gave a warning about a conflict (still seemed to run fine though). In "60. Multiplicative Functionals" there is a panel with a whole bunch of graphs and the text overlaps (this could be a theme or build issue).

jlperla commented 1 year ago

Great! Yeah you will probably need a local latex isntallation working on your machine to see the titles correctly for the plots. Not sure if that is a theme issue or not.

Why don't you copuy/past the wranings/etc. as a list here to discuss? Some might be deprecations which we want to trigger new issues for.

Jonah-Heyl commented 1 year ago

From lecture 14, IOError: could not spawn lualatex --interaction=batchmode main.tex: permission denied (EACCES)

Stacktrace: [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Union{RawFD, IO}}) @ Base ./process.jl:128 [2] #760 @ ./process.jl:139 [inlined] [3] setup_stdios(f::Base.var"#760#761"{Cmd}, stdios::Vector{Union{RawFD, IO}}) @ Base ./process.jl:223 [4] _spawn @ ./process.jl:138 [inlined] [5] _spawn(::Base.CmdRedirect, ::Vector{Union{RawFD, IO}}) @ Base ./process.jl:166 [6] run(::Base.CmdRedirect; wait::Bool) @ Base ./process.jl:479 [7] run(::Base.CmdRedirect) @ Base ./process.jl:477 [8] (::Latexify.var"#138#140"{Bool, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, LaTeXString})() @ Latexify ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:43 [9] cd(f::Latexify.var"#138#140"{Bool, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, LaTeXString}, dir::String) @ Base.Filesystem ./file.jl:112 [10] #137 @ ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:40 [inlined] [11] mktempdir(fn::Latexify.var"#137#139"{Bool, String, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, LaTeXString, String}, parent::String; prefix::String) @ Base.Filesystem ./file.jl:760 [12] mktempdir (repeats 2 times) @ ./file.jl:756 [inlined] [13] #_compile#136 @ ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:39 [inlined] [14] _compile @ ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:33 [inlined] [15] render(s::LaTeXString, ::MIME{Symbol("application/pdf")}; kw::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:debug, :name, :open), Tuple{Bool, String, Bool}}}) @ Latexify ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:124 [16] render @ ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:124 [inlined] [17] (::Latexify.var"#148#149"{Bool, Symbol, String, Int64, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, LaTeXString, String})(aux_name::String, #unused#::IOStream) @ Latexify ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:158 [18] mktemp(fn::Latexify.var"#148#149"{Bool, Symbol, String, Int64, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, LaTeXString, String}, parent::String) @ Base.Filesystem ./file.jl:732 [19] mktemp @ ./file.jl:730 [inlined] [20] render(s::LaTeXString, mime::MIME{Symbol("image/png")}; debug::Bool, convert::Symbol, name::String, callshow::Bool, open::Bool, dpi::Int64, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Latexify ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:145 [21] render @ ~/.julia/packages/Latexify/f4YvQ/src/utils.jl:134 [inlined] [22] #3 @ ./In[7]:7 [inlined] [23] |>(x::LaTeXString, f::var"#3#4") @ Base ./operators.jl:907 [24] top-level scope @ In[7]:7

From Lecture 20, WARNING: using OrdinaryDiffEq.FunctionMap in module Main conflicts with an existing identifier.

From lecture 60, Screenshot 2023-06-12 111513.

Jonah-Heyl commented 1 year ago

I should have put this first but the code that caused these warnings was,

Lecture 14,

Creates algebraic symbols that can be used in an algebraic expression

@variables g, r, x0 G = (1 + g) R = (1 + r) p0 = x0 / (1 - G * R ^ (-1)) print("Our formula is") latexify(p0) |> s -> render(s, MIME("image/png"))

From Lecture 20, using OrdinaryDiffEq, DiffEqOperators

function solve_transition_dynamics(p, t) (;N, M) = p

ψ_0 = [1.0; fill(0.0, N^M - 1)]
O! = MatrixFreeOperator((dψ, ψ, p, t) -> Q_T_mul!(dψ, ψ, p), (p, 0.0),
                        size=(N^M,N^M), opnorm=(p)->1.25)

# define the corresponding ODE problem
prob = ODEProblem(O!,ψ_0,(0.0,t[end]), p)
return solve(prob, LinearExponential(krylov=:simple), tstops = t)

end t = 0.0:5.0:100.0 p = default_params(N=10, M=6) sol = solve_transition_dynamics(p, t) v = solve_bellman(p) plot(t, [dot(sol(tval), v) for tval in t], xlabel = L"t", label = L"E_t(v)")

Lecture 60, function Mtilde_t_density(amf, t; xmin = 1e-8, xmax = 5.0, npts = 5000)

# Pull out the multiplicative decomposition
νtilde, H, g =
    multiplicative_decomp(amf.A, amf.B, amf.D, amf.F, amf.ν)
H2 = H*H

# The distribution
mdist = LogNormal(-t * H2 / 2, sqrt(t * H2))
x = range(xmin,  xmax, length = npts)
p = pdf.(mdist, x)

return x, p

end

function logMtilde_t_density(amf, t; xmin = -15.0, xmax = 15.0, npts = 5000)

# Pull out the multiplicative decomposition
@unpack A, B, D, F, ν = amf
νtilde, H, g = multiplicative_decomp(A, B, D, F, ν)
H2 = H * H

# The distribution
lmdist = Normal(-t * H2 / 2, sqrt(t * H2))
x = range(xmin,  xmax, length = npts)
p = pdf.(lmdist, x)

return x, p

end

times_to_plot = [10, 100, 500, 1000, 2500, 5000] dens_to_plot = [Mtilde_t_density(amf_2, t, xmin=1e-8, xmax=6.0) for t in times_to_plot] ldens_to_plot = [logMtilde_t_density(amf_2, t, xmin=-10.0, xmax=10.0) for t in times_to_plot]

plot_title = "Densities of M_t^tilda" is required, however, plot_title is not yet

supported in Plots

plots = plot(layout = (3,2), size = (600,800))

for (it, dens_t) in enumerate(dens_to_plot) x, pdf = dens_t plot!(plots[it], title = "Density for time (time_to_plot[it])") plot!(plots[it], pdf, fillrange = 0, label = "") end plot(plots)

jlperla commented 1 year ago

@Jonah-Heyl Are you ready to close this issue? If so, I would do so.

Jonah-Heyl commented 1 year ago

Yes, the plots are in a different issue now