Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Update cuds api according to m30#312

Merged
mehdisadeghi merged 12 commits into
masterfrom
update-cuds-api-according-to-m30
Aug 11, 2016
Merged

Update cuds api according to m30#312
mehdisadeghi merged 12 commits into
masterfrom
update-cuds-api-according-to-m30

Conversation

@mehdisadeghi

Copy link
Copy Markdown
Contributor

This PR simplifies CUDS class. Adds name and description to CUDS and Simulation classes. Moreover, uses name as the main parameter to add/get/remove items inside CUDS.

Mehdi Sadeghi added 4 commits July 28, 2016 15:00
The main parameter to add/get/remove items changed to `name`.
Some `uid` specific methods added to carry out the same tasks
with `uid`. Code simplified. `name` and `description` added to
Simulation and CUDS classes.

Perhaps I have to create multiple commits next time.
@codecov-io

codecov-io commented Aug 2, 2016

Copy link
Copy Markdown

Current coverage is 72.40% (diff: 91.30%)

Merging #312 into master will increase coverage by 0.88%

@@             master       #312   diff @@
==========================================
  Files           115        115          
  Lines          6949       6969    +20   
  Methods           0          0          
  Messages          0          0          
  Branches        803        808     +5   
==========================================
+ Hits           4970       5046    +76   
+ Misses         1952       1880    -72   
- Partials         27         43    +16   

Powered by Codecov. Last update 4d4a56c...2731f2a

@mehdisadeghi

Copy link
Copy Markdown
Contributor Author

@tuopuu @kitchoi @SGGgarcia Please review this PR.
@ahashibon Please see the changes regarding name parameter.

description=None):
self.name = name
self.description = description

@kitchoi kitchoi Aug 2, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Simulation does not have __slots__. User can always do:

sim = Simulation(cuds, engine_name)
sim.name = 'sim1'
sim.description = 'description for sim1'

Or, are the names/descriptions required in the API (then they should not be default to be None)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They are optional at the moment, exactly like the meta classes. Perhaps we have to turn CUDS and Simulation classes into CUDSItem derivaties, to have one universal data structure to deal with (it has been always the aim). However, for now I just decided to keep it simple.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with @mehdisadeghi here. For now it should be enough.

@kitchoi

kitchoi commented Aug 2, 2016

Copy link
Copy Markdown
Contributor

Looks like with this PR, it is then necessary to define a unique string name for every item being added to a CUDS. name essentially replaces uuid. Is this right? If so, is this behaviour intended by the SSB?

Comment thread simphony/cuds/tests/test_cuds.py Outdated
self.data = {}
self.dummpy_component1 = DummyComponent()
self.dummpy_component2 = DummyComponent()
self.dummpy_component1 = api.Box(name='mybox')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While at it, should fix this to self.dummy_component1 & 2. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh gotcha! I'll fix them right away! :)

@mehdisadeghi

Copy link
Copy Markdown
Contributor Author

name essentially replaces uuid. Is this right?

To some extent, yes. uid for internal consistency, name for users.

is this behaviour intended by the SSB

AFAIK, Yes. Hence mentioning Adham to confirm.

As I have commented in the code, the behavior of add/get/remove by name vs. by uid is ambiguous. What happens if a user adds a Box and Material with the exact same names? The initial behavior was to replace them blindly (as in python dict), I forced it to reject duplicates to have further discussions.

@ahashibon

Copy link
Copy Markdown
Contributor

As I have commented in the code, the behavior of add/get/remove by name vs. by uid is ambiguous. What happens if a user adds a Box and Material with the exact same names? The initial behavior was to replace them blindly (as in python dict), I forced it to reject duplicates to have further discussions.
For now this is ok. Next iteration we should allow the same name for different items. For example a Box and Material may have the same name, but two different materials cannot. In essence this would require a way in the API to distinguish between the items.

@mehdisadeghi

Copy link
Copy Markdown
Contributor Author

@tuopuu @kitchoi @SGGgarcia based on our discussions I made some changes. Please have a look.

Comment thread simphony/cuds/model.py Outdated
return self._uid

@uid.setter
def uid(self, value):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you don't provide the setter, it is read-only. Trying to set it would raise an AttributeError: can't set attribute

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree, please remove the setter and deleter readonly properties only need the property decorated function only

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good to know that. I'll remove setters and deleters.

@kitchoi

kitchoi commented Aug 4, 2016

Copy link
Copy Markdown
Contributor

Is there a test_get_nameless_component_by_name version of test_remove_nameless_component_by_name?

Comment thread simphony/cuds/model.py Outdated
if the component is not a CUDS component
ValueError
if the component is already added
if a component already exists

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if a component with the same name already exists?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, corrected.

@kitchoi

kitchoi commented Aug 4, 2016

Copy link
Copy Markdown
Contributor

Please ignore the comment on the existence of test_get_nameless_component_by_name, i saw the test that i was looking for that is named differently.

Comment thread simphony/cuds/tests/test_cuds.py Outdated

self.assertEqual(c.get_by_uid(self.nameless_cuds_1.uid),
self.nameless_cuds_1)
self.assertIsNone(c.get(self.nameless_cuds_1.name))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess my comment in CUDS.get is about whether it is a better user-experience to raise an Error here if name is None or empty.

@kitchoi

kitchoi commented Aug 4, 2016

Copy link
Copy Markdown
Contributor

Thanks @mehdisadeghi! Tests are diligent. There are a few minor issues above, except for that, the rest looks good to merge to me.
Side note: I remain puzzled by the existence of CUDS.data, but I think that's a separate issue/question.

Comment thread simphony/cuds/model.py
@property
def data(self):
"""Data container for CUDS items."""
return DataContainer(self._data)

@itziakos itziakos Aug 5, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the reasoning for creating a (shallow) copy of the self._data. If the purpose is to have a snapshot then this will work only if the contained keys and values are immutable. In any other case we have an object that references internal information that can change without anybody knowing about them.

If I am correct only the engine functions and returned dataset are required to support the snapshot principle. Does this extend to simulation? what is there a reason for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are correct, this will not work properly with our current mutable CUDS objects. I think the behavior of the data property regarding meta classes is unclear.

I think Simulation can have the same API as CUDS.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants