# Saving a VPTree with JLD

**URL:** <https://discourse.julialang.org/t/saving-a-vptree-with-jld/45425>\
**Category:** Data\
**Created:** [August 23, 2020, 5:52pm UTC](https://discourse.julialang.org/t/saving-a-vptree-with-jld/45425 "2020-08-23T17:52:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [August 23, 2020, 5:52pm UTC](https://discourse.julialang.org/t/saving-a-vptree-with-jld/45425/1 "2020-08-23T17:52:34Z")

</div>

I have some code that builds a number of `VPTree`s via VPTrees.jl and the building of these trees takes a long time. I’d like to be able to simply load a pre-built tree into a new session rather than having to re-build the trees each time I close/start a session. Here’s a MWE with JLD.jl and the error message I get:

```julia
using JLD
using StringDistances
using VPTrees

metric = (a, b) -> evaluate(Levenshtein(), a, b)
tree = VPTree(["Larry", "Moe", "Curly"], metric)

jldopen("tmp/test.jld", "w") do file
    addrequire(file, VPTrees)
    write(file, "tree", tree)
end

```

And the error:

```julia
ERROR: UndefVarError: isgeneric not defined
Stacktrace:
 [1] func2expr(::Function) at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:855
 [2] JLD.AnonymousFunctionSerializer(::Function) at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:862
 [3] writeas(::Function) at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:865
 [4] write_ref(::JLD.JldFile, ::Function, ::JLD.JldWriteSession) at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:668
 [5] macro expansion at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\jld_types.jl:639 [inlined]
 [6] h5convert!(::Ptr{UInt8}, ::JLD.JldFile, ::VPTree{String,Int64}, ::JLD.JldWriteSession) at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\jld_types.jl:654
 [7] write_compound(::JLD.JldFile, ::String, ::VPTree{String,Int64}, ::JLD.JldWriteSession; kargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:710
 [8] write_compound at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:704 [inlined]
 [9] #_write#23 at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:700 [inlined]
 [10] _write at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:700 [inlined]
 [11] #write#17 at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:524 [inlined]
 [12] write at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:524 [inlined] (repeats 2 times)
 [13] (::var"#118#119")(::JLD.JldFile) at .\REPL[166]:4
 [14] jldopen(::var"#118#119", ::String, ::Vararg{String,N} where N; kws::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:243
 [15] jldopen(::Function, ::String, ::String) at C:\Users\mthel\.julia\packages\JLD\jeGJb\src\JLD.jl:241
 [16] top-level scope at REPL[166]:1
 [17] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1088

```

Does someone know how to do this? Thanks!!
