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

Check for supported operators in DynamicExpressionsSymbolicExt is too restrictive?

Open nic-barbara opened this issue 8 months ago • 3 comments

Hi @MilesCranmer, poking through the weeds a bit here but I noticed you've added the following check in v1.10.4 and v2.5.0 when converting expressions to symbolic forms:

https://github.com/SymbolicML/DynamicExpressions.jl/blob/29ebdab9123f35ee5820799957f39612850baf57/ext/DynamicExpressionsSymbolicUtilsExt.jl#L108

Shouldn't the package still allow for custom operators that are formed from combinations of the SUPPORTED_OPS? E.g., if we had a unary operator pow2(x) = x*x. This used to work fine for me in v1.10.3, but now in v1.10.4 I get the intended error from the above if statement.

Thanks in advance!

nic-barbara avatar Mar 13 '26 05:03 nic-barbara

Hm, yeah, good point. I will think more if there's a way to get that behavior back. It was partially to upgrade to the new SymbolicUtils.jl version. But I guess it doesn't completely make sense to prevent tracing custom operators, because index_functions is there to allow for preventing that.

(@MilesCranmerBot can you please investigate this and make a draft PR if it looks fixable?)

MilesCranmer avatar Mar 13 '26 14:03 MilesCranmer

Investigated and this looks fixable. I opened a draft PR with a concrete change and tests:

  • Draft PR: https://github.com/SymbolicML/DynamicExpressions.jl/pull/171

Summary of fix:

  • When index_functions=false, custom operators are now traced if they can operate on symbolic inputs (instead of being rejected up front).
  • index_functions=true behavior is unchanged for preserving operator identity during round-trips.
  • We still raise a clear unsupported-operation error when tracing fails with MethodError.

I also ran the full local test suite (Pkg.test()), and it passed.

MilesCranmerBot avatar Mar 13 '26 14:03 MilesCranmerBot

Quick fix for those interested in the mean time:

ext = Base.get_extension(
    DynamicExpressions, 
    :DynamicExpressionsSymbolicUtilsExt
)
custom_ops = (..., ...)
@eval ext const SUPPORTED_OPS = (
    SUPPORTED_OPS..., 
    $(custom_ops...)
)

nic-barbara avatar Mar 15 '26 22:03 nic-barbara