-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
drop scalarizing #1052
Merged
Merged
drop scalarizing #1052
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6dde4d6
try dropping scalarizing
isaacsas 3776534
don't assume things are Nums
isaacsas e517185
remove debug printing
isaacsas d769f5a
more debug prints
isaacsas 745f449
start fixing tests
isaacsas 871d3da
remove shows
isaacsas ad58d36
more test fixes
isaacsas f7e68f7
disable broken tests
isaacsas bac1091
remove scalarizing of parameters in macro
isaacsas 6467291
make scalarizing a keyword
isaacsas 2c904fb
format
isaacsas 55d8e48
remove dropped code
isaacsas 2c1a46f
fix another test
isaacsas 9e2240f
fix doc issue
isaacsas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,17 +40,18 @@ rxs = [Reaction(k[1], nothing, [A]), # 0 -> A | |
Reaction(k[19] * t, [A], [B]), # A -> B with non constant rate. | ||
Reaction(k[20] * t * A, [B, C], [D], [2, 1], [2]), # 2A +B -> 2C with non constant rate. | ||
] | ||
@named rs = ReactionSystem(rxs, t, [A, B, C, D], k) | ||
@named rs = ReactionSystem(rxs, t, [A, B, C, D], [k]) | ||
rs = complete(rs) | ||
odesys = complete(convert(ODESystem, rs)) | ||
sdesys = complete(convert(SDESystem, rs)) | ||
|
||
# Hard coded ODE rhs. | ||
function oderhs(u, k, t) | ||
function oderhs(u, kv, t) | ||
A = u[1] | ||
B = u[2] | ||
C = u[3] | ||
D = u[4] | ||
k = kv[1] | ||
du = zeros(eltype(u), 4) | ||
du[1] = k[1] - k[3] * A + k[4] * C + 2 * k[5] * C - k[6] * A * B + k[7] * B^2 / 2 - | ||
k[9] * A * B - k[10] * A^2 - k[11] * A^2 / 2 - k[12] * A * B^3 * C^4 / 144 - | ||
|
@@ -68,11 +69,12 @@ function oderhs(u, k, t) | |
end | ||
|
||
# SDE noise coefs. | ||
function sdenoise(u, k, t) | ||
function sdenoise(u, kv, t) | ||
A = u[1] | ||
B = u[2] | ||
C = u[3] | ||
D = u[4] | ||
k = kv[1] | ||
G = zeros(eltype(u), length(k), length(u)) | ||
z = zero(eltype(u)) | ||
|
||
|
@@ -109,11 +111,12 @@ end | |
|
||
# Defaults test. | ||
let | ||
def_p = [ki => float(i) for (i, ki) in enumerate(k)] | ||
kvals = Float64.(1:length(k)) | ||
def_p = [k => kvals] | ||
def_u0 = [A => 0.5, B => 1.0, C => 1.5, D => 2.0] | ||
defs = merge(Dict(def_p), Dict(def_u0)) | ||
|
||
@named rs = ReactionSystem(rxs, t, [A, B, C, D], k; defaults = defs) | ||
@named rs = ReactionSystem(rxs, t, [A, B, C, D], [k]; defaults = defs) | ||
rs = complete(rs) | ||
odesys = complete(convert(ODESystem, rs)) | ||
sdesys = complete(convert(SDESystem, rs)) | ||
|
@@ -126,15 +129,11 @@ let | |
defs | ||
|
||
u0map = [A => 5.0] | ||
pmap = [k[1] => 5.0] | ||
kvals[1] = 5.0 | ||
pmap = [k => kvals] | ||
prob = ODEProblem(rs, u0map, (0, 10.0), pmap) | ||
@test prob.ps[k[1]] == 5.0 | ||
@test prob.u0[1] == 5.0 | ||
u0 = [10.0, 11.0, 12.0, 13.0] | ||
ps = [float(x) for x in 100:119] | ||
prob = ODEProblem(rs, u0, (0, 10.0), ps) | ||
@test [prob.ps[k[i]] for i in 1:20] == ps | ||
@test prob.u0 == u0 | ||
Comment on lines
-133
to
-137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are not appropriate inputs since they aren't mappings, hence I removed them. |
||
end | ||
|
||
### Check ODE, SDE, and Jump Functions ### | ||
|
@@ -181,7 +180,7 @@ let | |
Reaction(k[19] * t, [D], [E]), # D -> E with non constant rate. | ||
Reaction(k[20] * t * A, [D, E], [F], [2, 1], [2]), # 2D + E -> 2F with non constant rate. | ||
] | ||
@named rs = ReactionSystem(rxs, t, [A, B, C, D, E, F], k) | ||
@named rs = ReactionSystem(rxs, t, [A, B, C, D, E, F], [k]) | ||
rs = complete(rs) | ||
js = complete(convert(JumpSystem, rs)) | ||
|
||
|
@@ -193,7 +192,7 @@ let | |
@test all(map(i -> typeof(equations(js)[i]) <: JumpProcesses.VariableRateJump, vidxs)) | ||
|
||
p = rand(rng, length(k)) | ||
pmap = parameters(js) .=> p | ||
pmap = [k => p] | ||
u0 = rand(rng, 2:10, 6) | ||
u0map = unknowns(js) .=> u0 | ||
ttt = rand(rng) | ||
|
@@ -868,11 +867,9 @@ end | |
let | ||
@species (A(t))[1:20] | ||
using ModelingToolkit: value | ||
@test isspecies(value(A)) | ||
@test isspecies(value(A[2])) | ||
Av = value.(ModelingToolkit.scalarize(A)) | ||
@test isspecies(Av[2]) | ||
@test isequal(value(Av[2]), value(A[2])) | ||
Av = value(A) | ||
@test isspecies(Av) | ||
@test all(i -> isspecies(Av[i]), 1:length(Av)) | ||
end | ||
|
||
# Test mixed models are formulated correctly. | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@TorkelE I modified this as I think it makes more sense to disallow including observable variables in the unknowns, and to instead give users an error (rather than filtering them out). This also seems less likely to lead to user code bugs where a user thinks something is an unknown but it is implicitly an observable.