chakravala / Grassmann.jl

⟨Grassmann-Clifford-Hodge⟩ multilinear differential geometric algebra

Home Page:https://grassmann.crucialflow.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"vectorfield" example from readme does not work

eschnett opened this issue · comments

The readme contains this example

using Grassmann, Makie; @basis S"∞+++"
streamplot(vectorfield(exp((π/4)*(v12+v∞3)),V(2,3,4),V(1,2,3)),-1.5..1.5,-1.5..1.5,-1.5..1.5,gridsize=(10,10))

With just the statements above, vectorfield is undefined. If I also ] add GeometryTypes and using GeometryTypes, then vectorfield is found, but I'm then stuck at the next error:

julia> streamplot(vectorfield(exp((π/4)*(v12+v∞3)),V(2,3,4),V(1,2,3)),-1.5..1.5,-1.5..1.5,-1.5..1.5,gridsize=(10,10))
ERROR: MethodError: no method matching ptype(::GeometryBasics.Point{3,Float64})
Closest candidates are:
  ptype(::GeometryTypes.Point{N,T} where N) where T at /Users/eschnett/.julia/packages/Grassmann/9buUZ/src/Grassmann.jl:307
Stacktrace:
 [1] (::Grassmann.var"#707#709"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}})(::GeometryBasics.Point{3,Float64}) at /Users/eschnett/.julia/packages/Grassmann/9buUZ/src/Grassmann.jl:310
 [2] (::AbstractPlotting.var"#apply_f#505"{Grassmann.var"#707#709"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}})(::GeometryBasics.Point{3,Float64}, ::Type{T} where T) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1061
 [3] streamplot_impl(::Type{T} where T, ::Grassmann.var"#707#709"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}, ::GeometryBasics.HyperRectangle{3,Float32}, ::Tuple{Int64,Int64}, ::Float64, ::Int64, ::Float64) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1081
 [4] (::AbstractPlotting.var"#508#512")(::Function, ::GeometryBasics.HyperRectangle{3,Float32}, ::Tuple{Int64,Int64}, ::Float64, ::Int64, ::Float64) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1138
 [5] lift(::Function, ::Observables.Observable{Grassmann.var"#707#709"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}}, ::Observables.Observable{GeometryBasics.HyperRectangle{3,Float32}}, ::Vararg{Any,N} where N) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interaction/nodes.jl:8
 [6] plot!(::StreamPlot{...}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1132
 [7] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Tuple{Observables.Observable{Grassmann.var"#707#709"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}}}, ::Observables.Observable{Tuple{Grassmann.var"#707#709"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}},GeometryBasics.HyperRectangle{3,Float32}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:633
 [8] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Function, ::Vararg{Any,N} where N; kw_attributes::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:563
 [9] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Function, ::IntervalSets.Interval{:closed,:closed,Float64}, ::IntervalSets.Interval{:closed,:closed,Float64}, ::Vararg{IntervalSets.Interval{:closed,:closed,Float64},N} where N) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:532
 [10] streamplot(::Function, ::Vararg{Any,N} where N; attributes::Base.Iterators.Pairs{Symbol,Tuple{Int64,Int64},Tuple{Symbol},NamedTuple{(:gridsize,),Tuple{Tuple{Int64,Int64}}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/recipes.jl:15
 [11] top-level scope at REPL[8]:1
 [12] eval(::Module, ::Any) at ./boot.jl:331
 [13] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/eschnett/src/julia-1.4/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [14] run_backend(::REPL.REPLBackend) at /Users/eschnett/.julia/packages/Revise/C272c/src/Revise.jl:1075
 [15] top-level scope at none:0

This is with

julia> versioninfo()
Julia Version 1.4.2-pre.0
Commit ef4fe83698* (2020-04-15 16:24 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.3.0)
  CPU: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)

on MacOS.

It works on my system, can you do pkg> st Makie to see what version you are using

It looks like you have GeometryBasics.Point instead of GeomtryTypes.Point hmmm

Alright, looks like you have GeometryBasics instead of GeometryTypes for Makie.

Now I added support for both GeometryBasics and GeometryTypes, let me know if you test it.

I have

(GrassmannPlayground) pkg> status Makie
Project GrassmannPlayground v0.1.0
Status `~/src/jl/GrassmannPlayground/Project.toml`
  [ee78f7c6] Makie v0.10.0

The new ] add Grassmann#master has a different error message:

julia> streamplot(vectorfield(exp((π/4)*(v12+v∞3)),V(2,3,4),V(1,2,3)),-1.5..1.5,-1.5..1.5,-1.5..1.5,gridsize=(10,10))
ERROR: Function passed to streamplot must return Point2 or Point3
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] streamplot_impl(::Type{T} where T, ::Grassmann.var"#712#713"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}, ::GeometryBasics.HyperRectangle{3,Float32}, ::Tuple{Int64,Int64}, ::Float64, ::Int64, ::Float64) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1083
 [3] (::AbstractPlotting.var"#508#512")(::Function, ::GeometryBasics.HyperRectangle{3,Float32}, ::Tuple{Int64,Int64}, ::Float64, ::Int64, ::Float64) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1138
 [4] lift(::Function, ::Observables.Observable{Grassmann.var"#712#713"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}}, ::Observables.Observable{GeometryBasics.HyperRectangle{3,Float32}}, ::Vararg{Any,N} where N) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interaction/nodes.jl:8
 [5] plot!(::StreamPlot{...}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1132
 [6] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Tuple{Observables.Observable{Grassmann.var"#712#713"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}}}, ::Observables.Observable{Tuple{Grassmann.var"#712#713"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}},GeometryBasics.HyperRectangle{3,Float32}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:633
 [7] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Function, ::Vararg{Any,N} where N; kw_attributes::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:563
 [8] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Function, ::IntervalSets.Interval{:closed,:closed,Float64}, ::IntervalSets.Interval{:closed,:closed,Float64}, ::Vararg{IntervalSets.Interval{:closed,:closed,Float64},N} where N) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:532
 [9] streamplot(::Function, ::Vararg{Any,N} where N; attributes::Base.Iterators.Pairs{Symbol,Tuple{Int64,Int64},Tuple{Symbol},NamedTuple{(:gridsize,),Tuple{Tuple{Int64,Int64}}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/recipes.jl:15
 [10] top-level scope at REPL[3]:1
 [11] eval(::Module, ::Any) at ./boot.jl:331
 [12] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/eschnett/src/julia-1.4/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [13] run_backend(::REPL.REPLBackend) at /Users/eschnett/.julia/packages/Revise/C272c/src/Revise.jl:1075
 [14] top-level scope at none:0

I'm not sure how or why you have GeometryBasics instead of GeometryTypes so I can't really help debug that any further at the moment, you seem to have a different Makie configuration.

Sounds like the vectorfield method defined for GeometryBasics needs to return Point3.

Let me know if you debug it yourself, shouldn't be too difficult.

I looked at it, and changed the constructor to GeometryBasics.Point3, but this leads to an error I don't understand:

julia> streamplot(vectorfield(exp((π/4)*(v12+v∞3)),V(2,3,4),V(1,2,3)),-1.5..1.5,-1.5..1.5,-1.5..1.5,gridsize=(10,10))
ERROR: MethodError: no method matching Float32(::Chain{⟨_+++⟩,1,Float64,3})
Closest candidates are:
  Float32(::T) where T<:Number at boot.jl:715
  Float32(::Int8) at float.jl:60
  Float32(::Int16) at float.jl:60
  ...
Stacktrace:
 [1] convert(::Type{Float32}, ::Chain{⟨_+++⟩,1,Float64,3}) at ./number.jl:7
 [2] macro expansion at /Users/eschnett/.julia/packages/StaticArrays/1g9bq/src/util.jl:11 [inlined]
 [3] convert_ntuple at /Users/eschnett/.julia/packages/StaticArrays/1g9bq/src/util.jl:8 [inlined]
 [4] Vec{3,Float32}(::Tuple{Chain{⟨_+++⟩,1,Float64,3},Chain{⟨_+++⟩,1,Float64,3},Chain{⟨_+++⟩,1,Float64,3}}) at /Users/eschnett/.julia/packages/GeometryBasics/x7LIA/src/fixed_arrays.jl:19
 [5] convert at /Users/eschnett/.julia/packages/StaticArrays/1g9bq/src/convert.jl:10 [inlined]
 [6] push!(::Array{Vec{3,Float32},1}, ::Point{3,Chain{⟨_+++⟩,1,Float64,3}}) at ./array.jl:913
 [7] streamplot_impl(::Type{T} where T, ::Grassmann.var"#700#701"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}, ::GeometryBasics.HyperRectangle{3,Float32}, ::Tuple{Int64,Int64}, ::Float64, ::Int64, ::Float64) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1087
 [8] (::AbstractPlotting.var"#508#512")(::Function, ::GeometryBasics.HyperRectangle{3,Float32}, ::Tuple{Int64,Int64}, ::Float64, ::Int64, ::Float64) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1138
 [9] lift(::Function, ::Observables.Observable{Grassmann.var"#700#701"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}}, ::Observables.Observable{GeometryBasics.HyperRectangle{3,Float32}}, ::Vararg{Any,N} where N) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interaction/nodes.jl:8
 [10] plot!(::StreamPlot{...}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/basic_recipes/basic_recipes.jl:1132
 [11] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Tuple{Observables.Observable{Grassmann.var"#700#701"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}},Observables.Observable{IntervalSets.Interval{:closed,:closed,Float64}}}, ::Observables.Observable{Tuple{Grassmann.var"#700#701"{MultiVector{⟨∞+++⟩,Float64,16},SubManifold{⟨∞+++⟩,3,0x000000000000000e},SubManifold{⟨∞+++⟩,3,0x0000000000000007}},GeometryBasics.HyperRectangle{3,Float32}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:633
 [12] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Function, ::Vararg{Any,N} where N; kw_attributes::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:563
 [13] plot!(::Scene, ::Type{StreamPlot{...}}, ::Attributes, ::Function, ::IntervalSets.Interval{:closed,:closed,Float64}, ::IntervalSets.Interval{:closed,:closed,Float64}, ::Vararg{IntervalSets.Interval{:closed,:closed,Float64},N} where N) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/interfaces.jl:532
 [14] streamplot(::Function, ::Vararg{Any,N} where N; attributes::Base.Iterators.Pairs{Symbol,Tuple{Int64,Int64},Tuple{Symbol},NamedTuple{(:gridsize,),Tuple{Tuple{Int64,Int64}}}}) at /Users/eschnett/.julia/packages/AbstractPlotting/7mERO/src/recipes.jl:15
 [15] top-level scope at REPL[12]:1
 [16] eval(::Module, ::Any) at ./boot.jl:331
 [17] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/eschnett/src/julia-1.4/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [18] run_backend(::REPL.REPLBackend) at /Users/eschnett/.julia/packages/Revise/C272c/src/Revise.jl:1075
 [19] top-level scope at none:0

Apart from the Float32/Float64 mismatch, I don't know how to convert a Chain to a scalar value, or whether this even makes sense. Maybe things went wrong a long time before that.

If you look at the compatibility code in src/Grassmann.jl you'll find

GeometryBasics.Point(t::T) where T<:TensorAlgebra = convert(GeometryBasics.Point,t)

Is the method I use to convert a TensorAlgebra element to Point, in order to make this work it will also be necessary to make a similar method for the Point3 type instead.

The master branch works as-is if I have GeometryBasics added as requirement, and NOT have GeometryTypes added.

@eschnett GeometryBasics has now been made the default

Looks like I was stuck on an older version of Makie previously.