-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Discussed in #16
Originally posted by damskii9992 June 17, 2024
General
In EasyScience, we have a global object called borg, based on the singleton Borg class. This object has an associated map object based on the Graph class, which contains weak references to all created object instances which inherit from BasedBase, such as any BaseObj or BaseCollection object. One of the uses of this map, is that any object can be found no matter where it lives and no matter how deeply nested in other objects it is.
Current implementation
Currently, when an object is created, the borg calcuates the UUID of the object, which is a unique identifier for any python instance consisting of a 128bit string of numbers and letters. This UUID is then converted into a pure number sequence and is saved as the key of a key-value pair in a weakref dictionary on the borg with the reference to the object. To query the borg to find an object currently, the following code is used:
borg.map.get_item_by_key(borg.map.convert_id_to_key(object))
Proposed implementation
Instead of using UUIDs as keys to object references, I propose to use unique strings i.e. unique "names". These unique names can be set by the user or developer, but will by default by generated according to the class name of the object and the number of those objects, such as: Parameter_0, Parameter_1 etc. With this implementation, to query the borg to find an object, the following code can be used:
borg.map.get_item_by_key(object.unique_name)
or if the name is known:
borg.map.get_item_by_key("Best_Parameter")
Advantages with new implementation
- We don't need the borg to generate the UUIDs to then again query the borg for an object
- If the name is known, you don't even need the object to query the borg
- The list of all objects created by the call
borg.map.vertices()
will become human-readable. - The code becomes simpler and cleaner
- A user can personally set the unique id of the most important parameters for easy access
Disadvantage with new implementation
- Will raise errors when users or developers use the same unique name for multiple object instances