# Clear variable?

**URL:** <https://discourse.julialang.org/t/clear-variable/39592>\
**Category:** New to Julia\
**Tags:** turing\
**Created:** [May 16, 2020, 4:34pm UTC](https://discourse.julialang.org/t/clear-variable/39592 "2020-05-16T16:34:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manoj\_Gopalkrishnan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj_gopalkrishnan/32/14587_2.png) [@Manoj\_Gopalkrishnan](https://discourse.julialang.org/u/Manoj_Gopalkrishnan)\
**Post date:** [May 16, 2020, 4:34pm UTC](https://discourse.julialang.org/t/clear-variable/39592/1 "2020-05-16T16:34:39Z")

</div>

I am trying to sample a Turing model with this Gibbs sampler:

```julia
sampler = Gibbs(PG(200, :toss), NUTS(.65, :a, :b, :θ, :σ, :μ, :temp))

```

Unfortunately, while making sure some of my code was correct, I have set a, b, \mu to some values. When I try to run this line of code, I get the error

```julia
MethodError: Cannot `convert` an object of type Float64 to an object of type Symbol

```

I tried setting these variables to the keyword nothing. But that didn’t help. I tried clear!(:a) but that is throwing up an error.

I’m on Julia 1.4.1. Please help, am I reading this error correctly? How do I fix it, short of closing my workspace and starting the kernel again?

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [May 16, 2020, 5:57pm UTC](https://discourse.julialang.org/t/clear-variable/39592/2 "2020-05-16T17:57:35Z")

</div>

I don’t think the issue is what you think (though I haven’t used Turing much, so not 100% sure). Here’s where I usually see such an error:

```julia
julia> a = [:a, :b]
2-element Array{Symbol,1}:
 :a
 :b

julia> push!(a, 1.)
ERROR: MethodError: Cannot `convert` an object of type Float64 to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:167
  Symbol(::Any...) at strings/basic.jl:206

```

Because the Vector is of Symbols, and Julia won’t implicity convert a Float to a symbol. I don’t know enough about the functions there to know which might be causing the problem, but you can probably dig into the stack trace and figure it out.

Note: is usually helpful to answering questions if you can include a minimal example of code that causes the error and the entire stack trace. [See here](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) for more tips

---

<div class="post-metadata">

**Author:** ![Manoj\_Gopalkrishnan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj_gopalkrishnan/32/14587_2.png) [@Manoj\_Gopalkrishnan](https://discourse.julialang.org/u/Manoj_Gopalkrishnan)\
**Post date:** [May 30, 2020, 12:54pm UTC](https://discourse.julialang.org/t/clear-variable/39592/3 "2020-05-30T12:54:16Z")

</div>

Here is a MWE

```julia
g=Gibbs(NUTS(:u),PG(20, :s))

```

This single line throws the error

```julia
MethodError: no method matching iterate(::Symbol)
Closest candidates are:
  iterate(!Matched::Core.SimpleVector) at essentials.jl:603
  iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:603
  iterate(!Matched::ExponentialBackOff) at error.jl:253
  ...

Stacktrace:
 [1] indexed_iterate(::Symbol, ::Int64) at .\tuple.jl:84
 [2] merge(::NamedTuple{(),Tuple{}}, ::Tuple{Symbol}) at .\namedtuple.jl:255
 [3] NUTS{Turing.Core.ForwardDiffAD{40},space,metricT} where metricT<:AdvancedHMC.AbstractMetric where space(::Symbol) at C:\Users\Manoj\.julia\packages\Turing\GMBTf\src\inference\hmc.jl:359
 [4] NUTS(::Symbol; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\Manoj\.julia\packages\Turing\GMBTf\src\inference\hmc.jl:313
 [5] NUTS(::Symbol) at C:\Users\Manoj\.julia\packages\Turing\GMBTf\src\inference\hmc.jl:313
 [6] top-level scope at In[113]:1

```

If I change to

```julia
g=Gibbs(NUTS(.65,:u),PG(20, :s))

```

I get the error

```julia
MethodError: Cannot `convert` an object of type Float64 to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, !Matched::T) where T at essentials.jl:171
  Symbol(::Any...) at strings/basic.jl:207

Stacktrace:
 [1] merge(::NamedTuple{(),Tuple{}}, ::Tuple{Float64,Symbol}) at .\namedtuple.jl:255
 [2] NUTS{Turing.Core.ForwardDiffAD{40},space,metricT} where metricT<:AdvancedHMC.AbstractMetric where space(::Float64, ::Vararg{Any,N} where N) at C:\Users\Manoj\.julia\packages\Turing\GMBTf\src\inference\hmc.jl:359
 [3] NUTS(::Float64, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\Manoj\.julia\packages\Turing\GMBTf\src\inference\hmc.jl:313
 [4] NUTS(::Float64, ::Vararg{Any,N} where N) at C:\Users\Manoj\.julia\packages\Turing\GMBTf\src\inference\hmc.jl:313
 [5] top-level scope at In[114]:1

```

Finally if I change to

```julia
g=Gibbs(NUTS(1000,.65,:u),PG(20, :s))

```

it doesn’t give an error.

Can someone explain to me why I need to explicitly give the parameters to NUTS here? I can get away in sample() with giving NUTS only one parameter. The documentation says I can give no parameters, and it will pick up default values. Also what does the parameter

```julia
n_adapts::Int : The number of samples to use with adaptation.

```

mean? Where can I read about this and understand what I’m setting?

---

<div class="post-metadata">

**Author:** ![trappmartin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trappmartin/32/1165_2.png) [@trappmartin](https://discourse.julialang.org/u/trappmartin)\
**Post date:** [May 30, 2020, 1:07pm UTC](https://discourse.julialang.org/t/clear-variable/39592/4 "2020-05-30T13:07:31Z")

</div>

That is a bug. Looks like we didn’t implement the constructors for: `NUTS(.65,:u)` and `NUTS(:u)`.

I’ll open a PR for this.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [May 30, 2020, 3:39pm UTC](https://discourse.julialang.org/t/clear-variable/39592/5 "2020-05-30T15:39:41Z")

</div>

`NUTS` is not a valid Gibbs component. Use `HMC`.
