Skip to content

Commit fa585c4

Browse files
authored
Merge pull request #339 from JuliaDynamics/hw/fixes
small fixes for pd tests
2 parents 3c3ac42 + 17d59d6 commit fa585c4

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# NetworkDynamics Release Notes
22

3+
## v0.10.15 Changelog
4+
- small fixes, mainly for PowerDynamics tests ([#339](https://github.com/JuliaDynamics/NetworkDynamics.jl/pull/339))
5+
36
## v0.10.14 Changelog
47
- Add `assume_io_coupling` parameter to MTK `VertexModel` and `EdgeModel` constructors ([#332](https://github.com/JuliaDynamics/NetworkDynamics.jl/pull/332))
58
- New optional parameter forces MTK to consider direct dependency chains from outputs to inputs

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ authors = ["Frank Hellmann <[email protected]>, Michael Lindner <michaelli
77
projects = ["test", "benchmark"]
88

99
[deps]
10+
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
1011
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
1112
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
1213
Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
@@ -58,6 +59,7 @@ NetworkDynamicsSparsityExt = ["SparseConnectivityTracer"]
5859
NetworkDynamicsSymbolicsExt = ["Symbolics", "MacroTools"]
5960

6061
[compat]
62+
ADTypes = "1"
6163
Accessors = "0.1.43"
6264
Adapt = "4.0.4"
6365
ArgCheck = "2.3.0"

ext/NetworkDynamicsMTKExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function _get_metadata(sys, name, alldefaults, sysguesses)
238238
if !endswith(string(name), "ˍt") # known for "internal" derivatives
239239
@warn "Could not extract metadata for $name $(e.msg)"
240240
end
241-
return nt
241+
return md
242242
end
243243
if haskey(alldefaults, sym)
244244
def = alldefaults[sym]

src/NetworkDynamics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using DiffEqCallbacks: DiffEqCallbacks
2525
using MacroTools: postwalk, @capture
2626
using ConstructionBase: ConstructionBase
2727
using Accessors: Accessors
28+
using ADTypes: AutoForwardDiff
2829

2930
@static if VERSION v"1.11.0-0"
3031
using Base: AnnotatedIOBuffer, AnnotatedString

src/initialization.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,10 @@ The function solves a nonlinear problem to find values for all free variables/pa
498498
- `t`: Time at which to solve for steady state. Only relevant for components with explicit time dependency.
499499
- `tol`: Tolerance for the residual of the initialized model (defaults to `1e-10`). Init throws error if resid ≥ tol.
500500
- `residual`: Optional `Ref{Float64}` which gets the final residual of the initialized model.
501-
- `alg=nothing`: Nonlinear solver algorithm (defaults to NonlinearSolve.jl default with QR factorization, since init problems tend to be ill-conditioned.)
501+
- `alg_kwargs=(;)`: Additional keyword arguments passed to the nonlinear solver algorithm constructor
502+
- `alg=FastShortcutNLLSPolyalg(; linsolve=QRFactorization(), autodiff=AutoForwardDiff(), alg_kwargs...)`
503+
504+
Nonlinear solver algorithm (defaults to NonlinearSolve.jl default with QR factorization, since init problems tend to be ill-conditioned.)
502505
- `solve_kwargs=(;)`: Additional keyword arguments passed to the SciML `solve` function
503506
- `io=stdout`: IO stream for printing information
504507
@@ -530,7 +533,8 @@ function initialize_component(cf;
530533
# internal keywords to "return" the final defaults/guesses after applying formulas
531534
_final_defaults=nothing,
532535
_final_guesses=nothing,
533-
alg=nothing,
536+
alg_kwargs=(;),
537+
alg=FastShortcutNLLSPolyalg(; linsolve=QRFactorization(), autodiff=AutoForwardDiff(), alg_kwargs...),
534538
solve_kwargs=(;),
535539
io=stdout,
536540
kwargs...)
@@ -539,10 +543,6 @@ function initialize_component(cf;
539543
@warn "Passing `kwargs` to `initialize_component(!)` is deprecated. Use `alg` and `solve_kwargs=(; kw=val)` instead."
540544
end
541545

542-
if alg == nothing
543-
alg = FastShortcutNLLSPolyalg(linsolve=QRFactorization())
544-
end
545-
546546
defaults = isnothing(default_overrides) ? defaults : merge(defaults, default_overrides)
547547
guesses = isnothing(guess_overrides) ? guesses : merge(guesses, guess_overrides)
548548
bounds = isnothing(bound_overrides) ? bounds : merge(bounds, bound_overrides)

src/symbolicindexing.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct NWState{U,P,T,NW<:Network}
109109
t::T
110110
function NWState(thing, uflat::AbstractVector, p=nothing, t=nothing)
111111
nw = extract_nw(thing)
112+
@argcheck length(uflat) == dim(nw) "Length of uflat ($(length(uflat))) does not match number of states in network ($(dim(nw)))."
112113
_p = p isa Union{NWParameter,Nothing} ? p : NWParameter(nw, p)
113114
s = new{typeof(uflat),typeof(_p),typeof(t),typeof(nw)}(nw,uflat,_p,t)
114115
@argcheck isnothing(p) || s.nw === s.p.nw

test/AD_test.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ end
3232
# jacobian(fx, AutoReverseDiff(), x0)
3333
# jacobian(fx, AutoFiniteDiff(), x0)
3434
# jacobian(fx, AutoMooncake(), x0)
35-
@test_broken jacobian(fx, AutoEnzyme(; mode=EnzymeCore.Forward, function_annotation=EnzymeCore.Duplicated), x0)
36-
@test_broken jacobian(fx, AutoEnzyme(; mode=EnzymeCore.Reverse, function_annotation=EnzymeCore.Duplicated), x0)
37-
@test_broken jacobian(fx, AutoEnzyme(; mode=Enzyme.set_runtime_activity(EnzymeCore.Forward), function_annotation=EnzymeCore.Duplicated), x0)
38-
@test_broken jacobian(fx, AutoEnzyme(; mode=Enzyme.set_runtime_activity(EnzymeCore.Reverse), function_annotation=EnzymeCore.Duplicated), x0)
35+
# @test_broken jacobian(fx, AutoEnzyme(; mode=EnzymeCore.Forward, function_annotation=EnzymeCore.Duplicated), x0)
36+
# @test_broken jacobian(fx, AutoEnzyme(; mode=EnzymeCore.Reverse, function_annotation=EnzymeCore.Duplicated), x0)
37+
# @test_broken jacobian(fx, AutoEnzyme(; mode=Enzyme.set_runtime_activity(EnzymeCore.Forward), function_annotation=EnzymeCore.Duplicated), x0)
38+
# @test_broken jacobian(fx, AutoEnzyme(; mode=Enzyme.set_runtime_activity(EnzymeCore.Reverse), function_annotation=EnzymeCore.Duplicated), x0)
3939

4040
fp = function(p)
4141
dx = similar(p,length(x0))
@@ -46,10 +46,10 @@ end
4646
# jacobian(fp, AutoReverseDiff(), pflat(p0))
4747
# jacobian(fp, AutoFiniteDiff(), pflat(p0))
4848
# jacobian(fp, AutoMooncake(), pflat(p0))
49-
@test_broken jacobian(fp, AutoEnzyme(; mode=EnzymeCore.Forward, function_annotation=EnzymeCore.Duplicated), pflat(p0))
50-
@test_broken jacobian(fp, AutoEnzyme(; mode=EnzymeCore.Reverse, function_annotation=EnzymeCore.Duplicated), pflat(p0))
51-
@test_broken jacobian(fp, AutoEnzyme(; mode=Enzyme.set_runtime_activity(EnzymeCore.Forward), function_annotation=EnzymeCore.Duplicated), pflat(p0))
52-
@test_broken jacobian(fp, AutoEnzyme(; mode=Enzyme.set_runtime_activity(EnzymeCore.Reverse), function_annotation=EnzymeCore.Duplicated), pflat(p0))
49+
# @test_broken jacobian(fp, AutoEnzyme(; mode=EnzymeCore.Forward, function_annotation=EnzymeCore.Duplicated), pflat(p0))
50+
# @test_broken jacobian(fp, AutoEnzyme(; mode=EnzymeCore.Reverse, function_annotation=EnzymeCore.Duplicated), pflat(p0))
51+
# @test_broken jacobian(fp, AutoEnzyme(; mode=Enzyme.set_runtime_activity(EnzymeCore.Forward), function_annotation=EnzymeCore.Duplicated), pflat(p0))
52+
# @test_broken jacobian(fp, AutoEnzyme(; mode=Enzyme.set_runtime_activity(EnzymeCore.Reverse), function_annotation=EnzymeCore.Duplicated), pflat(p0))
5353

5454
scenarios = [Scenario{:jacobian, :in}(fx, x0; res1=jacobian(fx, AutoFiniteDiff(), x0)) ,
5555
Scenario{:jacobian, :in}(fp, pflat(p0); res1=jacobian(fp, AutoFiniteDiff(), pflat(p0)))]

0 commit comments

Comments
 (0)