juliaastrosim / physicalparticles.jl Goto Github PK
View Code? Open in Web Editor NEWPhysical vector and particle types for Julia
License: GNU General Public License v3.0
Physical vector and particle types for Julia
License: GNU General Public License v3.0
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)
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
.
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
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:
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!
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
.
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)
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.
Temperature, Energy.
And for star particles: age, chemical composition (metallicity).
I'm referring to
PhysicalParticles.jl/src/PhysicalParticle.jl
Line 349 in 3bb5227
Would be something like Particle
more appropriate?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.