Closed KarlisFre closed 6 months ago
It looks like the step
function is being traced every time because the velocity
boundary varies each time. I'll look into it.
A simple workaround would be to pass the boundary condition value as a tensor and set the boundary condition inside the function.
Changing the boundary behavior would be a major patch, so it will have to wait. In the meantime, here is an implementation of the workaround I mentioned:
from phi.tf.flow import *
@math.jit_compile
def step(velocity: Field, wind: Tensor):
print("Tracing step()")
velocity = velocity.with_extrapolation({'x': wind, 'y': ZERO_GRADIENT})
velocity, pressure = fluid.make_incompressible(velocity)
return velocity
for i in range(100):
wind = vec(x=math.random_uniform(), y=0)
velocity = StaggeredGrid((0,0), {'x': 0, 'y': ZERO_GRADIENT}, x=100, y=100, bounds=Box(x=100, y=100))
print(velocity)
step(velocity, wind)
Hi, Extrapolations are not treated correctly in jit-compile. If I run this program
It gives a warning and runs very slowly:
WARNING: tensorflow:5 out of the last 5 calls to <function JitFunction