-
Notifications
You must be signed in to change notification settings - Fork 5
Generic interface for Mesh #326
Changes from all commits
ec31852
a89075c
dc3a2e8
3d55d27
597a10e
bbccbf4
19e66dc
894797d
495a2e0
7aaedb0
1adf888
dd0724b
75185b5
1ce1688
91dd9b7
ecf81a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from abc import ABCMeta, abstractmethod | ||
|
|
||
|
|
||
| class ABCDataset(object): | ||
| """Abstract base class for a dataset. | ||
| """ | ||
| __metaclass__ = ABCMeta | ||
|
|
||
| @abstractmethod | ||
| def add(self, iterable): # pragma: no cover | ||
| """Adds a set of objects from the provided iterable | ||
| to the dataset. | ||
|
|
||
| If any object has no uids, the dataset will generate a new | ||
| uid for it. If the object has already an uid, it won't add the | ||
| object if an object with the same type uid already exists. | ||
| If the user wants to replace an existing object in the container | ||
| there is an 'update' method for that purpose. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| iterable : iterable of objects | ||
| the new set of objects that will be included in the container. | ||
|
|
||
| Returns | ||
| ------- | ||
| uids : list of uuid.UUID | ||
| The uids of the added objects. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError : | ||
| when there is an object with an uids that already exists | ||
| in the dataset. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def update(self, iterable): # pragma: no cover | ||
| """Updates a set of objects from the provided iterable. | ||
|
|
||
| Takes the uids of the objects and searches inside the dataset for | ||
| those objects. If the object exists, they are replaced in the | ||
| dataset. If any object doesn't exist, it will raise an exception. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
||
| iterable : iterable of objects | ||
| the objects that will be replaced. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError : | ||
| If any object inside the iterable does not exist. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def get(self, uid): # pragma: no cover | ||
| """Returns a copy of the object with the 'uid' id. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
||
| uid : uuid.UUID | ||
| the uid of the object | ||
|
|
||
| Raises | ||
| ------ | ||
| KeyError : | ||
| when the object is not in the container. | ||
|
|
||
| Returns | ||
| ------- | ||
| object : | ||
| A copy of the internally stored info. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def remove(self, uids): # pragma: no cover | ||
| """Remove the object with the provided uids from the container. | ||
|
|
||
| The uids inside the iterable should exists in the container. Otherwise | ||
| an exception will be raised. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| uids : iterable of uuid.UUID | ||
| the uids of the objects to be removed. | ||
|
|
||
| Raises | ||
| ------ | ||
| KeyError : | ||
| If any object doesn't exist. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def iter(self, uids=None, item_type=None): # pragma: no cover | ||
| """Generator method for iterating over the objects of the container. | ||
|
|
||
| It can receive any kind of sequence of uids to iterate over | ||
| those concrete objects. If nothing is passed as parameter, it will | ||
| iterate over all the objects. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| uids : iterable of uuid.UUID, optional | ||
| sequence containing the uids of the objects that will be | ||
| iterated. When the uids are provided, then the objects are | ||
| returned in the same order the uids are returned by the iterable. | ||
| If uids is None, then all objects are returned by the iterable | ||
| and there is no restriction on the order that they are returned. | ||
|
|
||
| Yields | ||
| ------ | ||
| object : Particle | ||
| The object item. | ||
|
|
||
| Raises | ||
| ------ | ||
| KeyError : | ||
| if any of the ids passed as parameters are not in the dataset. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def has(self, uid): # pragma: no cover | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to implement
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, the same applies to all the other pythonic container methods. Perhaps it's better to leave this the subject of another PR. (And I see we have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, if you do so, it's certainly possible, but at that point we should just reimplement the dict() interface... :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! However, we have to attack the problem of being a |
||
| """Checks if an object with the given uid already exists | ||
| in the dataset. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| uid : uuid.UUID | ||
| the uid of the object | ||
|
|
||
| Returns | ||
| ------- | ||
| True if the uid is found, False otherwise. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def has_type(self, item_type): # pragma: no cover | ||
| """Checks if the specified CUDSItem type is present | ||
| in the dataset. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| item_type : CUDSItem | ||
| The CUDSItem enum of the type of the items to return the count of. | ||
|
|
||
| Returns | ||
| ------- | ||
| True if the type is present, False otherwise. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def count_of(self, item_type): # pragma: no cover | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shell we implement
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's possible, yes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| """ Return the count of item_type in the container. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| item_type : CUDSItem | ||
| The CUDSItem enum of the type of the items to return the count of. | ||
|
|
||
| Returns | ||
| ------- | ||
| count : int | ||
| The number of items of item_type in the dataset. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError : | ||
| If the type of the item is not supported in the current | ||
| dataset. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def __len__(self): | ||
| """Returns the total number of items in the container. | ||
|
|
||
| Returns | ||
| ------- | ||
| count : int | ||
| The number of items of item_type in the dataset. | ||
| """ | ||
|
|
||
| def __contains__(self, item): | ||
| """Implements the `in` interface. Behaves as the has() method. | ||
| """ | ||
| return self.has(item) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DataSets must conform the the structore of
CUBA.DATA_SET, i.e. they needuid,name, etc defined.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok then I probably used the wrong name. I just picked dataset but I am not sure about it.
What is the generic name for things like particles, mesh, and lattice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DataSet!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you suggest that I add these as well, or that I should choose another name? This is just an interface to the generic interface, so I am not sure if we want to name it after the Dataset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name is fine. How about adding
meta.DataSetas a parent to get the properties?