Skip to content

consider using identity for deepcopy of RGF #98

Closed
@hexaeder

Description

@hexaeder

Is your feature request related to a problem? Please describe.

I use Symbolics to generate code for some components in simulation. Sometimes, it is desired to copy those components. However it is still important to check, whether different components have the same functional behavior, i.e. are derived from the same models. This works with "normal" julia functions:

f = function(du, u)
    du[1] = u[1]^2
    du[2] = u[2]^2
end
f2 = deepcopy(f)
f == f2 # true
f === f2 # true

However, the == and === property is lost on RGFs:

using Symbolics
@variables x y
formulas = [x^2, y^2]
_, f_rgf = build_function(formulas, [x, y]; expression=Val{false})

f_rgf2 = deepcopy(f_rgf)
f_rgf == f_rgf2 # false
f_rgf === f_rgf2 # false

Describe the solution you’d like
I think it would be possible to define deepcopy_internal as stated in the deepcopy docstring to avoid this:

using Symbolics.RuntimeGeneratedFunctions: RuntimeGeneratedFunction
Base.deepcopy_internal(f::RuntimeGeneratedFunction, stackdict::IdDict) = f

This definition aligns the behavior of RGFs with "normal" functions.

Additional context

DISCLAIMER: I don't know the inner workings of RGF. Somebody who knows would need to chime in on that. Is the current behavior actually desired and important? If so, feel free to just close this issue :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions