Skip to content

Commit 286ef24

Browse files
committed
test: add tests for macro compatibility
1 parent fc9f1e7 commit 286ef24

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

test/macro.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using ModelingToolkit, Symbolics
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
3+
using OrdinaryDiffEq
4+
using ModelingToolkitNeuralNets
5+
using ModelingToolkitStandardLibrary.Blocks
6+
using Lux
7+
8+
@mtkmodel Friction_UDE begin
9+
@variables begin
10+
y(t) = 0.0
11+
end
12+
@parameters begin
13+
Fu
14+
end
15+
@components begin
16+
nn_in = RealInputArray(nin = 1)
17+
nn_out = RealOutputArray(nout = 1)
18+
end
19+
@equations begin
20+
D(y) ~ Fu - nn_in.u[1]
21+
y ~ nn_out.u[1]
22+
end
23+
end
24+
25+
@mtkmodel TestFriction_UDE begin
26+
@components begin
27+
friction_ude = Friction_UDE(Fu = 120.0)
28+
nn = NeuralNetworkBlock(n_input = 1, n_output = 1)
29+
end
30+
@equations begin
31+
connect(friction_ude.nn_in, nn.output)
32+
connect(friction_ude.nn_out, nn.input)
33+
end
34+
end
35+
36+
@mtkbuild sys = TestFriction_UDE()
37+
38+
prob = ODEProblem(sys, [], (0, 1.0), [])
39+
sol = solve(prob, Rodas4())
40+
41+
@test SciMLBase.successful_retcode(sol)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ using SafeTestsets
55
@testset verbose=true "ModelingToolkitNeuralNets.jl" begin
66
@safetestset "QA" include("qa.jl")
77
@safetestset "Basic" include("lotka_volterra.jl")
8+
@safetestset "MTK model macro compatibility" include("macro.jl")
89
end

0 commit comments

Comments
 (0)