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 NumberedObjectCollection act like a set #138

Open
MicahGale opened this issue Feb 23, 2023 · 7 comments
Open

Make NumberedObjectCollection act like a set #138

MicahGale opened this issue Feb 23, 2023 · 7 comments
Assignees
Labels
feature request An issue that improves the user interface.
Milestone

Comments

@MicahGale
Copy link
Collaborator

This is very similar to #61. I am partially of the mind of either implementing both or only implement set behavior and not dict behavior.

This came out of this discussion (copied below): https://hpcgitlab.hpc.inl.gov/experiment_analysis/mcnpy/-/issues/54#note_480927h.

To summarize: implement set-like arithmetic and binary logic. This will leads to complications with multiple problems though and #22, and #83 will be involved in the solution.

Labossiere-Hickman, Travis James
@tjlaboss

I do like the option of having a NumberedObjectCollection behave as a set. Since the collections can come from different models, though, the standard Python set logic might not be appropriate for identically-numbered but unequal objects. Three solutions:

Only allow set operations for NumberedObjectCollection instances linked to the same problem.
Allow them, but warn for every conflict.
Don't implement set operations, and just have the user manually do set(num_obj_col) if they want.

Gale, Micah David
@MicahGale

Just going to mention #61 here.

But this is very much an issue that I have been grappling for awhile, that lead to all those weird scripts that can't be upgraded that I showed you today @bascandr. This needs to ultimately get resolved by #22.

My overall view is that we should allow different problems. I think we need to be able to spot ostensibly identical objects to merge (for instance two files with common heritage). If they are the same they should merge. This then deals with problems of pointers though. Maybe we need to implement a hidden object state that just engages passthrough mode, probably knock that sort of thing out along with #83. But if there is a number collision of dissimilar objects I think the RHS (to be consistent) should be renumbered with a warning. Though this could cause issues if users didn't intend that. Maybe we need a system to rollback changes? Like a database? That would be actually really nice:

try: 
   problem.start_transaction()
   ... do error prone thing...
   problem.commit()
except as e:
   problem.roll_back()
   raise e

Realistically this would be a with statement most likely.

Suffice it to say I think we enough discussion to open a few new issues.

@MicahGale
Copy link
Collaborator Author

marked this issue as related to #61

@MicahGale
Copy link
Collaborator Author

marked this issue as related to #54

@MicahGale
Copy link
Collaborator Author

marked this issue as related to #22

@MicahGale
Copy link
Collaborator Author

marked this issue as related to #83

@MicahGale MicahGale self-assigned this Sep 17, 2024
@MicahGale MicahGale mentioned this issue Sep 17, 2024
30 tasks
@MicahGale
Copy link
Collaborator Author

In python 3.9 dict1 | dict2 is now an option. (https://docs.python.org/3/library/stdtypes.html#dict.values), So that would be pythonic.

dict1 & dict2 is not supported, but I think in this case we could make it meaningful. I'm thinking we implement this using this is operator. May want to optimize using {hex(id(obj)) for obj in self}.

@tjlaboss
Copy link
Collaborator

Help on class set in module builtins:

class set(object)
 |  set() -> new empty set object
 |  set(iterable) -> new set object
 |  
 |  Build an unordered collection of unique elements.
 |  
 |  Methods defined here:
 |  
 |  __and__(self, value, /)
 |      Return self&value.
 |  
 |  __contains__(...)
 |      x.__contains__(y) <==> y in x.
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __gt__(self, value, /)
 |      Return self>value.
 |  
 |  __iand__(self, value, /)
 |      Return self&=value.
 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __ior__(self, value, /)
 |      Return self|=value.
 |  
 |  __isub__(self, value, /)
 |      Return self-=value.
 |  
 |  __iter__(self, /)
 |      Implement iter(self).
 |  
 |  __ixor__(self, value, /)
 |      Return self^=value.
 |  
 |  __le__(self, value, /)
 |      Return self<=value.
 |  
 |  __len__(self, /)
 |      Return len(self).
 |  
 |  __lt__(self, value, /)
 |      Return self<value.
 |  
 |  __ne__(self, value, /)
 |      Return self!=value.
 |  
 |  __or__(self, value, /)
 |      Return self|value.
 |  
 |  __rand__(self, value, /)
 |      Return value&self.
 |  
 |  __reduce__(...)
 |      Return state information for pickling.
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __ror__(self, value, /)
 |      Return value|self.
 |  
 |  __rsub__(self, value, /)
 |      Return value-self.
 |  
 |  __rxor__(self, value, /)
 |      Return value^self.
 |  
 |  __sizeof__(...)
 |      S.__sizeof__() -> size of S in memory, in bytes
 |  
 |  __sub__(self, value, /)
 |      Return self-value.
 |  
 |  __xor__(self, value, /)
 |      Return self^value.
 |  
 |  add(...)
 |      Add an element to a set.
 |      
 |      This has no effect if the element is already present.
 |  
 |  clear(...)
 |      Remove all elements from this set.
 |  
 |  copy(...)
 |      Return a shallow copy of a set.
 |  
 |  difference(...)
 |      Return the difference of two or more sets as a new set.
 |      
 |      (i.e. all elements that are in this set but not the others.)
 |  
 |  difference_update(...)
 |      Remove all elements of another set from this set.
 |  
 |  discard(...)
 |      Remove an element from a set if it is a member.
 |      
 |      If the element is not a member, do nothing.
 |  
 |  intersection(...)
 |      Return the intersection of two sets as a new set.
 |      
 |      (i.e. all elements that are in both sets.)
 |  
 |  intersection_update(...)
 |      Update a set with the intersection of itself and another.
 |  
 |  isdisjoint(...)
 |      Return True if two sets have a null intersection.
 |  
 |  issubset(...)
 |      Report whether another set contains this set.
 |  
 |  issuperset(...)
 |      Report whether this set contains another set.
 |  
 |  pop(...)
 |      Remove and return an arbitrary set element.
 |      Raises KeyError if the set is empty.
 |  
 |  remove(...)
 |      Remove an element from a set; it must be a member.
 |      
 |      If the element is not a member, raise a KeyError.
 |  
 |  symmetric_difference(...)
 |      Return the symmetric difference of two sets as a new set.
 |      
 |      (i.e. all elements that are in exactly one of the sets.)
 |  
 |  symmetric_difference_update(...)
 |      Update a set with the symmetric difference of itself and another.
 |  
 |  union(...)
 |      Return the union of sets as a new set.
 |      
 |      (i.e. all elements that are in either set.)
 |  
 |  update(...)
 |      Update a set with the union of itself and others.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __hash__ = None

@MicahGale
Copy link
Collaborator Author

Thanks. I think most of these make sense to implement. I don't want to go crazy with absolutely everything. Like maybe not intersect_update if we support &=. Also the right hand operators should be unneeded.

@MicahGale MicahGale modified the milestones: Release-1.0.0, 1.0.0-alpha Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request An issue that improves the user interface.
Projects
None yet
Development

No branches or pull requests

2 participants