Git Product home page Git Product logo

physicalparticles.jl's People

Contributors

elehcim avatar github-actions[bot] avatar islent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

elehcim

physicalparticles.jl's Issues

Pretty-printing of particles

Arrays of physical particles are quite complex:

julia> [SPHGas() for i=1:3]
3-element Array{SPHGas{Float64,Int64},1}:
 SPHGas{Float64,Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(kpc,),𝐋,nothing}}}(0.0 kpc, 0.0 kpc, 0.0 kpc), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(Gyr^-1, kpc),𝐋*𝐓^-1,nothing}}}(0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1), PVector{Quantity{Float64,𝐋*𝐓^-2,Unitful.FreeUnits{(Gyr^-2, kpc),𝐋*𝐓^-2,nothing}}}(0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2), 0.0 MβŠ™, 0, 0, 0, 0.0, 0.0 J, 0.0 kpc Gyr^-2, 0.0 J K^-1, 0.0 MβŠ™ kpc^-3, 0.0 kpc, 0.0, 0.0, 0, PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(Gyr^-1, kpc),𝐋*𝐓^-1,nothing}}}(0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1), 0.0 Gyr^-1, 0.0 Gyr^-1, 0.0, 0.0 N m^-1, 0.0 J K^-1 s^-1, 0.0 kpc Gyr^-1)
 SPHGas{Float64,Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(kpc,),𝐋,nothing}}}(0.0 kpc, 0.0 kpc, 0.0 kpc), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(Gyr^-1, kpc),𝐋*𝐓^-1,nothing}}}(0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1), PVector{Quantity{Float64,𝐋*𝐓^-2,Unitful.FreeUnits{(Gyr^-2, kpc),𝐋*𝐓^-2,nothing}}}(0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2), 0.0 MβŠ™, 0, 0, 0, 0.0, 0.0 J, 0.0 kpc Gyr^-2, 0.0 J K^-1, 0.0 MβŠ™ kpc^-3, 0.0 kpc, 0.0, 0.0, 0, PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(Gyr^-1, kpc),𝐋*𝐓^-1,nothing}}}(0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1), 0.0 Gyr^-1, 0.0 Gyr^-1, 0.0, 0.0 N m^-1, 0.0 J K^-1 s^-1, 0.0 kpc Gyr^-1)
 SPHGas{Float64,Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(kpc,),𝐋,nothing}}}(0.0 kpc, 0.0 kpc, 0.0 kpc), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(Gyr^-1, kpc),𝐋*𝐓^-1,nothing}}}(0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1), PVector{Quantity{Float64,𝐋*𝐓^-2,Unitful.FreeUnits{(Gyr^-2, kpc),𝐋*𝐓^-2,nothing}}}(0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2), 0.0 MβŠ™, 0, 0, 0, 0.0, 0.0 J, 0.0 kpc Gyr^-2, 0.0 J K^-1, 0.0 MβŠ™ kpc^-3, 0.0 kpc, 0.0, 0.0, 0, PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(Gyr^-1, kpc),𝐋*𝐓^-1,nothing}}}(0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1), 0.0 Gyr^-1, 0.0 Gyr^-1, 0.0, 0.0 N m^-1, 0.0 J K^-1 s^-1, 0.0 kpc Gyr^-1)

Cleaner printing styles are really necessary (and reserve default printing style for debugging)

`uconvert(PVector, units)` not typestable

I have a problem regarding unit conversion which seems to change the datatype.

For example:

source_units = getuVel(uGadget2);
target_units = getuVel(uAstro);
v = PVector(3.f0, 3.f0, 4.f0, source_units);
println(typeof(uconvert(target_units, v.x)))
     Quantity{Float64, 𝐋 𝐓^-1, Unitful.FreeUnits{(Gyr^-1, kpc), 𝐋 𝐓^-1, nothing}}

but I'd like it to stay a Float32.

See JuliaAstroSim/AstroIO.jl#10 (comment)

Benchmark is needed

Test like this:

a = PVector(u"m")
b = PVector(u"m")
x = rand(3)
y = rand(3)
julia> @code_llvm a*b

;  @ C:\Users\islent\.julia\packages\PhysicalParticles\yjUgz\src\PVector.jl:22 within `*'
; Function Attrs: uwtable
define { double } @"julia_*_21916"({ { double }, { double }, { double } } addrspace(11)* nocapture nonnull readonly dereferenceable(24), { { double }, { double }, { double } } addrspace(11)* nocapture nonnull readonly dereferenceable(24)) #0 {
top:
;  @ C:\Users\islent\.julia\packages\PhysicalParticles\yjUgz\src\PVector.jl:22 within `*' @ C:\Users\islent\.julia\packages\Unitful\dZYmO\src\quantities.jl:21
; β”Œ @ Base.jl:20 within `getproperty'
   %2 = getelementptr inbounds { { double }, { double }, { double } }, { { double }, { double }, { double } } addrspace(11)* %0, i64 0, i32 0, i32 0
   %3 = getelementptr inbounds { { double }, { double }, { double } }, { { double }, { double }, { double } } addrspace(11)* %1, i64 0, i32 0, i32 0
; β””
;  @ C:\Users\islent\.julia\packages\PhysicalParticles\yjUgz\src\PVector.jl:22 within `*' @ C:\Users\islent\.julia\packages\Unitful\dZYmO\src\quantities.jl:21 @ float.jl:405
  %4 = load double, double addrspace(11)* %2, align 8
  %5 = load double, double addrspace(11)* %3, align 8
  %6 = fmul double %4, %5
;  @ C:\Users\islent\.julia\packages\PhysicalParticles\yjUgz\src\PVector.jl:22 within `*' @ C:\Users\islent\.julia\packages\Unitful\dZYmO\src\quantities.jl:21
; β”Œ @ Base.jl:20 within `getproperty'
   %7 = getelementptr inbounds { { double }, { double }, { double } }, { { double }, { double }, { double } } addrspace(11)* %0, i64 0, i32 1, i32 0
   %8 = getelementptr inbounds { { double }, { double }, { double } }, { { double }, { double }, { double } } addrspace(11)* %1, i64 0, i32 1, i32 0
; β””
;  @ C:\Users\islent\.julia\packages\PhysicalParticles\yjUgz\src\PVector.jl:22 within `*' @ C:\Users\islent\.julia\packages\Unitful\dZYmO\src\quantities.jl:21 @ float.jl:405
  %9 = bitcast double addrspace(11)* %7 to <2 x double> addrspace(11)*
  %10 = load <2 x double>, <2 x double> addrspace(11)* %9, align 8
  %11 = bitcast double addrspace(11)* %8 to <2 x double> addrspace(11)*
  %12 = load <2 x double>, <2 x double> addrspace(11)* %11, align 8
  %13 = fmul <2 x double> %10, %12
;  @ C:\Users\islent\.julia\packages\PhysicalParticles\yjUgz\src\PVector.jl:22 within `*'
; β”Œ @ operators.jl:529 within `+' @ C:\Users\islent\.julia\packages\Unitful\dZYmO\src\quantities.jl:79 @ float.jl:401
   %14 = extractelement <2 x double> %13, i32 0
   %15 = fadd double %6, %14
   %16 = extractelement <2 x double> %13, i32 1
   %17 = fadd double %15, %16
; β””
  %.fca.0.insert = insertvalue { double } undef, double %17, 0
  ret { double } %.fca.0.insert
}

julia> @code_llvm x'*y

;  @ D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\LinearAlgebra\src\adjtrans.jl:245 within `*'
; Function Attrs: uwtable
define double @"julia_*_21917"(%jl_value_t addrspace(10)* nonnull align 8 dereferenceable(8), %jl_value_t addrspace(10)* nonnull align 16 dereferenceable(40)) #0 {
top:
; β”Œ @ Base.jl:20 within `getproperty'
   %2 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(11)*
   %3 = bitcast %jl_value_t addrspace(11)* %2 to %jl_value_t addrspace(10)* addrspace(11)*
   %4 = load %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %3, align 8
; β””
; β”Œ @ D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\LinearAlgebra\src\matmul.jl:9 within `dot'
   %5 = call double @julia_dot_21918(%jl_value_t addrspace(10)* nonnull %4, %jl_value_t addrspace(10)* nonnull %1)
; β””
  ret double %5
}

julia> @code_native a*b
        .text
; β”Œ @ PVector.jl:22 within `*'
        pushq   %rbp
        movq    %rsp, %rbp
; β”‚ @ PVector.jl:22 within `*' @ quantities.jl:21 @ float.jl:405
        vmovsd  (%rcx), %xmm0           # xmm0 = mem[0],zero
        vmulsd  (%rdx), %xmm0, %xmm0
        vmovupd 8(%rcx), %xmm1
        vmulpd  8(%rdx), %xmm1, %xmm1
; β”‚ @ PVector.jl:22 within `*'
; β”‚β”Œ @ operators.jl:529 within `+' @ quantities.jl:79 @ float.jl:401
        vaddsd  %xmm1, %xmm0, %xmm0
        vpermilpd       $1, %xmm1, %xmm1 # xmm1 = xmm1[1,0]
        vaddsd  %xmm1, %xmm0, %xmm0
; β”‚β””
        popq    %rbp
        retq
        nopw    %cs:(%rax,%rax)
; β””

julia> @code_native x'*y
        .text
; β”Œ @ adjtrans.jl:245 within `*'
        pushq   %rbp
        movq    %rsp, %rbp
; β”‚β”Œ @ Base.jl:20 within `getproperty'
        subq    $32, %rsp
        movq    (%rcx), %rcx
; β”‚β””
; β”‚β”Œ @ matmul.jl:9 within `dot'
        movabsq $julia_dot_21918, %rax
        callq   *%rax
; β”‚β””
        addq    $32, %rsp
        popq    %rbp
        retq
        nopl    (%rax)
; β””

Very few differences on compiled level!
But still need to benchmark performance of basic vectors

benchmarkplot broken

In my installation:

Julia Version 1.6.3
pkgs:

  [ab8c0f59] BenchmarkPlots v0.1.0
  [6e4b80f9] BenchmarkTools v1.2.0
  [336ed68f] CSV v0.8.5
  [5ae59095] Colors v0.12.8
  [a93c6f00] DataFrames v1.2.2
  [5789e2e9] FileIO v1.11.1
  [e9467ef8] GLMakie v0.4.7
  [bdcacae8] LoopVectorization v0.12.89
  [f517fe37] Polyester v0.5.4
  [09ab397b] StructArrays v0.6.3
  [ac1d9e8a] ThreadsX v0.1.8
  [1986cc42] Unitful v1.9.0
  [6112ee07] UnitfulAstro v1.0.1

if I run julia benchmark.jl I get:

ERROR: LoadError: UndefVarError: benchmarkplot not defined
Stacktrace:
 [1] top-level scope
   @ ~/.julia/dev/PhysicalParticles/Benchmark/benchmark.jl:28
in expression starting at /home/michele/.julia/dev/PhysicalParticles/Benchmark/benchmark.jl:28

from here:

scene, layout, df = benchmarkplot(

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Overload of Base.iterate making broadcast type unstable

module Test

import Base: length, iterate, real

abstract type AbstractType{T} end

@inline length(p::T) where T <: AbstractType = 1
@inline iterate(p::T) where T <: AbstractType = (p,nothing)
#@inline iterate(p::T,st) where T <: AbstractType = nothing
@inline real(p::T) where T <: AbstractType = p

end # module Test


import .Test.AbstractType

struct S{T<:Number} <: AbstractType{T}
    x::T
end

test(x, y) = x

@code_warntype test.(S(0), [0])

Gives output:

julia> @code_warntype test.(S(0), [0])
Variables
  #self#::Core.Const(var"##dotfunction#245#5"())
  x1::S{Int64}     
  x2::Vector{Int64}

Body::Union{}
1 ─     Base.broadcasted(Main.test, x1, x2)
β”‚       Core.Const(:(Base.materialize(%1)))
└──     Core.Const(:(return %2))

If uncomment @inline iterate(p::T,st) where T <: AbstractType = nothing, it gives a type unstable warning:

julia> @code_warntype test.(S(0), [0])
Variables
  #self#::Core.Const(var"##dotfunction#245#5"())
  x1::S{Int64}     
  x2::Vector{Int64}

Body::AbstractVector{var"#s827"} where var"#s827"
1 ─ %1 = Base.broadcasted(Main.test, x1, x2)::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(test), Tuple{Vector{Any}, Vector{Int64}}}
β”‚   %2 = Base.materialize(%1)::AbstractVector{var"#s827"} where var"#s827"
└──      return %2
julia> versioninfo()
Julia Version 1.6.0-beta1.0
Commit b84990e1ac (2021-01-08 12:42 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Xeon(R) W-10885M CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.0 (ORCJIT, skylake)
Environment:
  JULIA_DEPOT_PATH = E:\.julia
  JULIA_NUM_THREADS = 4
  JULIA_EDITOR = "D:\Programs\Microsoft VS Code\Code.exe"

julia 1.7.0-DEV.334 gives unstable warning:

julia> @code_warntype test.(S(0), [0])
Variables
  #self#::Core.Const(var"##dotfunction#257#1"())
  x1::S{Int64}
  x2::Vector{Int64}

Body::AbstractVector{var"#s829"} where var"#s829"
1 ─ %1 = Base.broadcasted(Main.test, x1, x2)::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(test), Tuple{Vector{Any}, Vector{Int64}}}   
β”‚   %2 = Base.materialize(%1)::AbstractVector{var"#s829"} where var"#s829"
└──      return %2

julia 1.5.2 gives a different unstable warning:

julia> @code_warntype test.(S(0), [0])
Variables
  #self#::Core.Compiler.Const(var"##dotfunction#253#1"(), false)
  x1::S{Int64}
  x2::Array{Int64,1}

Body::Union{BitArray{1}, Array}
1 ─ %1 = Base.broadcasted(Main.test, x1, x2)::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(test),Tuple{Array{Any,1},Array{Int64,1}}} 
β”‚   %2 = Base.materialize(%1)::Union{BitArray{1}, Array}
└──      return %2

It seems that the compiler is confused with BitArray and Array.

Define a getindex method for retrieving only a certain collection from a StructArray of Stars?

Hello @elehcim, I have the same problem when plotting a certain collection of particles in AstroPlot.jl. For example, I manually filter the collection in https://github.com/JuliaAstroSim/AstroPlot.jl/blob/5cda583666557c88049eb54e99b5e1a6be2c13c5/src/snapshots/positions.jl#L21:

function plot_positionslice!(scene, data, collection::Collection, u::Union{Nothing, Unitful.FreeUnits} = nothing; kw...)
    d = filter(p->p.Collection == collection, data)
    if isempty(d)
        @warn "No $collection particle found."
        return scene
    else
        plot_positionslice!(scene, d, u; kw...)
    end
end

During simulation, particles are transmited between processors. I can't figure out a way to avoid filtering :(

(As metioned in JuliaAstroSim/AstroIO.jl#8)

Incompatible with Gadfly

When installing from github, I got error:

(v1.3) pkg> add https://github.com/JuliaAstroSim/PhysicalParticles.jl
  Updating git-repo `https://github.com/JuliaAstroSim/PhysicalParticles.jl`
  Updating git-repo `https://github.com/JuliaAstroSim/PhysicalParticles.jl`
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Gadfly [c91e804a]:
 Gadfly [c91e804a] log:
 β”œβ”€possible versions are: [0.8.0, 1.0.0-1.0.1, 1.1.0] or uninstalled
 β”œβ”€restricted to versions 1.1.0 by an explicit requirement, leaving only versions 1.1.0
 └─restricted by compatibility requirements with DocStringExtensions [ffbed154] to versions: [0.8..0, 1.0.0-1.0.1] or uninstalled β€” no versions left
   └─DocStringExtensions [ffbed154] log:
     β”œβ”€possible versions are: [0.4.6, 0.5.0, 0.6.0, 0.7.0, 0.8.0-0.8.1] or uninstalled
     └─restricted to versions 0.8 by PhysicalParticles [78724250], leaving only versions 0.8.0-0.88.1
       └─PhysicalParticles [78724250] log:
         β”œβ”€possible versions are: 0.1.0 or uninstalled
         └─PhysicalParticles [78724250] is fixed to version 0.1.0

May I infer that the incompatibility comes from DocStringExtensions? @longqian95

After Gadfly removed, PhysicalParticles could be installed normally.
In fact DocStringExtensions didn't work as expected in documentation, so I'm considering removing it :D.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.