changeset 1819:e89e28fa9637 feature/jet_aqua

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 18 Oct 2024 21:33:55 +0200
parents d91a9f47380f (diff) 9b47cdbbba75 (current diff)
children bddcae938ded
files Manifest.toml test/Manifest.toml
diffstat 15 files changed, 164 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/Manifest.toml	Fri Oct 18 21:18:58 2024 +0200
+++ b/Manifest.toml	Fri Oct 18 21:33:55 2024 +0200
@@ -2,7 +2,7 @@
 
 julia_version = "1.11.1"
 manifest_format = "2.0"
-project_hash = "e8ce4954d65eae4e48090d67a590f9405da1832d"
+project_hash = "a8bfbeb10ca8c44ef39fdba75f02b23fc92b2c6a"
 
 [[deps.Artifacts]]
 uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
--- a/Project.toml	Fri Oct 18 21:18:58 2024 +0200
+++ b/Project.toml	Fri Oct 18 21:33:55 2024 +0200
@@ -21,3 +21,10 @@
 
 [compat]
 julia = "1.5"
+StaticArrays = "1.0"
+TOML = "1.0"
+Makie = "0.21"
+SparseArrayKit = "0.3"
+Tokens = "0.1.1"
+SparseArrays = "1.10"
+LinearAlgebra = "1.5"
--- a/src/Diffinitive.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/src/Diffinitive.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -10,4 +10,14 @@
 export Grids
 export SbpOperators
 
+
+
+# Aqua.jl fixes
+using StaticArrays
+using .LazyTensors
+Base.:+(a::StaticArray, b::LazyArray) = a +̃ b
+Base.:+(a::LazyArray, b::StaticArray) = a +̃ b
+Base.:-(a::StaticArray, b::LazyArray) = a -̃ b
+Base.:-(a::LazyArray, b::StaticArray) = a -̃ b
+
 end
--- a/src/Grids/equidistant_grid.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/src/Grids/equidistant_grid.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -15,7 +15,7 @@
 end
 
 # Indexing interface
-Base.getindex(g::EquidistantGrid, i) = g.points[i]
+Base.getindex(g::EquidistantGrid, i::Int) = g.points[i]
 Base.eachindex(g::EquidistantGrid) = eachindex(g.points)
 Base.firstindex(g::EquidistantGrid) = firstindex(g.points)
 Base.lastindex(g::EquidistantGrid) = lastindex(g.points)
--- a/src/Grids/mapped_grid.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/src/Grids/mapped_grid.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -94,25 +94,33 @@
 
 
 """
+    mapped_grid(x,J,size...)
+    mapped_grid(x,J,size...)
+"""
+function mapped_grid end
+"""
     mapped_grid(x, J, size::Vararg{Int})
 
 A `MappedGrid` with a default logical grid on the D-dimensional unit hyper 
-box [0,1]ᴰ. `x` and `J`are functions to be evaluated on the logical grid
+box [0,1]ᴰ. `x` and `J` are functions to be evaluated on the logical grid
 and `size` determines the size of the logical grid.
 """
 function mapped_grid(x, J, size::Vararg{Int})
     D = length(size)
     lg = equidistant_grid(ntuple(i->0., D), ntuple(i->1., D), size...)
-    return mapped_grid(lg, x, J)
+    return mapped_grid(x, J, lg)
+
+    # parameterspace = ...
+    # return mapped_grid(x, J, parameterspace, size...)
 end
 
 """
-    mapped_grid(lg::Grid, x, J)
+    mapped_grid(x, J, lg::Grid)
 
 A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are
 determined by the functions `x` and `J`.
 """
-function mapped_grid(lg::Grid, x, J)
+function mapped_grid(x, J, lg::Grid)
     return MappedGrid(
         lg,
         map(x,lg),
@@ -121,6 +129,17 @@
 end
 
 """
+    mapped_grid(x, J, lg::Grid)
+
+A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are
+determined by the functions `x` and `J`.
+"""
+function mapped_grid(x, J, parameterspace, size::Vararg{Int})
+    lg = equidistant_grid(parameterspace, size...)
+    return mapped_grid(x, J, lg)
+end
+
+"""
     metric_tensor(g::MappedGrid)
 
 The metric tensor of `g` as a grid function.
--- a/src/LazyTensors/lazy_tensor_operations.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -169,10 +169,10 @@
     )
 end
 
-InflatedTensor(before::IdentityTensor, tm::LazyTensor{T}) where T = InflatedTensor(before,tm,IdentityTensor{T}())
-InflatedTensor(tm::LazyTensor{T}, after::IdentityTensor) where T = InflatedTensor(IdentityTensor{T}(),tm,after)
+InflatedTensor(before::IdentityTensor, tm::LazyTensor) = InflatedTensor(before,tm,IdentityTensor{eltype(tm)}())
+InflatedTensor(tm::LazyTensor, after::IdentityTensor) = InflatedTensor(IdentityTensor{eltype(tm)}(),tm,after)
 # Resolve ambiguity between the two previous methods
-InflatedTensor(I1::IdentityTensor{T}, I2::IdentityTensor{T}) where T = InflatedTensor(I1,I2,IdentityTensor{T}())
+InflatedTensor(I1::IdentityTensor, I2::IdentityTensor) = InflatedTensor(I1,I2,IdentityTensor{promote_type(eltype(I1), eltype(I2))}())
 
 # TODO: Implement some pretty printing in terms of ⊗. E.g InflatedTensor(I(3),B,I(2)) -> I(3)⊗B⊗I(2)
 
@@ -263,7 +263,7 @@
     return itm1∘itm2
 end
 
-LazyOuterProduct(t1::IdentityTensor{T}, t2::IdentityTensor{T}) where T = IdentityTensor{T}(t1.size...,t2.size...)
+LazyOuterProduct(t1::IdentityTensor, t2::IdentityTensor) = IdentityTensor{promote_type(eltype(t1),eltype(t2))}(t1.size...,t2.size...)
 LazyOuterProduct(t1::LazyTensor, t2::IdentityTensor) = InflatedTensor(t1, t2)
 LazyOuterProduct(t1::IdentityTensor, t2::LazyTensor) = InflatedTensor(t1, t2)
 
--- a/src/RegionIndices/RegionIndices.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/src/RegionIndices/RegionIndices.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -25,18 +25,17 @@
 Index(R::Type{<:Region}, T::Type{<:Integer}) = Index{R,T}
 IndexTupleType(T::Type{<:Integer},R::NTuple{N, DataType} where N) = Tuple{Index.(R, T)...}
 
-Base.convert(::Type{T}, i::Index{R,T} where R) where T = i.i
+Base.convert(::Type{T}, i::Index{R,T} where R) where T <: Integer = i.i
 Base.convert(::Type{CartesianIndex}, I::NTuple{N,Index} where N) = CartesianIndex(convert.(Int, I))
 
 Base.Int(I::Index) = I.i
 Base.to_index(I::Index) = Int(I) #How to get this to work for all cases??
-Base.getindex(A::AbstractArray{T,N}, I::NTuple{N,Index}) where {T,N} = A[I...] #Is this ok??
 
 function Index(i::Integer, boundary_width::Integer, dim_size::Integer)
     return Index{getregion(i,boundary_width,dim_size)}(i)
 end
 
-IndexTuple(t::Vararg{Tuple{T, DataType}}) where T<:Integer = Index.(t)
+IndexTuple(t::Vararg{Tuple{Integer, DataType}}) = Index.(t)
 export IndexTuple
 
 # TODO: Use the values of the region structs, e.g. Lower(), for the region parameter instead of the types.
--- a/src/SbpOperators/stencil.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/src/SbpOperators/stencil.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -2,14 +2,16 @@
     range::UnitRange{Int64}
     weights::NTuple{N,T}
 
-    function Stencil(range::UnitRange,weights::NTuple{N,T}) where {T, N}
+    function Stencil(range::UnitRange,weights::NTuple{N,Any}) where N
+        T = eltype(weights)
+
         @assert length(range) == N
         new{T,N}(range,weights)
     end
 end
 
 """
-    Stencil(weights::NTuple; center::Int)
+    Stencil(weights...; center::Int)
 
 Create a stencil with the given weights with element `center` as the center of the stencil.
 """
@@ -109,21 +111,24 @@
     s::Stencil{Stencil{T,N},M}
 end
 
+NestedStencil(;center) = NestedStencil(Stencil(;center))
+CenteredNestedStencil() = NestedStencil(CenteredStencil())
+
 # Stencil input
 NestedStencil(s::Vararg{Stencil}; center) = NestedStencil(Stencil(s... ; center))
 CenteredNestedStencil(s::Vararg{Stencil}) = NestedStencil(CenteredStencil(s...))
 
 # Tuple input
-function NestedStencil(weights::Vararg{NTuple{N,Any}}; center) where N
+function NestedStencil(weights::Vararg{NTuple{N,Any} where N}; center)
     inner_stencils = map(w -> Stencil(w...; center), weights)
     return NestedStencil(Stencil(inner_stencils... ; center))
 end
-function CenteredNestedStencil(weights::Vararg{NTuple{N,Any}}) where N
+
+function CenteredNestedStencil(weights::Vararg{NTuple{N,Any} where N})
     inner_stencils = map(w->CenteredStencil(w...), weights)
     return CenteredNestedStencil(inner_stencils...)
 end
 
-
 # Conversion
 function NestedStencil{T,N,M}(ns::NestedStencil{S,N,M}) where {T,S,N,M}
     return NestedStencil(Stencil{Stencil{T}}(ns.s))
@@ -136,7 +141,7 @@
 function Base.convert(::Type{NestedStencil{T,N,M}}, s::NestedStencil{S,N,M}) where {T,S,N,M}
     return NestedStencil{T,N,M}(s)
 end
-Base.convert(::Type{NestedStencil{T}}, stencil) where T = NestedStencil{T}(stencil)
+Base.convert(::Type{NestedStencil{T}}, stencil::NestedStencil) where T = NestedStencil{T}(stencil)
 
 function Base.promote_rule(::Type{NestedStencil{T,N,M}}, ::Type{NestedStencil{S,N,M}}) where {T,S,N,M}
     return NestedStencil{promote_type(T,S),N,M}
--- a/src/SbpOperators/volumeops/constant_interior_scaling_operator.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/src/SbpOperators/volumeops/constant_interior_scaling_operator.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -19,7 +19,7 @@
     end
 end
 
-function ConstantInteriorScalingOperator(grid::EquidistantGrid, interior_weight, closure_weights)
+function ConstantInteriorScalingOperator(grid::EquidistantGrid, interior_weight::T, closure_weights::NTuple{N,T} where N) where T
     return ConstantInteriorScalingOperator(interior_weight, Tuple(closure_weights), size(grid)[1])
 end
 
--- a/src/SbpOperators/volumeops/volume_operator.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/src/SbpOperators/volumeops/volume_operator.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -6,18 +6,23 @@
 struct VolumeOperator{T,N,M,K} <: LazyTensor{T,1,1}
     inner_stencil::Stencil{T,N}
     closure_stencils::NTuple{M,Stencil{T,K}}
-    size::NTuple{1,Int}
+    size::Int
     parity::Parity
+
+    function VolumeOperator(inner_stencil::Stencil{T,N}, closure_stencils::Tuple{Stencil{T,K}, Vararg{Stencil{T,K}}}, size::Int, parity::Parity) where {T,N,K}
+        M = length(closure_stencils)
+        return new{T,N,M,K}(inner_stencil, closure_stencils, size, parity)
+    end
 end
 
 function VolumeOperator(grid::EquidistantGrid, inner_stencil, closure_stencils, parity)
-    return VolumeOperator(inner_stencil, Tuple(closure_stencils), size(grid), parity)
+    return VolumeOperator(inner_stencil, Tuple(closure_stencils), size(grid,1), parity)
 end # TBD: Remove this function?
 
 closure_size(::VolumeOperator{T,N,M}) where {T,N,M} = M
 
-LazyTensors.range_size(op::VolumeOperator) = op.size
-LazyTensors.domain_size(op::VolumeOperator) = op.size
+LazyTensors.range_size(op::VolumeOperator) = (op.size,)
+LazyTensors.domain_size(op::VolumeOperator) = (op.size,)
 
 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Lower})
     return @inbounds apply_stencil(op.closure_stencils[Int(i)], v, Int(i))
@@ -28,11 +33,11 @@
 end
 
 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Upper})
-    return @inbounds Int(op.parity)*apply_stencil_backwards(op.closure_stencils[op.size[1]-Int(i)+1], v, Int(i))
+    return @inbounds Int(op.parity)*apply_stencil_backwards(op.closure_stencils[op.size-Int(i)+1], v, Int(i))
 end
 
 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i)
-    r = getregion(i, closure_size(op), op.size[1])
+    r = getregion(i, closure_size(op), op.size)
     return LazyTensors.apply(op, v, Index(i, r))
 end
 # TODO: Move this to LazyTensors when we have the region communication down.
--- a/test/Grids/mapped_grid_test.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/test/Grids/mapped_grid_test.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -282,7 +282,7 @@
     @test logical_grid(mg) == lg
     @test collect(mg) == map(x̄, lg)
 
-    @test mapped_grid(lg, x̄, J) == mg
+    @test mapped_grid(x̄, J, lg) == mg
 end
 
 @testset "metric_tensor" begin
--- a/test/Manifest.toml	Fri Oct 18 21:18:58 2024 +0200
+++ b/test/Manifest.toml	Fri Oct 18 21:33:55 2024 +0200
@@ -2,7 +2,13 @@
 
 julia_version = "1.11.1"
 manifest_format = "2.0"
-project_hash = "9dddd5385164ee197d1b3f22302bc95701c1f5e5"
+project_hash = "b23d6f58220d898029330f7adcac8132668171ec"
+
+[[deps.Aqua]]
+deps = ["Compat", "Pkg", "Test"]
+git-tree-sha1 = "49b1d7a9870c87ba13dc63f8ccfcf578cb266f95"
+uuid = "4c88cf16-eb10-579e-8560-4a9242c79595"
+version = "0.8.9"
 
 [[deps.ArgTools]]
 uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
@@ -22,6 +28,22 @@
 uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
 version = "1.5.0"
 
+[[deps.CodeTracking]]
+deps = ["InteractiveUtils", "UUIDs"]
+git-tree-sha1 = "7eee164f122511d3e4e1ebadb7956939ea7e1c77"
+uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
+version = "1.3.6"
+
+[[deps.Compat]]
+deps = ["TOML", "UUIDs"]
+git-tree-sha1 = "8ae8d32e09f0dcf42a36b90d4e17f5dd2e4c4215"
+uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
+version = "4.16.0"
+weakdeps = ["Dates", "LinearAlgebra"]
+
+    [deps.Compat.extensions]
+    CompatLinearAlgebraExt = "LinearAlgebra"
+
 [[deps.CompilerSupportLibraries_jll]]
 deps = ["Artifacts", "Libdl"]
 uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
@@ -78,6 +100,20 @@
 uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
 version = "0.2.2"
 
+[[deps.JET]]
+deps = ["CodeTracking", "InteractiveUtils", "JuliaInterpreter", "LoweredCodeUtils", "MacroTools", "Pkg", "PrecompileTools", "Preferences", "Test"]
+git-tree-sha1 = "b2cb92e1fa8c1f33b1eb997e195dca442f53440b"
+uuid = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
+version = "0.9.11"
+
+    [deps.JET.extensions]
+    JETCthulhuExt = "Cthulhu"
+    ReviseExt = "Revise"
+
+    [deps.JET.weakdeps]
+    Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f"
+    Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
+
 [[deps.JLLWrappers]]
 deps = ["Artifacts", "Preferences"]
 git-tree-sha1 = "be3dc50a92e5a386872a493a10050136d4703f9b"
@@ -90,6 +126,12 @@
 uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
 version = "0.21.4"
 
+[[deps.JuliaInterpreter]]
+deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
+git-tree-sha1 = "2984284a8abcfcc4784d95a9e2ea4e352dd8ede7"
+uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
+version = "0.9.36"
+
 [[deps.LRUCache]]
 git-tree-sha1 = "b3cc6698599b10e652832c2f23db3cab99d51b59"
 uuid = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
@@ -153,6 +195,18 @@
 uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
 version = "1.11.0"
 
+[[deps.LoweredCodeUtils]]
+deps = ["JuliaInterpreter"]
+git-tree-sha1 = "260dc274c1bc2cb839e758588c63d9c8b5e639d1"
+uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
+version = "3.0.5"
+
+[[deps.MacroTools]]
+deps = ["Markdown", "Random"]
+git-tree-sha1 = "2fa9ee3e63fd3a4f7a9a4f4744a52f4856de82df"
+uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
+version = "0.5.13"
+
 [[deps.Markdown]]
 deps = ["Base64"]
 uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
--- a/test/Project.toml	Fri Oct 18 21:18:58 2024 +0200
+++ b/test/Project.toml	Fri Oct 18 21:33:55 2024 +0200
@@ -1,6 +1,8 @@
 [deps]
+Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
 BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
 Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
+JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
 LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
 SparseArrayKit = "a9a3c162-d163-4c15-8926-b8794fbefed2"
 SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
--- a/test/SbpOperators/volumeops/volume_operator_test.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/test/SbpOperators/volumeops/volume_operator_test.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -17,7 +17,7 @@
     g = equidistant_grid(0.,1., 11)
 
     @testset "Constructors" begin
-        op = VolumeOperator(inner_stencil,closure_stencils,(11,),even)
+        op = VolumeOperator(inner_stencil, closure_stencils, 11, even)
         @test op == VolumeOperator(g,inner_stencil,closure_stencils,even)
         @test op isa LazyTensor{T,1,1} where T
     end
--- a/test/runtests.jl	Fri Oct 18 21:18:58 2024 +0200
+++ b/test/runtests.jl	Fri Oct 18 21:33:55 2024 +0200
@@ -1,4 +1,7 @@
+using Diffinitive
 using Test
+using JET
+using Aqua
 using Glob
 
 """
@@ -18,7 +21,7 @@
     run_testfiles(".", globs)
 end
 
-function  run_testfiles(path, globs)
+function  run_testfiles(path,   globs)
     for name ∈ readdir(path)
         filepath = joinpath(path, name)
 
@@ -29,25 +32,44 @@
         end
 
         if endswith(name, "_test.jl") && any(occursin.(globs, filepath))
-            printstyled("Running "; bold=true, color=:green)
-            print(filepath)
-
-            t_start = time()
-            @testset "$name" begin
-                include(filepath)
+            log_and_time(filepath) do
+                @testset "$name" begin
+                    include(filepath)
+                end
             end
-            t_end = time()
-
-            Δt = t_end - t_start
-            printstyled(" ($(round(Δt, digits=2)) s)"; color=:light_black)
-            println()
         end
     end
 end
 
+function log_and_time(f, msg)
+    printstyled("Running "; bold=true, color=:green)
+    print(msg)
+
+    t_start = time()
+    f()
+    t_end = time()
+    Δt = t_end - t_start
+    printstyled(" ($(round(Δt, digits=2)) s)"; color=:light_black)
+    println()
+end
+
 testsetname = isempty(ARGS) ? "Diffinitive.jl" : "["*join(ARGS, ", ")*"]"
 
 @testset "$testsetname" begin
+    if isempty(ARGS)
+        log_and_time("code quality tests using Aqua.jl") do
+            @testset "Code quality (Aqua.jl)" begin
+                Aqua.test_all(Diffinitive)
+            end
+        end
+
+        log_and_time("code linting using JET.jl") do
+            @testset "Code linting (JET.jl)" begin
+                JET.test_package(Diffinitive; target_defined_modules = true)
+            end
+        end
+    end
+
     run_testfiles(ARGS)
     println()
 end