diff --git a/Project.toml b/Project.toml index b807120..8a2df7e 100644 --- a/Project.toml +++ b/Project.toml @@ -26,7 +26,7 @@ ForwardDiff = "0.10" JLD2 = "0.4" LinearAlgebra = "1.7" ModelBaseEcon = "0.6" -Pardiso = "0.5.4" +Pardiso = "0.5" Printf = "1.7" Random = "1.7" SparseArrays = "1.7" diff --git a/test/runtests.jl b/test/runtests.jl index 5134d2f..e92aff7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -153,24 +153,24 @@ end compare_plans(io, p, r; alphabetical=true) seek(io, 0) @test read(io, String) == "\nRange left: 0U:10U\nRange right: 7U:15U\nVariables only in left plan: [:b]\nVariables only in right plan: [:beta]\n4 common variables.\n(X) = Exogenous, (~) = Endogenous, (.) = Missing:\n NAME 0U:1U 2U:3U 4U:4U 5U:6U 7U:8U 9U:9U 10U:10U 11U:13U 14U:15U\n a ~ . X . ~ . ~ . ~ ~ ~ ~ ~ ~ . ~ . ~ \n as X . ~ . X . X . X X X X X X . X . X \n b ~ . X . ~ . X . X . ~ . ~ . . . . . \n beta . . . . . . . . . ~ . ~ . X . X . ~ \n bs X . ~ . X . ~ . ~ X X X X X . X . X \n c ~ . ~ . ~ . ~ . ~ ~ ~ ~ ~ ~ . ~ . ~ \n" - + # print only rows with differences io = IOBuffer() compare_plans(io, p, r; alphabetical=true, diff=true) seek(io, 0) @test read(io, String) == "\nRange left: 0U:10U\nRange right: 7U:15U\nVariables only in left plan: [:b]\nVariables only in right plan: [:beta]\n4 common variables.\n(X) = Exogenous, (~) = Endogenous, (.) = Missing:\n NAME 0U:1U 2U:3U 4U:4U 5U:6U 7U:8U 9U:9U 10U:10U 11U:13U 14U:15U\n b ~ . X . ~ . X . X . ~ . ~ . . . . . \n beta . . . . . . . . . ~ . ~ . X . X . ~ \n bs X . ~ . X . ~ . ~ X X X X X . X . X \n" - + # print summary in REPL out = @capture_out compare_plans(p, r; summary=true) @test out == "Range left: 0U:10U\nRange right: 7U:15U\nVariables only in left plan: [:b]\nVariables only in right plan: [:beta]\n4 common variables.\n:bs differs between the plans for the range(s) 7U:8U.\n" - + # return MVTSeries out_mvts = compare_plans(p, r) - @test out_mvts == MVTSeries(7U, (:a,:c,:as,:bs), [0 0 0 0 ; 0 0 0 0 ; 3 3 3 3 ; 2 2 3 3]') + @test out_mvts == MVTSeries(7U, (:a, :c, :as, :bs), [0 0 0 0; 0 0 0 0; 3 3 3 3; 2 2 3 3]') # return MVTSeries out_mvts2 = compare_plans(r, p) - @test out_mvts2 == MVTSeries(7U, (:a,:c,:as,:bs), [0 0 0 0 ; 0 0 0 0 ; 3 3 3 3 ; 1 1 3 3]') + @test out_mvts2 == MVTSeries(7U, (:a, :c, :as, :bs), [0 0 0 0; 0 0 0 0; 3 3 3 3; 1 1 3 3]') end # copyto! @@ -185,18 +185,18 @@ end copyto!(p_copy, r) @test p_copy.range == p.range @test p_copy.varshks == p.varshks - @test p_copy.exogenous == BitArray([ - 0 0 0 1 1; - 0 0 0 1 1; - 1 1 0 0 0; - 1 1 0 0 0; - 0 0 0 1 1; - 0 1 0 1 0; - 0 1 0 1 0; - 0 1 0 1 1; - 0 1 0 1 1; - 0 0 0 1 1; - 0 0 0 1 1; + @test p_copy.exogenous == BitArray([ + 0 0 0 1 1 + 0 0 0 1 1 + 1 1 0 0 0 + 1 1 0 0 0 + 0 0 0 1 1 + 0 1 0 1 0 + 0 1 0 1 0 + 0 1 0 1 1 + 0 1 0 1 1 + 0 0 0 1 1 + 0 0 0 1 1 ]) # When plans don't overlap, no changes are made @@ -227,21 +227,21 @@ end end @testset "copyto! plans" begin - ma = Model(); - @variables ma x a b c; - md = Model(); - @variables md b c d z; + ma = Model() + @variables ma x a b c + md = Model() + @variables md b c d z p1 = Plan(ma, 2020Q1:2021Q4) copyto!(p1.exogenous, rand(Bool, size(p1.exogenous))) n1, n2 = size(p1.exogenous) - + # same everythig p2 = Plan(ma, 2020Q1:2021Q4) @test @test_nowarn (copyto!(p2, p1); true) @test p1 == p2 - + # update sub-range p2 = Plan(ma, 2019Q1:2023Q4) @test @test_logs (:warn, "Ranges not updated in destination plan: 2019Q1:2019Q4, 2022Q1:2023Q4") (copyto!(p2, p1; verbose=true); true) @@ -255,25 +255,25 @@ end p2 = Plan(ma, 2019Q1:2020Q4) @test @test_nowarn (copyto!(p2, p1); true) @test p1[2020Q1:2020Q4] == p2[2020Q1:2020Q4] - @test p2[2019Q1:2019Q4].exogenous == falses(4,n2) - + @test p2[2019Q1:2019Q4].exogenous == falses(4, n2) + # rng given p2 = Plan(ma, 2019Q1:2020Q4) @test @test_nowarn (copyto!(p2, 2020Q3, p1); true) @test p1[2020Q3:2020Q3] == p2[2020Q3:2020Q3] - @test p2[2019Q1:2020Q2].exogenous == falses(6,n2) - @test p2[2020Q4:2020Q4].exogenous == falses(1,n2) - + @test p2[2019Q1:2020Q2].exogenous == falses(6, n2) + @test p2[2020Q4:2020Q4].exogenous == falses(1, n2) + @test @test_nowarn (copyto!(p2, 2020Q1:2020Q3, p1); true) @test p1[2020Q1:2020Q3] == p2[2020Q1:2020Q3] - @test p2[2019Q1:2019Q4].exogenous == falses(4,n2) - @test p2[2020Q4:2020Q4].exogenous == falses(1,n2) - + @test p2[2019Q1:2019Q4].exogenous == falses(4, n2) + @test p2[2020Q4:2020Q4].exogenous == falses(1, n2) + # given bad p2 = Plan(ma, 2019Q1:2020Q4) @test_throws BoundsError copyto!(p2, 2019Q2:2020Q3, p1) - @test p2.exogenous == falses(8,n2) - + @test p2.exogenous == falses(8, n2) + # Empty range intersection p2 = Plan(ma, 2018Q1:2019Q4) @test @test_nowarn (copyto!(p2, p1); true) @@ -283,14 +283,14 @@ end # different plans p3 = Plan(md, rangeof(p1)) @test @test_nowarn (copyto!(p3, p1); true) - @test p3.exogenous[:,1:2] == p1.exogenous[:,3:4] - @test p3.exogenous[:,3:4] == falses(8,2) + @test p3.exogenous[:, 1:2] == p1.exogenous[:, 3:4] + @test p3.exogenous[:, 3:4] == falses(8, 2) @test @test_logs( (:warn, r"Ignored source plan variables \(missing in destination plan\): (a, x|x, a)"), (:warn, r"Variables not updated in destination plan \(missing in source plan\): (d, z|z, d)"), (copyto!(p3, p1; verbose=true); true) ) - + end include("simdatatests.jl") @@ -378,16 +378,20 @@ include("misc.jl") end end -# make sure Pardiso runs deterministic (single thread) for the tests -Pardiso.set_nprocs_mkl!(1) - for sfdef = QuoteNode.(StateSpaceEcon.StackedTimeSolver.sf_libs) sfdef.value == :default && continue sfdef.value == :none && continue - # Pardiso in macos is giving "Not enough memory". Disable for now - # sfdef.value == :pardiso && Sys.isapple() && continue + if sfdef.value == :pardiso + # Pardiso in macos doesn't work. Disable for now + if Sys.isapple() + @info "Skip :pardiso on apple" + continue + end + # make sure Pardiso runs deterministic (single thread) for the tests + Pardiso.set_nprocs_mkl!(1) + end @info "Using $(sfdef)"