jeff-regier / Celeste.jl

Scalable inference for a generative model of astronomical images
MIT License
183 stars 28 forks source link

Can't import Celeste, TypeError: SizedArray: in S, expected S<:Tuple, got Tuple{Int64,Int64} #665

Closed gostevehoward closed 7 years ago

gostevehoward commented 7 years ago

@jeff-regier I can't import Celeste on latest Julia 0.6. I ran Pkg.update(). Error is

ERROR: LoadError: LoadError: LoadError: TypeError: SizedArray: in S, expected S<:Tuple, got Tuple{Int64,Int64}
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:539
 [2] include(::String) at ./sysimg.jl:14
 [3] include_from_node1(::String) at ./loading.jl:539
 [4] include(::String) at ./sysimg.jl:14
 [5] include_from_node1(::String) at ./loading.jl:539
 [6] include(::String) at ./sysimg.jl:14
 [7] anonymous at ./<missing>:2
while loading /home/steve/.julia/v0.6/Celeste/src/bivariate_normals.jl, in expression starting on line 517
while loading /home/steve/.julia/v0.6/Celeste/src/Model.jl, in expression starting on line 54
while loading /home/steve/.julia/v0.6/Celeste/src/Celeste.jl, in expression starting on line 18

Not sure how to debug that. Line 517 doesn't seem to have relevant code. Full log:

11:03 steve@steve-laptop:~/work/Celeste.jl$ git rev-parse HEAD                                                    [0]
e1e845bb3e5d7b4669b34f6aaa5ec41cd620c8fc
11:03 steve@steve-laptop:~/work/Celeste.jl$ git status                                                            [0]
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
11:03 steve@steve-laptop:~/work/Celeste.jl$ julia                                                                 [0]
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0-pre.beta.338 (2017-04-26 15:52 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 8e12b77 (0 days old master)
|__/                   |  x86_64-pc-linux-gnu

julia> Pkg.status()
34 additional packages:
 - BinDeps                       0.4.7
 - Blosc                         0.2.0
 - Calculus                      0.2.2
 - Celeste                       0.3.0+             master
 - Compat                        0.24.0
 - DataArrays                    0.4.0
 - DataFrames                    0.9.1
 - DataStructures                0.5.3
 - DiffBase                      0.1.0
 - Distributions                 0.12.5
 - FITSIO                        0.9.0
 - FileIO                        0.3.1
 - ForwardDiff                   0.4.2
 - GZip                          0.3.0
 - HDF5                          0.8.0
 - JLD                           0.6.10
 - LegacyStrings                 0.2.1
 - LineSearches                  0.1.5
 - NaNMath                       0.2.4
 - Optim                         0.7.8
 - PDMats                        0.6.0
 - PositiveFactorizations        0.0.4
 - QuadGK                        0.1.2
 - Reexport                      0.0.3
 - ReverseDiff                   0.1.2
 - Rmath                         0.1.6
 - SHA                           0.3.2
 - SortingAlgorithms             0.1.1
 - SpecialFunctions              0.1.1
 - StaticArrays                  0.4.0+             master
 - StatsBase                     0.13.1
 - StatsFuns                     0.5.0
 - URIParser                     0.1.8
 - WCS                           0.1.3

julia> Pkg.update()
INFO: Updating METADATA...
INFO: Updating StaticArrays master...
INFO: Updating Celeste master...
INFO: Computing changes...
INFO: No packages to install, update or remove

julia> import Celeste
INFO: Precompiling module Celeste.
ERROR: LoadError: LoadError: LoadError: TypeError: SizedArray: in S, expected S<:Tuple, got Tuple{Int64,Int64}
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:539
 [2] include(::String) at ./sysimg.jl:14
 [3] include_from_node1(::String) at ./loading.jl:539
 [4] include(::String) at ./sysimg.jl:14
 [5] include_from_node1(::String) at ./loading.jl:539
 [6] include(::String) at ./sysimg.jl:14
 [7] anonymous at ./<missing>:2
while loading /home/steve/.julia/v0.6/Celeste/src/bivariate_normals.jl, in expression starting on line 517
while loading /home/steve/.julia/v0.6/Celeste/src/Model.jl, in expression starting on line 54
while loading /home/steve/.julia/v0.6/Celeste/src/Celeste.jl, in expression starting on line 18
ERROR: Failed to precompile Celeste to /home/steve/.julia/lib/v0.6/Celeste.ji.
Stacktrace:
 [1] compilecache(::String) at ./loading.jl:673
 [2] require(::Symbol) at ./loading.jl:460

julia>
Keno commented 7 years ago

With recent versions of StaticArrays, you may have to spell those as SizedArray{Tuple{2,2},... rather than SizedArray{(2,2),..., etc.

gostevehoward commented 7 years ago

Thanks @Keno. There are several weird things going on here.

First, I narrowed the source of the problem down to the six SizedMatrix types in the declaration of BivariateNormalDerivatives.

The master version of bivariate_normals.jl includes declarations in both styles: it has SArray types with the Tuple{1,2,3} form, and it has the above SizedMatrix types with the (1,2,3) form. So it was a bit unclear which version of StaticArrays the code is intended to run against. The REQUIRE file still says 0.1.4, but Jeff said to checkout master several weeks ago. So that's what I have. (Of course I tried running against 0.4.0 and got the predicatable error from the new-style types.)

I tried changing the SizedMatrix types over to the Tuple{1,2,3} form, but got a new error:

[1]<1> ERROR: MethodError: Cannot `convert` an object of type Type{Tuple{2,2}} to an object of type Array{Float64,2}
This may have arisen from a call to the constructor Array{Float64,2}(...),
since type constructors fall back to convert methods.
[1]<1> ERROR: Stack trace:
[1]<1> ERROR:   Type at SizedArray.jl:23 [inlined]
[1]<1> ERROR:   macro expansion at SizedArray.jl:41 [inlined]
[1]<1> ERROR:   Type at SizedArray.jl:35 [inlined]
[1]<1> ERROR:   convert at convert.jl:18 [inlined]
[1]<1> ERROR:   Celeste.PSF.BivariateNormalDerivatives{Float64}() at bivariate_normals.jl:90
[1]<1> ERROR:   (::Celeste.PSF.##call#1#2)(::Bool, ::Float64, ::Float64, ::Type{T} where T, ::Celeste.Transform.DataTransform, ::Int64) at PSF.jl:58
[1]<1> ERROR:   #fit_raw_psf_for_celeste#16 at PSF.jl:679 [inlined]
[1]<1> ERROR:   fit_raw_psf_for_celeste at PSF.jl:677 [inlined]
[1]<1> ERROR:   convert(::Type{Celeste.Model.Image}, ::Celeste.SDSSIO.RawImage) at SDSSIO.jl:278
[1]<1> ERROR:   load_field_images(::Array{Celeste.SDSSIO.RunCamcolField,1}, ::String, ::Bool, ::Bool) at SDSSIO.jl:309
[1]<1> ERROR:   load_field_images(::Array{Celeste.SDSSIO.RunCamcolField,1}, ::String) at SDSSIO.jl:299
[1]<1> ERROR:   include_from_node1(::String) at loading.jl:539
[1]<1> ERROR:   include(::String) at sysimg.jl:14
[1]<1> ERROR:   process_options(::Base.JLOptions) at client.jl:305
[1]<1> ERROR:   _start() at client.jl:371

I suspect this is a bug in StaticArrays, though I lack the context to be sure, but observe:

julia> StaticArrays.SizedMatrix{(2,2), Float64}
ERROR: TypeError: SizedArray: in S, expected S<:Tuple, got Tuple{Int64,Int64}

julia> StaticArrays.SizedMatrix{Tuple{2,2}, Float64}
StaticArrays.SizedArray{Tuple{2,2},Float64,2,M} where M

julia> StaticArrays.SizedMatrix{Tuple{2,2}, Float64}()
ERROR: MethodError: Cannot `convert` an object of type Type{Tuple{2,2}} to an object of type Array{Float64,2}
This may have arisen from a call to the constructor Array{Float64,2}(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] Type at /home/steve/.julia/v0.6/StaticArrays/src/SizedArray.jl:23 [inlined]
 [2] StaticArrays.SizedArray{Tuple{2,2},Float64,2,M} where M() at /home/steve/.julia/v0.6/StaticArrays/src/SizedArray.jl:31

The other weird thing is that, in the original error traceback (in my previous comment), line 517 seems to be spurious. You can truncate bivariate_normals.jl to be less than 500 lines and still get line 517 in the traceback. If you mess around, you can get the traceback to point to a different file (which is less than 500 lines) but still say line 517. So that traceback seems to be somehow corrupted.

Keno commented 7 years ago

StaticArrays was switched over gradually. SArray was first, but I think SizedArray was switched over now as well.

jeff-regier commented 7 years ago

@andymiller is reporting this problem too. Is there a workaround?

gostevehoward commented 7 years ago

In addition to #666, the following patch to StaticArrays master fixed it for me:

diff --git a/src/SizedArray.jl b/src/SizedArray.jl
index 6c0b976..ec7a34d 100644
--- a/src/SizedArray.jl
+++ b/src/SizedArray.jl
@@ -20,7 +20,7 @@ immutable SizedArray{S <: Tuple, T, N, M} <: StaticArray{S, T, N}
     end

     function (::Type{SizedArray{S, T, N, M}}){S, T, N, M}()
-        new{S, T, N, M}(Array{T, M}(S))
+        new{S, T, N, M}(Array{T, M}(S.parameters...))
     end
 end

I submitted a PR to StaticArrays. I have no idea if it's the right fix or what. But it gets Celeste working again.

jeff-regier commented 7 years ago

Thanks for fixing this Steve. @andymiller let us know if you're having trouble still. Celeste master works for me now if I run

Pkg.update()
Pkg.checkout("StaticArrays")
Pkg.build("StaticArrays")
andymiller commented 7 years ago

Works for me --- thanks!