# Unexpectedly Large Compile Time Using MethodOfLines.jl

**URL:** <https://discourse.julialang.org/t/unexpectedly-large-compile-time-using-methodoflines-jl/105212>\
**Category:** Numerics\
**Created:** [October 20, 2023, 1:57am UTC](https://discourse.julialang.org/t/unexpectedly-large-compile-time-using-methodoflines-jl/105212 "2023-10-20T01:57:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aharbick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aharbick/32/202619_2.png) [@aharbick](https://discourse.julialang.org/u/aharbick)\
**Post date:** [October 20, 2023, 1:57am UTC](https://discourse.julialang.org/t/unexpectedly-large-compile-time-using-methodoflines-jl/105212/1 "2023-10-20T01:57:15Z")

</div>

So I am trying to use the MethodOfLines package to solve some equations which are somewhat similar to 2D diffusion equations. As a starting point, I have modified the heat equation example from the documentation to work in 2D, here is my code:

```julia
module Diffusion2D

using OrdinaryDiffEq, ModelingToolkit, MethodOfLines, DomainSets
# Parameters, variables, and derivatives
@parameters t x y
@variables u(..)
Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2
Dy = Differential(y)
Dyy = Differential(y)^2

# 1D PDE and boundary conditions
eq = Dt(u(t, x, y)) ~ 0.1*(Dxx(u(t, x, y)) + Dyy(u(t, x, y)))
bcs = [u(0, x, y) ~ sin(2*pi*x) * sin(2*pi*y),
        u(t, 0, y) ~ 0.0,
        u(t, 1, y) ~ 0.0,
        u(t, x, 0) ~ 0.0,
        u(t, x, 1) ~ 0.0]
 
# Space and time domains
domains = [t ∈ Interval(0.0, 0.5),
        x ∈ Interval(0.0, 1.0),
        y ∈ Interval(0.0, 1.0)]

# PDE system
@named pdesys = PDESystem(eq, bcs, domains,[t, x, y],[u(t, x, y)])

# Method of lines discretization
dx = 0.01
dy = 0.01
order = 2
discretization = MOLFiniteDifference([x => dx, y => dy],t, approx_order=order)

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys, discretization)

# Solve ODE problem
@time sol = solve(prob, Tsit5(), saveat=0.01)

end

```

This code seems to work correctly and it gives the right solution, and once it’s been compiled, the solve step runs in ~140 seconds typically, which is within reason for the dx/dy I am using. The main issue is that the first time I run the code, the solve step typically takes ~6000 seconds to compile and run (it was even longer than this before I put it all in a module). This strikes me as an unusually large compile time, have I made a mistake which is causing this issue? Or otherwise is there ways I can optimize the compile time? If it’s relevant, I am running this code inside a Jupyter notebook. Thanks!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 22, 2023, 5:09pm UTC](https://discourse.julialang.org/t/unexpectedly-large-compile-time-using-methodoflines-jl/105212/2 "2023-10-22T17:09:01Z")

</div>

The current codegen of MethodOfLines uses a scalarization which leads to long compile times. This is something that is being addressed by JuliaSimCompiler:

> **[Home · JuliaSimCompiler.jl](https://help.juliahub.com/juliasimcompiler/dev/)**
>
> Documentation for JuliaSimCompiler.jl.

We will demonstrate this in the near future.

---

<div class="post-metadata">

**Author:** ![aharbick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aharbick/32/202619_2.png) [@aharbick](https://discourse.julialang.org/u/aharbick)\
**Post date:** [October 23, 2023, 5:42pm UTC](https://discourse.julialang.org/t/unexpectedly-large-compile-time-using-methodoflines-jl/105212/3 "2023-10-23T17:42:53Z")

</div>

Ah I see, thanks for the response! Is there currently a way to convert PDESystems to IRSystems in the same way that is done with the ODESystem used in the example on the JuliaSimCompiler page (or at least achieve the same effect)? I tried modifying my above code to add:

```julia
...

@named pdesys = PDESystem(eq, bcs, domains,[t, x, y],[u(t, x, y)])

using JuliaSimCompiler
pdesys_ir = IRSystem(pdesys)

...

```

but it seems that IRSystem() does not currently have a method for PDESystem.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 28, 2023, 11:07am UTC](https://discourse.julialang.org/t/unexpectedly-large-compile-time-using-methodoflines-jl/105212/4 "2023-10-28T11:07:10Z")

</div>

There is an extension being created so that loading JuliaSimCompiler will make it automatically use `IRSystem`. These are updates that will be demonstrated in the near future.
