MethodOfLines.jl icon indicating copy to clipboard operation
MethodOfLines.jl copied to clipboard

Discretization of brussellator fails

Open finmod opened this issue 6 months ago • 13 comments

In the two versions of brusselator.jl (test and docs), the discretization cell goes into a loop and never exit

# Method of lines discretization
N = 32

dx = 1 / N
dy = 1 / N

order = 2

discretization = MOLFiniteDifference([x => dx, y => dy], t, approx_order = order)

#MethodOfLines.generate_code(pdesys, discretization)
# Convert the PDE problem into an ODE problem
println("Discretization:")
@time prob = discretize(pdesys, discretization)

time 87 m and counting!

It is advisable to have this "Getting Started example" always in top form otherwise using MOL is a curse.

finmod avatar Jun 24 '25 13:06 finmod

@AayushSabharwal I thought this was fixed on latest releases already?

ChrisRackauckas avatar Jun 24 '25 13:06 ChrisRackauckas

I'll take a look

AayushSabharwal avatar Jun 24 '25 13:06 AayushSabharwal

On MTK#master

396.630006 seconds (4.36 G allocations: 137.717 GiB, 2.21% gc time, 1.41% compilation time: 47% of which was recompilation)

AayushSabharwal avatar Jun 26 '25 06:06 AayushSabharwal

Here is the outcome of a test of brusselator_eq.jl on my notebook. Yes, it works in 144 minutes. This cannot be a gentle or "Getting started" introduction to MOL! Or is there a problem with all these warnings?

Test Summary: | Pass Total Time MOLFiniteDifference Interface | 102 102 5m35.8s 335.806247 seconds (1.36 G allocations: 44.751 GiB, 2.50% gc time, 34.16% compilation time) Discretization: ┌ Warning: The system contains interface boundaries, which are not compatible with system transformation. The system will not be transformed. Please post an issue if you need this feature. └ @ MethodOfLines C:\Users\Denis.julia\packages\MethodOfLines\QMJYo\src\system_parsing\pde_system_transformation.jl:43 1205.361398 seconds (4.94 G allocations: 156.575 GiB, 1.93% gc time, 0.30% compilation time) Solve: 7318.014306 seconds (853.49 M allocations: 32.619 GiB, 0.29% gc time, 94.88% compilation time) WARNING: Method definition brusselator_f(Any, Any, Any) in module ##238 at C:\Users\Denis.julia\packages\MethodOfLines\QMJYo\test\pde_systems\brusselator_eq.jl:18 overwritten at C:\Users\Denis.julia\packages\MethodOfLines\QMJYo\test\pde_systems\brusselator_eq.jl:72. Test Summary: | Pass Total Time MOLFiniteDifference Interface: 2D Brusselator Equation | 1154 1154 144m21.7s 8661.909559 seconds (6.83 G allocations: 219.594 GiB, 0.57% gc time, 80.36% compilation time) Test Summary: | Pass Total Time MOLFiniteDifference Interface: 1D Linear Diffusion, Non-Uniform | 96 96 6m39.0s 399.000078 seconds (1.07 G allocations: 37.390 GiB, 1.92% gc time, 57.19% compilation time) Test Summary: | Broken Total Time MOLFiniteDifference Interface: Advanced Nonlinear Diffusion | 1 1 20.5s 20.518313 seconds (21.37 M allocations: 1.013 GiB, 1.08% gc time, 96.35% compilation time) ┌ Warning: The system contains interface boundaries, which are not compatible with system transformation. The system will not be transformed. Please post an issue if you need this feature. └ @ MethodOfLines C:\Users\Denis.julia\packages\MethodOfLines\QMJYo\src\system_parsing\pde_system_transformation.jl:43

finmod avatar Jun 26 '25 09:06 finmod

The tests aren't the getting started introduction though? And the long execution time issue is fixed on the latest MTK.

AayushSabharwal avatar Jun 26 '25 09:06 AayushSabharwal

For completeness, the Getting Started introduction remains a huge drag to using MOL:

# Method of lines discretization
N = 32

dx = 1 / N
dy = 1 / N

order = 2

discretization = MOLFiniteDifference([x => dx, y => dy], t, approx_order = order)

#MethodOfLines.generate_code(pdesys, discretization)
# Convert the PDE problem into an ODE problem
println("Discretization:")
@time prob = discretize(pdesys, discretization)
26 m

gives this outcome which is still 4x larger thhan your quote above:

[33m[1m┌ [22m[39m[33m[1mWarning: [22m[39mThe system contains interface boundaries, which are not compatib`le with system transformation. The system will not be transformed. Please post an issue if you need this feature.
[33m[1m└ [22m[39m[90m@ MethodOfLines C:\Users\Denis\.julia\packages\MethodOfLines\QMJYo\src\system_parsing\pde_system_transformation.jl:43[39m
1556.288325 seconds (4.94 G allocations: 155.908 GiB, 1.73% gc time, 0.95% compilation time: 59% of which was recompilation)

finmod avatar Jun 26 '25 14:06 finmod

v10.6.0?

ChrisRackauckas avatar Jun 26 '25 14:06 ChrisRackauckas

MTK v9.80.6 and MOL v0.11.8

finmod avatar Jun 26 '25 14:06 finmod

Right, so v9 being slow is known. When I said that this is fixed on the latest MTK, I was referring to v10.6. Some of the performance improvements that make it faster on 10.6 are backported to v9 in https://github.com/SciML/ModelingToolkit.jl/pull/3771 which just merged and will be tagged soon. Note that it probably won't be as fast as v10, because not all of the changes can be backported.

AayushSabharwal avatar Jun 26 '25 15:06 AayushSabharwal

It's also worth noting that performance numbers vary drastically across machines, so my @times likely won't be the same as yours.

AayushSabharwal avatar Jun 26 '25 15:06 AayushSabharwal

Ok got the hint. I am reinstalling MTK#Master and rebuilding everything else around it.

finmod avatar Jun 26 '25 15:06 finmod

If you'd like to try the latest v9, it's available in the backport-v9 branch.

AayushSabharwal avatar Jun 26 '25 15:06 AayushSabharwal

With backport-v9, no notable improvement. I will just wait until MTKv10.6 appears in my status.

finmod avatar Jun 26 '25 16:06 finmod