From 0bdbfdaaeb33c1b4a42f2820697dbbbc6dc6953c Mon Sep 17 00:00:00 2001 From: Abhinav Kaushlya Date: Wed, 18 Dec 2019 19:04:32 +0530 Subject: [PATCH] Update to Julia 1.3.0 This updates the Dockerfile to use Julia 1.3.0. Also some changes are made to the mux_server.jl --- Dockerfile | 12 ++-- Project.toml | 12 ++++ api/mux_server.jl | 175 +++++++++++++++++++++++----------------------- 3 files changed, 107 insertions(+), 92 deletions(-) create mode 100644 Project.toml diff --git a/Dockerfile b/Dockerfile index 2bf89d3..3fd4e6e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Start with 0.5.0 which is also latest at the moment -FROM julia:0.5.0 +FROM julia:1.3.0 # Install stuff needed by the HttpParser package RUN apt-get update && apt-get install -y \ @@ -12,9 +12,9 @@ RUN apt-get update && apt-get install -y \ # Make package folder and install everything in require ENV JULIA_PKGDIR=/opt/julia -RUN julia -e "Pkg.init()" -COPY REQUIRE /opt/julia/v0.5/REQUIRE -RUN julia -e "Pkg.resolve()" +RUN julia -e "Pkg.activate()" +COPY Project.toml /opt/julia/v1.3.0/Project.toml +RUN julia -e "Pkg.instantiate()" # Build all the things RUN julia -e 'Pkg.build()' @@ -23,10 +23,10 @@ RUN julia -e 'Pkg.build()' RUN julia -e 'Pkg.build("Plots"); Pkg.build("SymEngine"); Pkg.rm("Conda")' # Clone WebBase -RUN julia -e 'Pkg.clone("https://github.com/JuliaDiffEq/DiffEqWebBase.jl");' +RUN julia -e 'Pkg.add(PackageSpec(url="https://github.com/JuliaDiffEq/DiffEqWebBase.jl", rev="master"));' # Check out master until patches -RUN julia -e 'Pkg.checkout("DiffEqBase"); Pkg.checkout("OrdinaryDiffEq"); Pkg.checkout("StochasticDiffEq"); Pkg.checkout("ParameterizedFunctions");' +RUN julia -e 'Pkg.add(PackageSpec(name="DiffEqBase", rev="master")); Pkg.add(PackageSpec(name="OrdinaryDiffEq", rev="master")); Pkg.add(PackageSpec(name="StochasticDiffEq", rev="master")); Pkg.add(PackageSpec(name="ParameterizedFunctions", rev="master"));' # Force precompile of all modules -- this should greatly improve startup time RUN julia -e 'using DiffEqBase, DiffEqWebBase, OrdinaryDiffEq, StochasticDiffEq, ParameterizedFunctions, Plots, Mux, JSON, HttpCommon' diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..30de8a4 --- /dev/null +++ b/Project.toml @@ -0,0 +1,12 @@ +[deps] +Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" +DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" +DiffEqWebBase = "199ddbe7-5660-5d34-ad45-164698b1b2b3" +HttpCommon = "77172c1b-203f-54ac-aa54-3f1198fe9f90" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +Mux = "a975b10e-0019-58db-a62f-e48ff68538c9" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +ParameterizedFunctions = "65888b18-ceab-5e60-b2b9-181511a3b968" +Plotly = "58dd65bb-95f3-509e-9936-c39a10fdeae7" +PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" +StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" diff --git a/api/mux_server.jl b/api/mux_server.jl index f6b0f86..70a03a1 100644 --- a/api/mux_server.jl +++ b/api/mux_server.jl @@ -1,27 +1,29 @@ -tic() -using DiffEqBase, DiffEqWebBase, OrdinaryDiffEq, StochasticDiffEq, Calculus, ParameterizedFunctions, Plots, Mux, JSON, HttpCommon -include("sanitation.jl") -plotly() - -const algs = Dict{Symbol,DEAlgorithm}( - :Tsit5 => Tsit5(), - :Vern6 => Vern6(), - :Vern7 => Vern7(), - :BS3 => BS3(), - :Rosenbrock23 => Rosenbrock23(), - :SRIW1 => SRIW1(), - :SRA1 => SRA1()) -const opts = Dict{Symbol,Bool}( - :build_tgrad => false, - :build_jac => false, - :build_expjac => false, - :build_invjac => false, - :build_invW => false, - :build_hes => false, - :build_invhes => false, - :build_dpfuncs => false) - -println("Package loading took this long: ", toq()) +time = @elapsed begin + using DiffEqBase, DiffEqWebBase, OrdinaryDiffEq, StochasticDiffEq, Calculus, ParameterizedFunctions, Plots, Mux, JSON, HttpCommon + include("sanitation.jl") + plotly() + + const algs = Dict{Symbol,DEAlgorithm}( + :Tsit5 => Tsit5(), + :Vern6 => Vern6(), + :Vern7 => Vern7(), + :BS3 => BS3(), + :Rosenbrock23 => Rosenbrock23(), + :SRIW1 => SRIW1(), + :SRA1 => SRA1()) + const opts = Dict{Symbol,Bool}( + :build_tgrad => false, + :build_jac => false, + :build_expjac => false, + :build_invjac => false, + :build_invW => false, + :build_hes => false, + :build_invhes => false, + :build_dpfuncs => false) + +end + +println("Package loading took this long: ", time) # Headers -- set Access-Control-Allow-Origin for either dev or prod function withHeaders(res, req) @@ -69,70 +71,71 @@ function solveit(req::Dict{Any,Any}) end function solveit(b64::String) - tic() - - setup_time = @elapsed begin - strObj = String(base64decode(b64)) - obj = JSON.parse(strObj) - title = obj["title"] - println("Title: ", title) - exstr = string("begin\n", obj["diffEqText"], "\nend") - sanitize_string(exstr) - ex = parse(exstr) - # Need a way to make sure the expression only calls "safe" functions here!!! - println("Diff equ: ", ex) - name = Symbol(strObj) - [sanitize_string(p) for p in obj["parameters"]] - params = [parse(p) for p in obj["parameters"]] - println("Params: ", params) - - # Make sure these are always floats - tspan = (Float64(obj["timeSpan"][1]),Float64(obj["timeSpan"][2])) - println("tspan: ", tspan) - u0 = [parse(Float64, u) for u in obj["initialConditions"]] - println("u0: ", u0) - # Also need sanitization here! - sanitize_string(obj["vars"]) - vars = eval(parse(obj["vars"])) - println("vars: ", vars, " type: ", typeof(vars)) - algstr = obj["solver"] #Get this from the reqest in the future! - f = ode_def_opts(name, opts, ex, params...) - - if haskey(obj,"noiseText") - noise_name = Symbol(strObj*"noise") - exstr = string("begin\n", obj["noiseText"], "\nend") + time = @elapsed begin + + setup_time = @elapsed begin + strObj = String(base64decode(b64)) + obj = JSON.parse(strObj) + title = obj["title"] + println("Title: ", title) + exstr = string("begin\n", obj["diffEqText"], "\nend") sanitize_string(exstr) - noise_ex = parse(exstr) - println("Noise equ: ", noise_ex) - [sanitize_string(p) for p in obj["noiseParameters"]] - noise_params = [parse(p) for p in obj["noiseParameters"]] - g = ode_def_opts(noise_name, opts, noise_ex, noise_params...) - prob = QuickSDEProblem{Vector{Float64},Float64,true,:Diagonal,typeof(randn)}(f,g,u0,tspan,DiffEqBase.WHITE_NOISE) - else - prob = QuickODEProblem{Vector{Float64},Float64,true}(f,u0,tspan) - end - alg = algs[parse(algstr)] + ex = parse(exstr) + # Need a way to make sure the expression only calls "safe" functions here!!! + println("Diff equ: ", ex) + name = Symbol(strObj) + [sanitize_string(p) for p in obj["parameters"]] + params = [parse(p) for p in obj["parameters"]] + println("Params: ", params) + + # Make sure these are always floats + tspan = (Float64(obj["timeSpan"][1]),Float64(obj["timeSpan"][2])) + println("tspan: ", tspan) + u0 = [parse(Float64, u) for u in obj["initialConditions"]] + println("u0: ", u0) + # Also need sanitization here! + sanitize_string(obj["vars"]) + vars = eval(parse(obj["vars"])) + println("vars: ", vars, " type: ", typeof(vars)) + algstr = obj["solver"] #Get this from the reqest in the future! + f = ode_def_opts(name, opts, ex, params...) + + if haskey(obj,"noiseText") + noise_name = Symbol(strObj*"noise") + exstr = string("begin\n", obj["noiseText"], "\nend") + sanitize_string(exstr) + noise_ex = parse(exstr) + println("Noise equ: ", noise_ex) + [sanitize_string(p) for p in obj["noiseParameters"]] + noise_params = [parse(p) for p in obj["noiseParameters"]] + g = ode_def_opts(noise_name, opts, noise_ex, noise_params...) + prob = QuickSDEProblem{Vector{Float64},Float64,true,:Diagonal,typeof(randn)}(f,g,u0,tspan,DiffEqBase.WHITE_NOISE) + else + prob = QuickODEProblem{Vector{Float64},Float64,true}(f,u0,tspan) + end + alg = algs[parse(algstr)] + end + println("Setup time: $setup_time") + + length(f.syms) != length(u0) && error("Initial conditions inconsistent with the differential equation. Make sure there is an initial value for every variable.") + (maximum(isinf.(u0)) || maximum(isnan.(u0))) && error("Initial conditions must be finite values") + + maxiters = 1e4 + + solve_time = @elapsed sol = solve(prob,alg,Vector{Vector{Float64}}(),Vector{Float64}(),[],Val{false},maxiters=maxiters) + println("Solve time: $solve_time") + + length(sol)>= .9*maxiters && error("Max iterations reached. The equation may be stiff, blow up to infinity, or you choose too long of a timespan. Try the stiff solver (Rosenbrock23 for ODEs) or make sure that the equation has a valid solution. If you need more computing power/time try DifferentialEquations.jl!") + + plot_time = @elapsed p = plot(sol,vars=vars) + println("Plot time: $plot_time") + + layout = Plots.plotly_layout_json(p) + series = Plots.plotly_series_json(p) + + res = Dict("layout" =>layout, "series"=>series, "title" => title) end - println("Setup time: $setup_time") - - length(f.syms) != length(u0) && error("Initial conditions inconsistent with the differential equation. Make sure there is an initial value for every variable.") - (maximum(isinf.(u0)) || maximum(isnan.(u0))) && error("Initial conditions must be finite values") - - maxiters = 1e4 - - solve_time = @elapsed sol = solve(prob,alg,Vector{Vector{Float64}}(),Vector{Float64}(),[],Val{false},maxiters=maxiters) - println("Solve time: $solve_time") - - length(sol)>= .9*maxiters && error("Max iterations reached. The equation may be stiff, blow up to infinity, or you choose too long of a timespan. Try the stiff solver (Rosenbrock23 for ODEs) or make sure that the equation has a valid solution. If you need more computing power/time try DifferentialEquations.jl!") - - plot_time = @elapsed p = plot(sol,vars=vars) - println("Plot time: $plot_time") - - layout = Plots.plotly_layout_json(p) - series = Plots.plotly_series_json(p) - - res = Dict("layout" =>layout, "series"=>series, "title" => title) - println("Done, took this long: ", toq()) + println("Done, took this long: ", time) return JSON.json(Dict("data" => res, "error" => false)) end