-
-
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 ourterms of serviceand 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 forBuild 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 forBuild 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
structLowHighOld{T}
low::T
high::T
functionLowHighOld(low::T,high::T)where{T}
new{T}(deepcopy(low),deepcopy(high))
end
end
#New struct with branching
structLowHighNew{T}
low::T
high::T
functionLowHighNew(low::T,high::T;do_copy=true)where{T}
ifdo_copy
returnnew{T}(deepcopy(low),deepcopy(high))
else
returnnew{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_llvmdebuginfo=:noneLowHighOld(low_value, high_value)
@code_llvmdebuginfo=:noneLowHighNew(low_value, high_value; do_copy=true)
The output of the code introspection is as follows:
definevoid@julia_LowHighOld_2364([2xi64]*noaliasnocapturenoundefnonnullsret([2xi64])
align8dereferenceable(16)%0,{}* noundefnonnullreadonly%1,i64signext%2,i64signext%3) #0{
top:
%newstruct.sroa.0.0..sroa_idx=getelementptrinbounds[2xi64], [2xi64]*%0,i640,i640
storei64%2,i64*%newstruct.sroa.0.0..sroa_idx,align8
%newstruct.sroa.2.0..sroa_idx1=getelementptrinbounds[2xi64], [2xi64]*%0,i640,i641storei64%3,i64*%newstruct.sroa.2.0..sroa_idx1,align8
retvoid
}
definevoid@julia_LowHighNew_2366([2xi64]*noaliasnocapturenoundefnonnullsret([2xi64])
align8dereferenceable(16)%0,[1xi8]*nocapturenoundefnonnullreadonlyalign1dereferenceable(1)%1,{}* noundefnonnullreadonly%2,i64signext%3,i64signext%4) #0{
top:
%.sroa.025.0..sroa_idx=getelementptrinbounds[2xi64], [2xi64]*%0,i640,i640
storei64%3,i64*%.sroa.025.0..sroa_idx,align8
%.sroa.2.0..sroa_idx26=getelementptrinbounds[2xi64], [2xi64]*%0,i640,i641
storei64%4,i64*%.sroa.2.0..sroa_idx26,align8
retvoid
}
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.
if hop_rate(hop_rates.low, species, site) > acceptance_threshold | ||
return true | ||
else | ||
# compute the real rate. Could have used hop_rates.high as well. |
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 mean we are storing two copies of the hopping constants for the low vs high (or is it aliased)?
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.
Aliased becausedo_copy = false
when initializingLowHigh(hopping_rates)
.Same withrx_rates
.
if rx_rate(rx_rates.low, rx, site) > acceptance_threshold | ||
return true | ||
else | ||
# compute the real rate. Could have used rx_rates.high as well. |
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.
Similar question to above
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.
Same answer -- aliased.
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. |
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).