# JuMP Unable to register the function

**URL:** https://discourse.julialang.org/t/jump-unable-to-register-the-function/124006
**Category:** Optimization (Mathematical)
**Tags:** jump, optimization
**Created:** [December 20, 2024, 4:36am UTC](https://discourse.julialang.org/t/jump-unable-to-register-the-function/124006 "2024-12-20T04:36:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jgr](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jgr](https://discourse.julialang.org/u/jgr)
#### Post date: [December 20, 2024, 4:36am UTC](https://discourse.julialang.org/t/jump-unable-to-register-the-function/124006/1 "2024-12-20T04:36:35Z")

</div>

The function I want to maximize is

```julia
function L(params::Vector{Real}, df::DataFrame, mm::MMParams)
    θ1, α1, β1, D1, N1, ϵ1, θ2, α2, β2, D2, N2, ϵ2, ρ, pA, pF, σ, constant = params
    Π = mm.Π

    y_star_1 = y_start((θ1, α1, β1, D1, N1, ϵ1, ρ, pA, pF))
    y_star_2 = y_start((θ2, α2, β2, D2, N2, ϵ2, ρ, pA, pF))

    lists = unique(df[:, :list])
    L = 0.0

    for firm in lists
        dt = df[df[:, :list] .== firm, :]
        for row in eachrow(dt)
            s = row[:s]
            j = row[:LS]
            i = row[:S]

            if j in 0:2 && i in 1:2
                y_star = (i == 1 ? y_star_1 : y_star_2)
                f_value = logf(s, y_star, σ, constant)
                π_value = Π[j + 1, i + 1]
                L += f_value + log(π_value)
            end
        end
    end
    return L
end

```

I try to register this function

```julia
L_closure = (params...) -> L(collect(params), df, mm)
# Register the function
JuMP.register(
    model,
    :L,
    length(initial_params), # Number of parameters
    L_closure,
    autodiff = true # Enable automatic differentiation
)

```

But I got the error

> Unable to register the function

Anyone knows how to solve this?

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [December 21, 2024, 12:01am UTC](https://discourse.julialang.org/t/jump-unable-to-register-the-function/124006/2 "2024-12-21T00:01:30Z")

</div>

Hi @jgr, I’ve moved this to the optimisation section.

At a guess (I can’t run your code so I can’t confirm), you need `params::Vector{<:Real}` instead of `params::Vector{Real}`. The distinction is subtle, see:

```Julia
julia> x = [1.0, 2.0]
2-element Vector{Float64}:
 1.0
 2.0

julia> x isa Vector{Real}
false

julia> x isa Vector{<:Real}
true

```

If that doesn’t work, you need to ensure that your function can be differentiated with ForwardDiff.jl.

I’d also encourage you to adopt the newer syntax for nonlinear modelling: [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nonlinear/#jump_user_defined_operators)

For details, see [ANN: JuMP v1.15 is released](https://discourse.julialang.org/t/ann-jump-v1-15-is-released/103875)
