-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #408 from isaacsas/indexing_fixes
Indexing fixes
- Loading branch information
Showing
7 changed files
with
55 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
# prepares the problem | ||
using JumpProcesses, Test | ||
using JumpProcesses, Test, SymbolicIndexingInterface | ||
rate1(u, p, t) = p[1] | ||
rate2(u, p, t) = p[2] | ||
affect1!(integ) = (integ.u[1] += 1) | ||
affect2!(integ) = (integ.u[2] += 1) | ||
crj1 = ConstantRateJump(rate1, affect1!) | ||
crj2 = ConstantRateJump(rate2, affect2!) | ||
g = DiscreteFunction((du, u, p, t) -> nothing; syms = [:a, :b], paramsyms = [:p1, :p2]) | ||
maj = MassActionJump([[1 => 1], [1 => 1]], [[1 => -1], [1 => -1]]; param_idxs = [1,2]) | ||
g = DiscreteFunction((du, u, p, t) -> nothing; | ||
sys = SymbolicIndexingInterface.SymbolCache([:a, :b], [:p1, :p2], :t)) | ||
dprob = DiscreteProblem(g, [0, 10], (0.0, 10.0), [1.0, 2.0]) | ||
jprob = JumpProblem(dprob, Direct(), crj1, crj2) | ||
jprob = JumpProblem(dprob, Direct(), crj1, crj2, maj) | ||
|
||
# runs the tests | ||
# test basic querying of u0 and p | ||
@test jprob[:a] == 0 | ||
@test jprob[:b] == 10 | ||
@test jprob[:p1] == 1.0 | ||
@test jprob[:p2] == 2.0 | ||
@test getp(jprob,:p1)(jprob) == 1.0 | ||
@test getp(jprob,:p2)(jprob) == 2.0 | ||
@test jprob.ps[:p1] == 1.0 | ||
@test jprob.ps[:p2] == 2.0 | ||
|
||
# tests for setindex (e.g. `jprob[:a] = 10`) not possible, this requires the problem to have a .f.sys filed., | ||
# test updating u0 | ||
jprob[:a] = 20 | ||
@test jprob[:a] == 20 | ||
|
||
# test mass action jumps update with parameter mutation in problems | ||
@test jprob.massaction_jump.scaled_rates[1] == 1.0 | ||
jprob.ps[:p1] = 3.0 | ||
@test jprob.ps[:p1] == 3.0 | ||
@test jprob.massaction_jump.scaled_rates[1] == 3.0 | ||
p1setter = setp(jprob, [:p1, :p2]) | ||
p1setter(jprob, [4.0, 10.0]) | ||
@test jprob.ps[:p1] == 4.0 | ||
@test jprob.ps[:p2] == 10.0 | ||
@test jprob.massaction_jump.scaled_rates == [4.0, 10.0] |