Replies: 6 comments 13 replies
-
Thanks for summarising @sphuber, obviously I can adapt #5439, #5442, #5445 and #5446 to these, when agreed on. Some initial responses:
yes
It is used, in
I would just note that this is not facile, since with static analysis it's not foolproof to identify instances of Some initial notes:
|
Beta Was this translation helpful? Give feedback.
-
Also to note, for |
Beta Was this translation helpful? Give feedback.
-
For the actual implementation, you would do something like: from functools import cached_property
class NodeAttributes:
def __init__(self, node):
self._node = node
def get(self, key):
return self._node.backend_entity.get_attribute(key)
class NodeContext:
def __init__(self, node):
self._node = node
@cached_property
def attributes(self):
return NodeAttributes(self._node)
class Node:
@cached_property
def ctx(self):
return NodeContext(self) You'll note, this means you now have to initialise more objects than just the |
Beta Was this translation helpful? Give feedback.
-
First I should mention that I am fully on board with tidying up method namespace of Nodes - it is a nuisance in everyday use and great to see this being tackled. In deciding which methods to keep at the top-level and which to group under sub-namespaces, however, I think besides architectural considerations we should consider which methods are most often used interactively. We could at some point try come up with some sort of statistics, e.g. looking at our tutorial material, but short of that my feeling is that
While the database layout may differ, I think most AiiDA users will consider attributes and extras "properties of the node". Rather than proposing a full layout, here is my list of methods that I believe should remain at the top level of the node in order to avoid unnecessary typing (more can be added for consistency reasons):
|
Beta Was this translation helpful? Give feedback.
-
Putting attributs/extras aside for a moment, after reading
I expected the That would lead me to an arrangement like (just showing what changes):
Just pointing this out as another possible grouping. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I agree with the division and the following concepts (e.g. rename objects to collection). Only important comment for me is: I wouldn't use the name I'm not sure of a good suggestion, but I think it should not be |
Beta Was this translation helpful? Give feedback.
-
The
Node
class has many methods and attributes in its public namespace. This has been noted as being a problem for users of an interactive shell as it makes it difficult to find what they are looking for and to intuit what is supposed to be part of the public API. Here is a suggestion for reorganizing the namespace byThe main idea is to take all methods that are not directly relevant to the properties of the node itself, but rather have to do with its context in the provenance graph, and move them to a nested namespace. For the sake of argument, let's call this namespace
base
for now. Any methods that are related can be grouped into further sub-namespaces where appropriate. With this approach the top level namespace should be significantly de-cluttered. One potential downside of moving methods from the top-namespace to sub-namespaces is that discoverability may be slightly reduced. Users will now have to "know" for example to go toNode.base.attributes.get
to get an attribute. Still the changes may be a net gain in terms of clarity and user friendliness.Below is a table with the proposed name changes for each currently public attribute and method:
Collection
NodeCollection
directlyadd_comment
Node.base.comments.add
add_incoming
Node.base.links.add_incoming
attributes
Node.base.attributes.all
attributes_items
Node.base.attributes.items
attributes_keys
Node.base.attributes.keys
backend
backend_entity
check_mutability
Node._check_mutability_attributes
class_node_type
clear_attributes
Node.base.attributes.clear
clear_extras
Node.base.extras.clear
clear_hash
Node.base.caching.clear_hash
computer
copy_tree
Node.base.repository.copy_tree
ctime
delete_attribute
Node.base.attributes.delete
delete_attribute_many
Node.base.attributes.delete_many
delete_extra
Node.base.extras.delete
delete_extra_many
Node.base.extras.delete_many
delete_object
Node.base.repository.delete_object
description
erase
Node.base.repository.erase
extras
Node.base.extras.all
extras_items
Node.base.extras.items
extras_keys
Node.base.extras.keys
from_backend_entity
get
Node.objects.get
get_all_same_nodes
Node.base.caching.get_all_same_nodes
get_attribute
Node.base.attributes.get
get_attribute_many
Node.base.attributes.get_many
get_cache_source
Node.base.caching.get_cache_source
get_comment
Node.base.comments.get
get_comments
Node.base.comments.all
get_description
description
property that just fetches the similarly named column from the database mode. Might require a name change for clarity.get_extra
Node.base.extras.get
get_extra_many
Node.base.extras.get_many
get_hash
Node.base.caching.get_hash
get_incoming
Node.base.links.get_incoming
get_object
Node.base.repository.get_object
get_object_content
Node.base.repository.get_object_content
get_outgoing
Node.base.links.get_outgoing
get_stored_link_triples
Node.base.links.get_stored_link_triples
glob
Node.base.repository.glob
has_cached_links
execmanager.upload_calculation
andCalcJob.presubmit
, should essentially be replaced withis_stored
because in that case all links should be stored and the cache is empty.)id
pk
insteadinitialize
is_created_from_cache
Node.base.caching.is_created_from_cache
is_stored
is_valid_cache
Node.base.caching.is_valid_cache
label
list_object_names
Node.base.repository.list_object_names
list_objects
Node.base.repository.list_objects
logger
mtime
node_type
objects
collection
open
Node.base.repository.open
pk
process_type
put_object_from_file
Node.base.repository.put_object_from_file
put_object_from_filelike
Node.base.repository.put_object_from_filelike
put_object_from_tree
Node.base.repository.put_object_from_tree
rehash
Node.base.caching.rehash
remove_comment
Node.base.comments.remove
repository_metadata
Node.base.repository.metadata
repository_serialize
Node.base.repository.serialize
reset_attributes
Node.base.attributes.reset
reset_extras
Node.base.extras.reset
set_attribute
Node.base.attributes.set
set_attribute_many
Node.base.attributes.set_many
set_extra
Node.base.extras.set
set_extra_many
Node.base.extras.set_many
store
store_all
update_comment
Node.base.comments.update
user
uuid
validate_incoming
Node.base.links.validate_incoming
validate_outgoing
Node.base.links.validate_outgoing
validate_storability
Node._validate_storability
verify_are_parents_stored
Node._verify_are_parents_stored
walk
Node.base.repository.walk
If these changes were to be adopted, this would be the resulting namespace:
If we can agree on the new naming, the idea would be to get this in
v2.0
in a backwards-compatible way. Deprecation warnings could potentially be hidden by default and enabled with a config option or environment variable (see this PR for details). With the development ofaiida-upgrade
we can even automate the update of existing code. These kinds of changes would be easy to implement inaiida-upgrade
so the change should be relatively painless for users.Beta Was this translation helpful? Give feedback.
All reactions