# Saving SDE data using DataFrames.jl naming of columns

**URL:** <https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325>\
**Category:** General Usage\
**Created:** [October 6, 2022, 3:08am UTC](https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325 "2022-10-06T03:08:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Beez](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Beez](https://discourse.julialang.org/u/Max_Beez)\
**Post date:** [October 6, 2022, 3:08am UTC](https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325/1 "2022-10-06T03:08:16Z")

</div>

I am simulating an SDE using DifferentialEquations.jl and I am using DataFrames.jl to save the solution data.

I get a data frame with columns named timestamp, value1, value2 and value3.

I would like to use SDEFunction to be able to use the kwarg syms to able to name the elements rather than have value1, value2 and value3.

Further information is found here : [SDE Problems](https://diffeq.sciml.ai/stable/types/sde_types/#SciMLBase.SDEFunction)

> - `syms`: the symbol names for the elements of the equation. This should match `u0` in size. For example, if `u0 = [0.0,1.0]` and `syms = [:x, :y]`, this will apply a canonical naming to the values, allowing `sol[:x]` in the solution and automatically naming values in plots.

And here [Saving and Loading Solution Data](https://diffeq.sciml.ai/stable/features/io/)

> If we set syms in the DiffEqFunction, then those names will be used:

> f = ODEFunction(f\_2dlinear,syms=[:a,:b,:c,:d])  
> prob = ODEProblem(f,rand(2,2),(0.0,1.0));  
> sol1 =solve(prob,Euler();dt=1//2^(4));  
> df = DataFrame(sol1)

However I when I try using SDEFunction and try passing any information such as my function f (and g) it doesn’t work. Namely, as instructed I try passing

> `!(du,u,p,t)` or `du = f(u,p,t)`

it returns an error. For instance, passing

> du = f(u,p,t)

will give the following

> ERROR: UndefVarError: u not defined

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 6, 2022, 5:58am UTC](https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325/2 "2022-10-06T05:58:35Z")

</div>

> [@Max\_Beez](#):
>
> Namely, as instructed I try passing
> 
> > `!(du,u,p,t)` or `du = f(u,p,t)`
> 
> it returns an error. For instance, passing
> 
> > du = f(u,p,t)
> 
> will give the following

I don’t understand what you actually did. Show me an MWE. It’s really nothing more than `f = SDEFunction(f,g,syms=[:a,:b,:c,:d])`

---

<div class="post-metadata">

**Author:** ![Max\_Beez](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Beez](https://discourse.julialang.org/u/Max_Beez)\
**Post date:** [October 6, 2022, 4:03pm UTC](https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325/3 "2022-10-06T16:03:25Z")

</div>

Here is a MWE (without using SDEFunction)

> using DifferentialEquations, DataFrames, Plots  
> u0 = [1.2]  
> function f(du,u,p,t)  
> du[1] = 0.1\*sin(u[1])  
> end  
> function g(du,u,p,t)  
> du[1] = 1.2  
> end  
> prob = SDEProblem(f,g,u0,(0.0,1.0))  
> sol = solve(prob, dt=0.01, EM())  
> df = Dataframe(sol)  
> @show df  
> Plots.plot(sol)

Now if I were to use SDEFunction method, what should I put?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 6, 2022, 4:44pm UTC](https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325/4 "2022-10-06T16:44:43Z")

</div>

> [@Max\_Beez](#):
>
> prob = SDEProblem(f,g,u0,(0.0,1.0))

`prob = SDEProblem(SDEFunction(f,g),u0,(0.0,1.0))`

---

<div class="post-metadata">

**Author:** ![Max\_Beez](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Beez](https://discourse.julialang.org/u/Max_Beez)\
**Post date:** [October 6, 2022, 5:56pm UTC](https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325/5 "2022-10-06T17:56:54Z")

</div>

I copy and pasted

> prob = SDEProblem(SDEFunction(f,g),u0,(0.0,1.0))

Now I have

> using DifferentialEquations,DataFrames, Plots  
> u0 = [1.2]  
> function f(du,u,p,t)  
> du[1] = 0.1\*sin(u[1])  
> end  
> function g(du,u,p,t)  
> du[1] = 1.2  
> end  
> prob = SDEProblem(SDEFunction(f,g),u0,(0.0,1.0))  
> sol = solve(prob, dt=0.01, EM())  
> df = DataFrame(sol)  
> @show df  
> Plots.plot(sol)

Upon running I get

> ERROR: MethodError: no method matching SDEProblem(::SDEFunction{true, typeof(f), typeof(g), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, ::Vector{Float64}, ::Tuple{Float64, Float64})  
> Closest candidates are:  
> SDEProblem(::SciMLBase.AbstractSDEFunction, ::Any, ::Any, ::Any) at ~/.julia/packages/SciMLBase/IJbT7/src/problems/sde\_problems.jl:124  
> SDEProblem(::SciMLBase.AbstractSDEFunction, ::Any, ::Any, ::Any, ::Any; kwargs…) at ~/.julia/packages/SciMLBase/IJbT7/src/problems/sde\_problems.jl:124  
> SDEProblem(::Any, ::Any, ::Any, ::Any) at ~/.julia/packages/SciMLBase/IJbT7/src/problems/sde\_problems.jl:128  
> …  
> Stacktrace:  
> [1] top-level scope  
> @ ~/Param/MWE.jl:9

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 6, 2022, 8:45pm UTC](https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325/6 "2022-10-06T20:45:57Z")

</div>

> [@Max\_Beez](#):
>
> prob = SDEProblem(SDEFunction(f,g),u0,(0.0,1.0))

Oh oops `prob = SDEProblem(SDEFunction(f,g),g,u0,(0.0,1.0))` it’s a bit odd that it needs the two but it does. See:

[https://diffeq.sciml.ai/stable/types/sde\_types/#SciMLBase.SDEProblem](https://diffeq.sciml.ai/stable/types/sde_types/#SciMLBase.SDEProblem)

---

<div class="post-metadata">

**Author:** ![Max\_Beez](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Beez](https://discourse.julialang.org/u/Max_Beez)\
**Post date:** [October 6, 2022, 8:52pm UTC](https://discourse.julialang.org/t/saving-sde-data-using-dataframes-jl-naming-of-columns/88325/7 "2022-10-06T20:52:48Z")

</div>

Ah, okay got it, bit odd indeed. Thanks for the help.
