-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DirectCR-RSSA #346
base: master
Are you sure you want to change the base?
DirectCR-RSSA #346
Conversation
Pull Request Test Coverage Report for Build 6141985002
💛 - Coveralls |
Conflicts: src/spatial/bracketing.jl src/spatial/reaction_rates.jl
src/spatial/directcrdirect.jl
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a very hard-to-find bug in the ordering of arguments in generate_jumps!. I fixed it here and in NSM.jl.
Pull Request Test Coverage Report for Build 6180696485
💛 - Coveralls |
…to RSSACRDirect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs rebasing too it appears.
function LowHigh(low::T, high::T; do_copy = true) where {T} | ||
if do_copy | ||
return new{T}(deepcopy(low), deepcopy(high)) | ||
else | ||
return new{T}(low, high) | ||
end | ||
end | ||
LowHigh(pair::Tuple{T,T}; kwargs...) where {T} = LowHigh(pair[1], pair[2]; kwargs...) | ||
LowHigh(low_and_high::T; kwargs...) where {T} = LowHigh(low_and_high, low_and_high; kwargs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does switching to using a branch have performance implications? We create these structures a lot right in the scalar case right? I'm not sure if Julia will remove it during compilation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it's not optimized away, it shouldn't be expensive, right? I am not good at reading low level code but it seems that it does get optimized away in the end.
# Old struct without branching
struct LowHighOld{T}
low::T
high::T
function LowHighOld(low::T, high::T) where {T}
new{T}(deepcopy(low), deepcopy(high))
end
end
# New struct with branching
struct LowHighNew{T}
low::T
high::T
function LowHighNew(low::T, high::T; do_copy=true) where {T}
if do_copy
return new{T}(deepcopy(low), deepcopy(high))
else
return new{T}(low, high)
end
end
end
# Test values
low_value = 10
high_value = 20
# Code introspection to see if the branch is removed in scalar cases
@code_llvm debuginfo=:none LowHighOld(low_value, high_value)
@code_llvm debuginfo=:none LowHighNew(low_value, high_value; do_copy=true)
The output of the code introspection is as follows:
define void @julia_LowHighOld_2364([2 x i64]* noalias nocapture noundef nonnull sret([2 x i64])
align 8 dereferenceable(16) %0, {}* noundef nonnull readonly %1, i64 signext %2, i64 signext %3) #0 {
top:
%newstruct.sroa.0.0..sroa_idx = getelementptr inbounds [2 x i64], [2 x i64]* %0, i64 0, i64 0
store i64 %2, i64* %newstruct.sroa.0.0..sroa_idx, align 8
%newstruct.sroa.2.0..sroa_idx1 = getelementptr inbounds [2 x i64], [2 x i64]* %0, i64 0, i64 1 store i64 %3, i64* %newstruct.sroa.2.0..sroa_idx1, align 8
ret void
}
define void @julia_LowHighNew_2366([2 x i64]* noalias nocapture noundef nonnull sret([2 x i64])
align 8 dereferenceable(16) %0, [1 x i8]* nocapture noundef nonnull readonly align 1 dereferenceable(1) %1, {}* noundef nonnull readonly %2, i64 signext %3, i64 signext %4) #0 {
top:
%.sroa.025.0..sroa_idx = getelementptr inbounds [2 x i64], [2 x i64]* %0, i64 0, i64 0
store i64 %3, i64* %.sroa.025.0..sroa_idx, align 8
%.sroa.2.0..sroa_idx26 = getelementptr inbounds [2 x i64], [2 x i64]* %0, i64 0, i64 1
store i64 %4, i64* %.sroa.2.0..sroa_idx26, align 8
ret void
}
test/spatial/ABC.jl
Outdated
|
||
# SSAs | ||
for alg in [DirectCRDirect(), DirectCRRSSA()] | ||
push!(jump_problems, JumpProblem(prob, alg, majumps, hopping_constants = hopping_constants, spatial_system = grids[1], save_positions = (false, false), rng = rng)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
push!(jump_problems, JumpProblem(prob, alg, majumps, hopping_constants = hopping_constants, spatial_system = grids[1], save_positions = (false, false), rng = rng)) | |
push!(jump_problems, JumpProblem(prob, alg, majumps; hopping_constants, spatial_system = grids[1], save_positions = (false, false), rng)) |
jump = sample_jump_direct(rx_rates.high, hop_rates.high, site, spatial_system, rng) | ||
time_delta += randexp(rng) | ||
if accept_jump(p, u, jump) | ||
p.next_jump_time = t + time_delta / groupsum(rt) | ||
p.next_jump = jump | ||
break | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle if there is no next jump?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I do not rembmer any of the logic by now. Do we have a test for what you are asking? If not, we should, for all SSAs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed comments.
What do I need to do to get rid of the format and the spell check CI failures? @isaacsas |
For spell check fix the listed spelling errors I guess. Haven’t ever used it or seen it before. For formatting use JuliaFormatter to format the repo and add to the PR. |
Just FYI, I'm traveling for the next week, but will try to review once I am back in Boston. |
@Vilin97 sorry again for the long delays with this. I’ll try to put a test for the case I was worried about into the general tests in a followup. Assuming tests now pass I’ll merge. I do think there is a chance the removal of the dispatch for HighLow could have performance implications, as I’m not sure Julia can always remove the branch in this situation (what it can do from the REPL may not be the same as what it can do here). But in any case we can merge and that can be examined later as a performance optimization. Thanks again for your efforts on this — I look forward to updating the benchmarks to use it to see how it does. |
Ahh, I didn’t realize that the updates to address my earlier comments actually never passed tests. |
A new spatial SSA called
DirectCRRSSA
uses RSSA-style sampling to sample the site+jump. It is about 20% faster thanDirectCRDirect
, at least on the problem in thetest/spatial/ABC.jl
(5 sites in a line, 3 species, 2 reactions).