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

uniqueness of names #548

Closed
mlubin opened this issue Oct 27, 2018 · 5 comments
Closed

uniqueness of names #548

mlubin opened this issue Oct 27, 2018 · 5 comments

Comments

@mlubin
Copy link
Member

mlubin commented Oct 27, 2018

On the call yesterday we discussed the issue about names for display purposes being different than names that one would want to use as unique lookup keys. I proposed allowing two different names per variable/constraint, a lookup name and a display name. Thinking about it more, this seems too complicated.

New proposal: We allow variables to have arbitrary non-unique names. On lookup, if there are two variables with the same name, we throw an error. That's all.

Pros:

  • This is overall less breaking from 0.18
  • Simple rules
  • We already allow variables to have non-unique lookup names (the empty string), so this removes that exception

Cons:

  • Authors of code that generates JuMP sub-models will have to decide if they prefer simple names that print well or names that are guaranteed to be unique and useful for lookup

@ccoffrin @jd-lara @IainNZ

jump-dev/JuMP.jl#1292

@ccoffrin
Copy link

To clarify, when you say "lookup names", you are talking about string based lookups, correct? In my software the variable refrence is what I will always use as the unique variable id.

Questions:

@mlubin
Copy link
Member Author

mlubin commented Oct 27, 2018

you are talking about string based lookups, correct?

Yes, I mean lookup by string. More precisely, given a string, return the corresponding MOI.VariableIndex or JuMP.VariableRef.

if two variables have a string name, looking them up each by their variable refrence is still fine and does not generate an error?

Correct. The MOI.VariableIndex or JuMP.VariableRef is the ultimate identifier of the variable.

what are the implications of using non-unique names for https://github.com/odow/MathOptFormat.jl?

MOF or LP or MPS writers will have to generate unique names (this is already the case because we allow blank names). So the mapping from MOI model to the file formats won't be 1-1. OTOH, if you read an MOF/LP/MPS file into an MOI model you'll be able to look up the variables in the model using their names in the file.

@odow
Copy link
Member

odow commented Oct 27, 2018

Authors of code that generates JuMP sub-models will have to decide if they prefer simple names that print well or names that are guaranteed to be unique and useful for lookup

I think we should encourage authors of JuMP extensions/submodels/etc to use anonymous variables with a meaningful print name, and provide an external way of accessing the variables if required. For example, they can bundle the references into the JuMP extension dictionary with model.ext[:power_models_jl]

@ccoffrin
Copy link

Based on clarifications, I think this is a good solution. The semantics are nearly the same as JuMP v0.18, which has been working quite well for our group thus far.

@odow, that is basically the convention that we are currently using.

mlubin added a commit that referenced this issue Oct 27, 2018
Throw an error only when looking up a string that corresponds to multiple
variables.

Closes #548
Closes jump-dev/JuMP.jl#1292
@jd-lara
Copy link
Contributor

jd-lara commented Oct 28, 2018

I think the alternative works. For reference, this will create the following use cases:

  • Use variable names and internal look-up for single models not meant to interact with other JuMP models. This can be done with JuMP.VariableRef. Variable names can be used for printing.
  • Use anonymous variables when developing extension packages that build on top of JuMP like PowerSimulations and PowerModels. Exploit model.ext for those purposes or use an external dict with the references. This cases will require a variable name for printing.

@blegat blegat mentioned this issue Oct 28, 2018
mlubin added a commit that referenced this issue Oct 31, 2018
* Allow duplicate variable names

Throw an error only when looking up a string that corresponds to multiple
variables.

Closes #548
Closes jump-dev/JuMP.jl#1292

* more test coverage

* share build_name_to_con_map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants