Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make function registration local #821

Closed
philipbarrett opened this issue Aug 5, 2016 · 1 comment
Closed

Make function registration local #821

philipbarrett opened this issue Aug 5, 2016 · 1 comment
Labels
Category: Nonlinear Related to nonlinear programming Type: Enhancement
Milestone

Comments

@philipbarrett
Copy link

philipbarrett commented Aug 5, 2016

Registering user-defined functions appears to be a global action. This can lead to some undesirable outcomes. For example:

function foo( A::Float64 )
  f(x) = exp( A * x )
  f1(x) = A * exp( A * x )
  f2(x) = A * A * exp( A * x )
      # Function to register
  JuMP.register(:f,1,f1,f2)
      # Registration
  ####
    # Optimization problem here using f
    # Leads to some return statement
  ####
end

# Session code
use1 = foo(2.0)
    # Works fine
use2 = foo(3.0)
    # Gives error "Operator f has already been defined"
use3 = foo(2.0)
    # Also gives the error(!)

Here I want the symbol :f to register a locally-defined JuMP function. But it appears to be global and immutable. So I'd like to request the following features:

  1. If possible, make function registration local.
  2. If this isn't possible, add methods to: a) check that a function is registered, and b) de-register a previously-defined function.

The example above seems like a pretty important one. For starters, it is a way to use one function (here foo) to solve similar problems with differently parameterized objective functions. In addition, the current set-up leads to an error when calling the same function twice (see use1 and use3 above) with no apparent way to check for this (aside from a try-catch block).

Hopefully this isn't too hard to add, and it seems like the payoff would be pretty large. Thanks!

PS. This is based on my similar stackoverflow question here: http://stackoverflow.com/questions/38774351/how-to-check-if-a-user-defined-function-is-already-registered-in-julia-jump

@mlubin
Copy link
Member

mlubin commented Aug 5, 2016

This is a prerequisite for #808. Wouldn't expect it soon though, unless someone steps up and submits some PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Nonlinear Related to nonlinear programming Type: Enhancement
Development

No branches or pull requests

2 participants