Compare commits

..

No commits in common. "080f0f590c75c2f51f5442a48d820d0067f2b649" and "87dbaf2c327f36179c0426b7c97255a53cee4e4e" have entirely different histories.

10 changed files with 27 additions and 75 deletions

View File

@ -17,9 +17,9 @@ jobs:
fetch-depth: 0
- name: Setup Julia environment
uses: https://github.com/julia-actions/setup-julia@v2
uses: https://github.com/julia-actions/setup-julia@v1.9.2
with:
version: '1.10'
version: '1.9.2'
- name: Instantiate
run: |
@ -58,9 +58,9 @@ jobs:
fetch-depth: 0
- name: Setup Julia environment
uses: https://github.com/julia-actions/setup-julia@v2
uses: https://github.com/julia-actions/setup-julia@v1.9.2
with:
version: '1.10'
version: '1.9.2'
- name: Build docs
run: |

View File

@ -84,13 +84,11 @@ Compute a sum over the vector. Use an algorithm that accounts for accumulated er
Linearly many FLOP with growing data.
"""
function compute(::ComputeTaskABC_Sum, data...)::Float64
return sum_kbn([data...])
#=s = 0.0im
s = 0.0im
for d in data
s += d
end
return s=#
return s
end
function compute(::ComputeTaskABC_Sum, data::AbstractArray)::Float64

View File

@ -27,6 +27,9 @@ Return a ProcessInput of randomly generated [`ABCParticle`](@ref)s from a [`ABCP
Note: This uses RAMBO to create a valid process with conservation of momentum and energy.
"""
function gen_process_input(processDescription::ABCProcessDescription)
inParticleTypes = keys(processDescription.inParticles)
outParticleTypes = keys(processDescription.outParticles)
massSum = 0
inputMasses = Vector{Float64}()
for (particle, n) in processDescription.inParticles
@ -63,7 +66,8 @@ function gen_process_input(processDescription::ABCProcessDescription)
index = 1
for (particle, n) in processDescription.outParticles
for _ in 1:n
push!(outputParticles, particle(final_momenta[index]))
mom = final_momenta[index]
push!(outputParticles, particle(SFourMomentum(-mom.E, mom.px, mom.py, mom.pz)))
index += 1
end
end

View File

@ -313,7 +313,7 @@ Return the factor of a vertex in a QED feynman diagram.
return -1im * e * gamma()
end
@inline function QED_inner_edge(p::QEDParticle)
@inline function QED_inner_edge(p::QEDParticle)::DiracMatrix
return propagator(particle(p), p.momentum)
end

View File

@ -27,8 +27,7 @@ function optimize_step!(optimizer::RandomWalkOptimizer, graph::DAG)
# push
# choose one of fuse/split/reduce
# TODO refactor fusions so they actually work
option = rand(r, 2:3)
option = rand(r, 1:3)
if option == 1 && !isempty(operations.nodeFusions)
push_operation!(graph, rand(r, collect(operations.nodeFusions)))
return true

View File

@ -48,7 +48,7 @@ function insert_helper!(
trie::NodeIdTrie{NodeType},
node::NodeType,
depth::Int,
) where {TaskType <: AbstractDataTask, NodeType <: DataTaskNode{TaskType}}
) where {TaskType <: AbstractTask, NodeType <: Union{DataTaskNode{TaskType}, ComputeTaskNode{TaskType}}}
if (length(children(node)) == depth)
push!(trie.value, node)
return nothing
@ -62,26 +62,6 @@ function insert_helper!(
end
return insert_helper!(trie.children[id], node, depth)
end
# TODO: Remove this workaround once https://github.com/JuliaLang/julia/issues/54404 is fixed in julia 1.10+
function insert_helper!(
trie::NodeIdTrie{NodeType},
node::NodeType,
depth::Int,
) where {TaskType <: AbstractComputeTask, NodeType <: ComputeTaskNode{TaskType}}
if (length(children(node)) == depth)
push!(trie.value, node)
return nothing
end
depth = depth + 1
id = node.children[depth].id
if (!haskey(trie.children, id))
trie.children[id] = NodeIdTrie{NodeType}()
end
return insert_helper!(trie.children[id], node, depth)
end
"""
insert!(trie::NodeTrie, node::Node)
@ -91,17 +71,7 @@ Insert the given node into the trie. It's sorted by its type in the first layer,
function insert!(
trie::NodeTrie,
node::NodeType,
) where {TaskType <: AbstractDataTask, NodeType <: DataTaskNode{TaskType}}
if (!haskey(trie.children, NodeType))
trie.children[NodeType] = NodeIdTrie{NodeType}()
end
return insert_helper!(trie.children[NodeType], node, 0)
end
# TODO: Remove this workaround once https://github.com/JuliaLang/julia/issues/54404 is fixed in julia 1.10+
function insert!(
trie::NodeTrie,
node::NodeType,
) where {TaskType <: AbstractComputeTask, NodeType <: ComputeTaskNode{TaskType}}
) where {TaskType <: AbstractTask, NodeType <: Union{DataTaskNode{TaskType}, ComputeTaskNode{TaskType}}}
if (!haskey(trie.children, NodeType))
trie.children[NodeType] = NodeIdTrie{NodeType}()
end

View File

@ -1,8 +1,6 @@
using MetagraphOptimization
using Random
RNG = Random.MersenneTwister(321)
function test_known_graph(name::String, n, fusion_test = true)
@testset "Test $name Graph ($n)" begin
graph = parse_dag(joinpath(@__DIR__, "..", "input", "$name.txt"), ABCModel())
@ -11,7 +9,7 @@ function test_known_graph(name::String, n, fusion_test = true)
if (fusion_test)
test_node_fusion(graph)
end
test_random_walk(RNG, graph, n)
test_random_walk(graph, n)
end
end
@ -45,7 +43,7 @@ function test_node_fusion(g::DAG)
end
end
function test_random_walk(RNG, g::DAG, n::Int64)
function test_random_walk(g::DAG, n::Int64)
@testset "Test Random Walk ($n)" begin
# the purpose here is to do "random" operations and reverse them again and validate that the graph stays the same and doesn't diverge
reset_graph!(g)
@ -56,18 +54,18 @@ function test_random_walk(RNG, g::DAG, n::Int64)
for i in 1:n
# choose push or pop
if rand(RNG, Bool)
if rand(Bool)
# push
opt = get_operations(g)
# choose one of fuse/split/reduce
option = rand(RNG, 1:3)
option = rand(1:3)
if option == 1 && !isempty(opt.nodeFusions)
push_operation!(g, rand(RNG, collect(opt.nodeFusions)))
push_operation!(g, rand(collect(opt.nodeFusions)))
elseif option == 2 && !isempty(opt.nodeReductions)
push_operation!(g, rand(RNG, collect(opt.nodeReductions)))
push_operation!(g, rand(collect(opt.nodeReductions)))
elseif option == 3 && !isempty(opt.nodeSplits)
push_operation!(g, rand(RNG, collect(opt.nodeSplits)))
push_operation!(g, rand(collect(opt.nodeSplits)))
else
i = i - 1
end
@ -89,6 +87,8 @@ function test_random_walk(RNG, g::DAG, n::Int64)
end
end
Random.seed!(0)
test_known_graph("AB->AB", 10000)
test_known_graph("AB->ABBB", 10000)
test_known_graph("AB->ABBBBB", 1000, false)

View File

@ -9,7 +9,7 @@ import MetagraphOptimization.ABCParticle
import MetagraphOptimization.interaction_result
const RTOL = sqrt(eps(Float64))
RNG = Random.MersenneTwister(0)
RNG = Random.default_rng()
function check_particle_reverse_moment(p1::SFourMomentum, p2::SFourMomentum)
@test isapprox(abs(p1.E), abs(p2.E))
@ -123,8 +123,6 @@ expected_result = execute(graph, process_2_4, machine, particles_2_4)
end
end
#=
TODO: fix precision(?) issues
@testset "AB->ABBB after random walk" begin
for i in 1:50
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())
@ -134,7 +132,6 @@ TODO: fix precision(?) issues
@test isapprox(execute(graph, process_2_4, machine, particles_2_4), expected_result; rtol = RTOL)
end
end
=#
@testset "AB->AB large sum fusion" begin
for _ in 1:20
@ -234,19 +231,3 @@ end
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
end
end
@testset "$(process) after random walk" for process in ["ke->ke", "ke->kke", "ke->kkke"]
process = parse_process("ke->kkke", QEDModel())
inputs = [gen_process_input(process) for _ in 1:100]
graph = gen_graph(process)
gt = execute.(Ref(graph), Ref(process), Ref(machine), inputs)
for i in 1:50
graph = gen_graph(process)
optimize!(RandomWalkOptimizer(RNG), graph, 100)
@test is_valid(graph)
func = get_compute_function(graph, process, machine)
@test isapprox(func.(inputs), gt; rtol = RTOL)
end
end

View File

@ -1,7 +1,7 @@
using MetagraphOptimization
using Random
RNG = Random.MersenneTwister(0)
RNG = Random.default_rng()
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())

View File

@ -15,7 +15,7 @@ import MetagraphOptimization.QED_vertex
def_momentum = SFourMomentum(1.0, 0.0, 0.0, 0.0)
RNG = Random.MersenneTwister(0)
RNG = Random.default_rng()
testparticleTypes = [
PhotonStateful{Incoming, PolX},