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

Variable indexed by Any #1050

Closed
emma58 opened this issue Jun 4, 2019 · 3 comments
Closed

Variable indexed by Any #1050

emma58 opened this issue Jun 4, 2019 · 3 comments

Comments

@emma58
Copy link
Contributor

emma58 commented Jun 4, 2019

It came as a bit of a surprise to me that m.maybe = Var(Any) throws an error:
RuntimeError: Cannot iterate over abstract Set 'Any' before it has been constructed (initialized).

m.maybe=Var(Any, dense=False) works as expected, which makes some sense after digging into the code. But it seems like this is something that should at least be documented, especially since this is unique to indexing a Var by Any. (And I think this is still a reasonable thing to do since VarList does not give you control over the names of the keys.)

@blnicho
Copy link
Member

blnicho commented Jun 4, 2019

It looks like this was partially documented in an old rst file that was lost during the documentation reorganization (https://github.com/Pyomo/pyomo/blob/cc58252fca1bc489789527038ea4a1c290b6b726/doc/attic/old_sphinx_files/tutorial/index.rst) but I agree that our current documentation should include this point either in the section describing Var components or in the section on "Working with Pyomo models"

@jsiirola
Copy link
Member

jsiirola commented Jun 5, 2019

This should definitely be included in the Var documentation.

In addition, this is indeed a poor error message. PEP #326 would introduce more consistent handling of infinite Set objects. At that point, we could do one of two things:

  1. Produce a more informative error message when creating Vars indexed by infinite sets, including hinting at declaring them with dense=False.
  2. Automatically assume dense=False if dense is not specified for Vars indexed by infinite Sets (we would still need to produce the error message if dense was explicitly set to True).

@emma58
Copy link
Contributor Author

emma58 commented Feb 1, 2022

#2184 added a nice warning when you don't specify dense=False, so closing this.

@emma58 emma58 closed this as completed Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants