Hello everyone! I am studying MSc Mechatronics and currently working on my scientific project. It is regarding making the Julia code of 1D Heat equation faster. With this message, I have also attached the Julia source code. I had some ideas which I can implement but unsure of that. I have listed them below. I request everyone to enlighten me whether I am going in the right direction. Your ideas and suggestions are also most welcomed.
(1) While defining the system matrix and matrix A, maybe I can use “Staticarrays.jl” instead of “spdiagm”. Is it possible? If yes, how can I implement it?
(2) Searching for other optimizers instead of “Ipopt”.
(3) Can I use “Import Ipopt.optimizer” instead of using the whole library in the code? (Using whole library may occupy a lot more space and can also make the program slower to run).
Thank you for your time and I hope to receive suggestions and ideas!
I think you should profile the code to see where the bottlenecks are. Unless the execution is really quick, (3) is probably irrelevant. (1) may or may not make any difference.
For N = 11 you can probably either use StaticArrays or just normal vectors! Sparse matrices will only slow down things here.
(I don’t know what the scope of your project is, but PDE constrained optimisation is a big topic with very elegant and useful algorithms to compute the gradients faster with so-called adjoint equations.)
Two recommendations: first, carefully read and apply the performance tips, particularly the admonition to avoid non-constant global variables. Second, please share your code as text wrapped in triple backticks so other users can easily read and copy-paste it (see here).
I mean, this is just a generally inefficient algorithm for solving the heat equation. If you’re really looking to speed it up, you might want to try starting with a more efficient algorithm, like writing it in Fourier space and just doing a diagonal solve.
The suggestions for static arrays are unlikely to help due to the way JuMP constructs problems. From a purely JuMP perspective, the formulation looks okay.
Given the formulation, what makes you think it is slow? Ipopt is pretty good for this sort of stuff. As Chris says, there are alternate algorithmic approaches that may be more efficient.
Thank you for your message. Actually it takes around 12-15 minutes to get the result and graphs after running this code. I need to reduce the program execution time and that is my task.
Hello Chris. Thank you for your message. What specifically makes this inefficient? Is this the current Euler algorithm that is used in the code? Can you please help me how can I write this code using Fourier space and solving the diagonals?
I modified the program using StaticArrays, but it seems it is not making a significant impact on the speed. I am more convinced that I will have to change the Ipopt optimzer. Can you suggest efficient optimizers rather than Ipopt?