Clean up NodeDefinition typing, fix empty-input handling, expose ClusterSummaryFeatures#890
Open
sevmag wants to merge 4 commits into
Open
Clean up NodeDefinition typing, fix empty-input handling, expose ClusterSummaryFeatures#890sevmag wants to merge 4 commits into
sevmag wants to merge 4 commits into
Conversation
Draft
Replace lowercase `torch.tensor` annotations with `torch.Tensor`, fix return-type docstrings on `NodeDefinition.forward` and `_construct_nodes` (they return a tensor, not a graph), correct the `ClusterSummaryFeatures._construct_nodes` return annotation from `Data` to `torch.Tensor`, and fix `_verify_standardization`'s return annotation (it returns None, not a tensor). Reorder imports to match the project's standard grouping. Also clarify the `ClusterSummaryFeatures` docstring about which features come from Glauch's thesis and which (counts) do not.
When the input pulse tensor was empty, `_construct_nodes` returned a `torch_geometric.data.Data` object built from `np.column_stack([x, []])` instead of a `torch.Tensor` shaped `[0, num_features]`. Downstream code expects a tensor, so this could crash or silently produce a malformed graph. Return a correctly-shaped empty tensor instead, and drop the now-unused `Data` import.
The class was already importable through `graphnet.models.data_representation.graphs` but missing from the top-level `data_representation` package's public re-exports.
84154ba to
5576fdd
Compare
Aske-Rosted
reviewed
May 26, 2026
Collaborator
Aske-Rosted
left a comment
There was a problem hiding this comment.
This looks good to me as long as there is a reason for why you might want to allow the passing of empty data objects. I would assume that we in that case might just want to catch that instance and raise an error?
Collaborator
Author
Good point! I agree that an empty graph is probably not what we want. I will adjust it to throw an error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First in a series of small PRs being carved out of #813 to make review easier (see the comment on #813 for the full split plan). This one is all the touch-ups around
NodeDefinitionthat landed in that branch and aren't tied to the CNN work — pulling them out so they can be reviewed and merged on their own.Three independent commits:
NodeDefinition— replace lowercasetorch.tensorannotations withtorch.Tensor; fix return-type docstrings onforwardand_construct_nodes(they return a tensor, not a graph); correctClusterSummaryFeatures._construct_nodesreturn annotation fromDatatotorch.Tensor; fix_verify_standardizationannotation (returnsNone, nottorch.Tensor); reorder imports to project convention; clarify theClusterSummaryFeaturesdocstring about which features come from Glauch's thesis and which (counts) don't.NodeAsDOMTimeSeriesempty-input handling — when the input pulse tensor is empty,_construct_nodespreviously returned atorch_geometric.data.Databuilt fromnp.column_stack([x, []])instead of a tensor of shape[0, num_features]. Downstream callers expect a tensor; this could crash or silently produce a malformed graph. Returns a correctly-shaped empty tensor and drops the now-unusedDataimport.ClusterSummaryFeaturesfrom the top-leveldata_representationpackage (was already reachable via.graphs).No functional changes outside of (2), which is a bug fix.
Test plan
pre-commit run --files src/graphnet/models/data_representation/graphs/nodes/nodes.py src/graphnet/models/data_representation/__init__.py— already verified locallySplit from #813.
🤖 Generated with Claude Code