Replies: 1 comment 2 replies
-
hi @c-heat16 this is a great suggestion. I agree being able to query material from an inventory like a dictionary makes it easier. Currently our Inventory node keeps a list of material nodes and the API expects a list of material nodes so I am not sure how to handle that as of right now. SDK inventory node dataclass @dataclass(frozen=True)
class JsonAttributes(PrimaryBaseNode.JsonAttributes):
# uuid_base.py inherited attributes
uuid: str = field(default_factory=lambda: str(uuid.uuid4()))
updated_by: Any = None
created_by: Any = None
created_at: str = ""
updated_at: str = ""
# primary_base_node.py inherited attributes
locked: bool = False
model_version: str = ""
public: bool = False
name: str = ""
notes: str = ""
# inventory.py attributes
material: List[Material] = field(default_factory=list) JSON the API requires {
"name":"my inventory name",
"node":["Inventory"],
"uid":"_:90f45778-b7c9-4b77-8b83-a6ea9671a937",
"uuid":"90f45778-b7c9-4b77-8b83-a6ea9671a937",
"material":[
{
"node":["Material"],
"name":"my material 1",
"uid":"_:9679ff12-f9b4-41f4-be95-080b78fa71fd",
"uuid":"9679ff12-f9b4-41f4-be95-080b78fa71fd",
"bigsmiles":"[H]{[>][<]C(C[>])c1ccccc1[]}"
},
{
"node":["Material"],
"name":"my material 2",
"uid":"_:1ee41708-3531-43eb-8049-4bb91ad73df6",
"uuid":"1ee41708-3531-43eb-8049-4bb91ad73df6",
"bigsmiles":"654321"
}
]
} There are a few ways of doing this that I've thought of, but the issue then becomes performance, accuracy, and code maintainability. What I can do is when the user tries to interact with the inventory to turn the materials list into a dict, o(n) operation, and give it to the user and after they try to set the materials list for the inventory then convert it from dict to list again, another o(n) operation. Another way, would be that we have a method within the inventory node called The other way would be to keep the list of materials in the inventory as a dict and only serialize and deserialize them into a list, I think this might be the best way to go, but I am not sure right now, and I'll have to figure out serialization and deserialization code for it. Let me know what your thoughts are as they are very insightful. for reference here are the current inventory getters and setters @property
@beartype
def material(self) -> List[Material]:
return self._json_attrs.material.copy()
@material.setter
@beartype
def material(self, new_material_list: List[Material]):
new_attrs = replace(self._json_attrs, material=new_material_list)
self._update_json_attrs_if_valid(new_attrs) |
Beta Was this translation helpful? Give feedback.
-
In the previous version of the API, inventory nodes could be queries/indexed like dictionaries - if a material named
'my_material'
was added tomy_inventory
it could be obtained viamy_inventory['my_material'].
This provided an easy, convenient way to access materials associated with a particular project/collection.This behavior doesn't seem to have carried over to the new version of the API, however, and the utility that the inventory nodes provides to the user (programmer) is unclear IMO. Admittedly, though, I'm not familiar with the overall objectives of CRIPT, only how I/my team interacts with it. Without the indexing ability, it seems like the inventory is just a collection of materials associated with a project/collection, which could be constructed programmatically without the user - when a project/collection is saved (
api.save(project)
), the system could just identify material nodes associated with the project and put them in an inventory.I have found the indexing functionality very useful for my work and have added a
make_material_dict()
method (below) to the Inventory class which can be called once the inventory is created and populated. For it to work, however, lines 72-75 (__setattr__
) ofcript/nodes/core.py
must be commented out/deleted. While it works, as intended, it goes through a long routine of re-validating each material graph afterwards, which is not necessarily quick with a large inventory. Perhaps that can be improved at some point in the future.Beta Was this translation helpful? Give feedback.
All reactions