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

Friendlier syntax for `KernelFunctionOperation`?

Open glwagner opened this issue 3 years ago • 6 comments

Wondering if it'd be nicer to write

Ri_op = KernelFunctionOperation{Center, Center, Center}(Riᶜᶜᶜ, grid, velocities, tracers.b)

rather than the current syntax

Ri_op = KernelFunctionOperation{Center, Center, Center}(Riᶜᶜᶜ, grid, computed_dependencies=(velocities, tracers.b))

I think we can document the fact that the "dependencies" (really, arguments to the kernel function) are computed. I'm actually not sure if it's so common to nest fields that require computation into a KernelFunctionOperation. It seems like that's maybe an edge case and most of the time we are just using ordinary numbers, fields, etc as "computed dependencies" and in that case it's silly to call them "computed dependencies".

@tomchor you have used this the most, what do you think?

glwagner avatar Mar 13 '22 12:03 glwagner

Looks nicer to me.

francispoulin avatar Mar 13 '22 15:03 francispoulin

most of the time we are just using ordinary numbers, fields, etc as "computed dependencies" and in that case it's silly to call them "computed dependencies".

My impression is that that's why the parameters argument existed (but please correct me if I'm wrong). In the current way computed_dependencies and parameters clearly indicate what's what (and what happens behind the scenes). So on that note, personally, I like that computed_dependencies keeps things explicit.

Also, I can't say for other people, but I frequently pass fields that require computation to KFO. (Usually passing u-U to calculate fluctuations, etc.)

tomchor avatar Mar 14 '22 01:03 tomchor

What if we get rid of parameters and computed_dependencies, and call compute! on all the arguments?

glwagner avatar Mar 14 '22 03:03 glwagner

What if we get rid of parameters and computed_dependencies, and call compute! on all the arguments?

That'd work for me. Would that have the same performance or would it add some overhead?

tomchor avatar Mar 15 '22 23:03 tomchor

Probably the same because compute! is a no-op for most objects?

glwagner avatar Mar 16 '22 01:03 glwagner

If it's the same, then I'm okay calling compute on everything and don't separate between parameters and computed_dependencies anymore. I think we gotta make that clear on the docstring though!

tomchor avatar Mar 16 '22 13:03 tomchor

Done

glwagner avatar Mar 22 '23 17:03 glwagner