JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.35k stars 151 forks source link

linear_expansion does not work on equations involving linear algebra (array variables) #1231

Open dylanede opened 3 weeks ago

dylanede commented 3 weeks ago

It looks like there's no support for array and matrix operations in linear_expansion, e.g. broadcast.

I also have found that the workaround of performing scalarize on everything prior to linear_expansion can be incredibly slow and memory-hungry for moderately sized systems. For example for a particular system of 407 equations in 407 unknowns, @time for scalarizing equations and variables and then calling linear_expansion gives

129.486180 seconds (699.76 M allocations: 55.483 GiB, 8.34% gc time, 0.08% compilation time)

on my machine.

bowenszhu commented 3 weeks ago

I also have found that the workaround of performing scalarize on everything prior to linear_expansion can be incredibly slow and memory-hungry for moderately sized systems.

Thanks for pointing this out and for the PR! I agree this is a performance bottleneck. I have an idea on how to improve this and will aim to have a fix pushed soon this year.