Skip to content
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 tests for indexing problem with a parameter #387

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ end
# when setindex! is used.
function Base.setindex!(prob::JumpProblem, args...; kwargs...)
SciMLBase.___internal_setindex!(prob.prob, args...; kwargs...)
if using_params(prob.massaction_jump)
update_parameters!(prob.massaction_jump, prob.prob.p)
end

# since parameters are no longer allowed to be mutated and the preceding will error this
# isn't needed
# if using_params(prob.massaction_jump)
# update_parameters!(prob.massaction_jump, prob.prob.p)
# end
Comment on lines +126 to +130
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setp will still allow for issues, along with manual mutation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need a custom dispatch on it then to update MassActionJumps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, @AayushSabharwal can probably help with that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, thanks!

Copy link
Member

@AayushSabharwal AayushSabharwal Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have set_parameter! in SII which is used by setp internally, and can be implemented to do other bookkeeping actions when setp is used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AayushSabharwal, can you add the needed dispatches to that when parameters get modified, i.e. something like what we had before when modifying a problem:

if using_params(prob.massaction_jump)
    update_parameters!(prob.massaction_jump, prob.prob.p)
end

Alternatively, @ChrisRackauckas do we want to put this on users (since this could be expensive, so a faster workflow is to only call it once all parameter modifications are finished)? That does leave a gotcha someone could encounter unless they carefully read the docs (which is why the previous behavior here always updated directly after modifying a parameter).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we do put calling the jump update function on users currently when modifying integrators within callbacks, so perhaps it isn't unreasonable to do that.

end

# when getindex is used.
Expand Down
8 changes: 4 additions & 4 deletions test/jprob_symbol_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ 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])
g = DiscreteFunction((du, u, p, t) -> nothing; sys = SymbolicIndexingInterface.SymbolCache([:a, :b], [:p1, :p2], :t)
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved
dprob = DiscreteProblem(g, [0, 10], (0.0, 10.0), [1.0, 2.0])
jprob = JumpProblem(dprob, Direct(), crj1, crj2)

# runs the tests
@test jprob[:a] == 0
@test jprob[:b] == 10
@test jprob[:p1] == 1.0
@test jprob[:p2] == 2.0

# tests for setindex (e.g. `jprob[:a] = 10`) not possible, this requires the problem to have a .f.sys filed.,
# these are no longer supported by SciMLBase
@test getp(jprob,:p1)(jprob) == 1.0
@test getp(jprob,:p2)(jprob) == 2.0
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved
Loading