Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Root Node to Graph #192

Merged
merged 20 commits into from
Jul 29, 2024
Merged

Add Root Node to Graph #192

merged 20 commits into from
Jul 29, 2024

Conversation

michaelmckinsey1
Copy link
Collaborator

@michaelmckinsey1 michaelmckinsey1 commented Jul 9, 2024

Examples of add_root_node and get_node can be found in the notebook in thicket-tutorial/48

add_root_node enables adding a root node to the Thicket.graph and corresponding Thicket.statsframe and Thicket.dataframe objects.

get_node provides a simpler interface for grabbing a node object by its name in the Thicket instead of using something like [n for n in self.graph.traverse() if n.frame["name"] == name][0]. This function is optional for this PR or could be its own PR; I am proposing it here.

@michaelmckinsey1
Copy link
Collaborator Author

michaelmckinsey1 commented Jul 9, 2024

Depends on #190 and #173

@michaelmckinsey1 michaelmckinsey1 added area-thicket Issues and PRs involving Thicket's core Thicket datastructure and associated classes priority-normal Normal priority issues and PRs status-work-in-progress PR is currently being worked on type-feature Requests for new features or PRs which implement new features labels Jul 9, 2024
@michaelmckinsey1 michaelmckinsey1 self-assigned this Jul 9, 2024
@michaelmckinsey1 michaelmckinsey1 changed the title Add root node Add Root Node to Graph Jul 9, 2024
@michaelmckinsey1 michaelmckinsey1 added status-ready-for-review This PR is ready to be reviewed by assigned reviewers and removed status-work-in-progress PR is currently being worked on labels Jul 10, 2024
@michaelmckinsey1 michaelmckinsey1 marked this pull request as ready for review July 10, 2024 19:55
Copy link
Collaborator

@ilumsden ilumsden left a comment

Choose a reason for hiding this comment

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

Mostly looks good.

The only change that really needs to be made is the one about pop(). The other two are just suggestions.


new_node = hatchet.node.Node(
frame_obj=frame.Frame(attrs=attrs), hnid=len(self.graph)
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you're going to do frame.Frame, why not also do node.Node? Or, better yet, just do the imports in a way that let's you do Node and Frame.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was using node.Node but we use node as a variable name in squash and I'm using it in get_node(). Not a big deal, so I'll just import Node and Frame

7e56d11

warnings.warn(f'More than one node with name "{name}". Returning a list')
return node

return node.pop()
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better to just return node[0]. pop will do things like resizing (see the source code), which isn't needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ilumsden ilumsden requested a review from pearce8 July 11, 2024 00:10
@michaelmckinsey1 michaelmckinsey1 added status-revisions-needed Revisions have been requested from a reviewer for this PR status-ready-for-review This PR is ready to be reviewed by assigned reviewers and removed status-ready-for-review This PR is ready to be reviewed by assigned reviewers status-revisions-needed Revisions have been requested from a reviewer for this PR labels Jul 11, 2024
Copy link
Collaborator

@ilumsden ilumsden left a comment

Choose a reason for hiding this comment

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

This mostly looks good at this point. Just a couple of minor changes.



def test_add_root_node(literal_thickets):
tk, tk2, tk3 = literal_thickets
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you're not using tk2 or tk3, change this line to the following:

tk, _, _ = literal_thickets

Copy link
Collaborator Author

Choose a reason for hiding this comment

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



def test_get_node(literal_thickets):
tk, tk2, tk3 = literal_thickets
Copy link
Collaborator

Choose a reason for hiding this comment

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

See previous comment about use of underscores here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

warnings.warn(f'More than one node with name "{name}". Returning a list')
return node
elif len(node) == 0:
raise ValueError(f'Node with name "{name}" not found.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would raise a KeyError here instead.

Copy link
Collaborator Author

@michaelmckinsey1 michaelmckinsey1 Jul 22, 2024

Choose a reason for hiding this comment

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

node = [n for n in self.graph.traverse() if n.frame["name"] == name]

if len(node) > 1:
warnings.warn(f'More than one node with name "{name}". Returning a list')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this warning is necessary as long as we document the return type correctly. Regardless if this warning is kept or removed, the docstring needs to be updated to indicate that it can return either Node or List[Node].

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@ilumsden ilumsden left a comment

Choose a reason for hiding this comment

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

LGTM.

@pearce8 this is ready for your review

@pearce8 pearce8 merged commit e675a8a into LLNL:develop Jul 29, 2024
4 checks passed
@slabasan slabasan added this to the 2024.2.0 milestone Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-thicket Issues and PRs involving Thicket's core Thicket datastructure and associated classes priority-normal Normal priority issues and PRs status-ready-for-review This PR is ready to be reviewed by assigned reviewers type-feature Requests for new features or PRs which implement new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants