Skip to content

Replace UUIDS with unique_names #18

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

Merged
merged 58 commits into from
Jul 16, 2024
Merged

Replace UUIDS with unique_names #18

merged 58 commits into from
Jul 16, 2024

Conversation

damskii9992
Copy link
Contributor

No description provided.

@damskii9992 damskii9992 added the chore PR label label Jun 18, 2024
@damskii9992 damskii9992 added the [area] global_object Anything related to the global_object label Jun 18, 2024
@andped10
Copy link
Contributor

It is not clear to me where and how it is ensured that a unique_name is unique

@damskii9992
Copy link
Contributor Author

damskii9992 commented Jun 19, 2024

It is not clear to me where and how it is ensured that a unique_name is unique

In the Graph.py file under the add_vertex method, this method is called whenever an EasyScience object is created. It is the method which actually adds the reference to the object to the global map

@damskii9992 damskii9992 closed this Jul 8, 2024
@damskii9992 damskii9992 reopened this Jul 8, 2024
Copy link
Member

@rozyczko rozyczko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's ready to merge. There are minor issues to be looked at but no major problems.

Comment on lines 114 to 117
if class_name not in self._name_iterator_dict.keys():
self._name_iterator_dict[class_name] = 0
else:
self._name_iterator_dict[class_name] += 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just

        self._name_iterator_dict.setdefault(class_name, 0)
        self._name_iterator_dict[class_name] += 1

avoiding conditionals

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed better. Changing this.

Comment on lines 106 to 110
extracted_list = []
for key, item in self.__type_dict.items():
if obj_type in item.type:
extracted_list.append(key)
return extracted_list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just

return [key for key, item in self.__type_dict.items() if obj_type in item.type]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, list comprehension is indeed better. This was not a part of my PR and the method might be completely removed or changed later on, but lets change it for now.

@unique_name.setter
def unique_name(self, new_unique_name: str):
""" Set a new unique name for the object. The old name is still kept in the map.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we are not able to reuse the unique names then?
why not delete (prune) the vertex? Leaving old mapping seems wasteful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are, but only once the old object using the unique_name has been deleted and garbage collection has run and thus removed its entries from the map.
Alternatively the user can manually prune the old unique_name from the map. The prune method is not "hidden".
We want to encourage users to not reuse unique_names, as that makes them not really "unique".
But maybe this discussion belongs in the ADR Suggestion #16.

raise TypeError("Unique name has to be a string.")
self._unique_name = new_unique_name
self._global_object.map.add_vertex(self)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have 3 identical methods unique_name and _unique_name_generator in

  • Variable
  • ObjectClasses
  • descriptor_base

Since all of them inherit from a base class, which eventually is ComponentSerializer, maybe it would make sense to combine some of these duplicates?

Copy link
Contributor Author

@damskii9992 damskii9992 Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would, it would in general make a lot of sense for us to fix our inheritance tree for stuff such as this. I would claim that this does not belong in a ComponentSerializer class, as that class is just for serialization, but rather in a base class which all our objects inherit from, which we don't currently have, as our descriptors and parameters do not inherit from BasedBase.
So this will hopefully be amended in a future PR, when we actually fix our inheritance tree.

@@ -164,18 +167,19 @@ def virtualizer(obj: BV) -> BV:
d = obj.encode_data()
if hasattr(d, 'fixed'):
d['fixed'] = True
d['unique_name'] = None
v_p = cls(**d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v_p looks awfully cryptic, can't we rename this to something more meaningful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, feel free to change it in a separate branch/PR. I don't have the bigger picture of what this part of the code is actually used for. I think v_p stands for "virtual_parameter", possibly?

global_object = GlobalObject()
global_object.instantiate_stack()
global_object.stack.enabled = False
borg = global_object # alias for global_object, remove later
Copy link
Member

@rozyczko rozyczko Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assignment could be made a property, which returns global_object but also notifies the user (print()? log.warning()?) about looking obsolescence of borg.
Could be useful when porting the libraries

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we even need anything in hugger.
This was going to be an impelentation of some sort of Variable wrapper so all changes to it are saved on the Undo stack.
I don't think it is fully/at all enabled so maybe we should make it go obsolescent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to remove it, but unfortunately, it is used, specifically in the logger. Maybe we should create an issue on this to see if it can be changed in the future?

@damskii9992 damskii9992 merged commit 7cd24b5 into develop Jul 16, 2024
26 checks passed
@damskii9992 damskii9992 deleted the replace_UUIDS branch July 16, 2024 08:35
@damskii9992 damskii9992 linked an issue Jul 16, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[area] global_object Anything related to the global_object chore PR label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace UUIDS with string names in BORG
3 participants