Skip to content

Add all_dependencies method to Base Entities#155

Merged
kroenlein merged 13 commits intomainfrom
feature/dependencies
Jan 4, 2022
Merged

Add all_dependencies method to Base Entities#155
kroenlein merged 13 commits intomainfrom
feature/dependencies

Conversation

@kroenlein
Copy link
Copy Markdown
Collaborator

This is an initial effort to migrate _all_dependencies into gemd-python. At present, recursive_foreach and recursive_flatmap can crawl a structure to recover all objects but cannot do so in a way that reveals layers that are helpful in batching.

The current structure of the method calls don't feel quite right, and at least feel like they motivate creation of a has_spec mixin.

Comment thread gemd/entity/base_entity.py Outdated
Comment thread gemd/entity/object/base_object.py Outdated
@sfriedowitz
Copy link
Copy Markdown

The current structure of the method calls don't feel quite right, and at least feel like they motivate creation of a has_spec mixin.

I agree with this for HasSpec. I have run into this issue before, and it would be potentially nice to have a more structured inheritance pattern there to distinguish between run and spec objects.

Would it be alot of work?

@kroenlein
Copy link
Copy Markdown
Collaborator Author

I agree with this for HasSpec. I have run into this issue before, and it would be potentially nice to have a more structured inheritance pattern there to distinguish between run and spec objects.

Would it be alot of work?

I started prototyping it and it turned into a research project about overloading python setters because ingredient_run has special logic.

@kroenlein kroenlein marked this pull request as ready for review January 3, 2022 17:57
@kroenlein kroenlein requested a review from bfolie January 3, 2022 17:58
Comment thread gemd/entity/object/base_object.py Outdated
if self.process is not None:
result.add(self.process)

return result
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This logic feels wrong because it requires base_object to know about the structure of its child classes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I agree that the isinstance(self, GEMD) would look nicer if we could test mixins instead. No obvious solution for MaterialSpec since PropertyAndConditions is just structured differently than MeasurementRun's property. A HasMaterial and HasProcess mixin would be more straightforward, but it's not clear that it buys you much because the only consequence is that you provide an abstract method that must be implemented where you don't even know the return type.

If necessary, I could bake that chunk of framework out.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we can't write this method without having a holistic understanding of the GEMD object structure, then what's the value in having this logic live in BaseObject as opposed to citrine-python?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Especially since all_dependencies is only used for batching in the context of upload, which is a citrine-python concern

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The mechanism has been reworked. Does this make more sense? I generally don't think that logic that relies only on gemd-python concepts should be implemented in a downstream package, and it seemed like implementing it as a gemd.util method was going to be messy. I still would have liked a cleaner way of accessing the PropertyAndCondition elements.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, I think that this makes more sense.

Comment thread gemd/entity/object/base_object.py Outdated

for typ in (HasParameters, HasConditions, HasProperties, HasSpec, HasTemplate):
if isinstance(self, typ):
result |= typ.all_dependencies(self)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why use the in-place union operation here, but result.add below? They seem to me like they both do the same thing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

add adds a single element to the set, where as |= adds all elements of a second set (like append & extend for lists). If you'd prefer all method calls, result |= could be changed to result.update()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@bfolie For clarity, I did not change |= to result.update() in my last push. Should I have?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No need to change

@kroenlein kroenlein merged commit 009abc9 into main Jan 4, 2022
@kroenlein kroenlein deleted the feature/dependencies branch January 4, 2022 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants