[Contribution] pyhealth.graph: Native knowledge graph support + GraphProcessor#853
Open
joshuasteier wants to merge 2 commits intosunlabuiuc:masterfrom
Open
[Contribution] pyhealth.graph: Native knowledge graph support + GraphProcessor#853joshuasteier wants to merge 2 commits intosunlabuiuc:masterfrom
joshuasteier wants to merge 2 commits intosunlabuiuc:masterfrom
Conversation
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.
Contributor Information
Description
Adds native knowledge graph support to PyHealth via a new
pyhealth.graphmodule and aGraphProcessorinpyhealth.processors. This is foundational infrastructure enabling graph-based EHR models (GraphCare, G-BERT, KAME, etc.) to consume standard PyHealth datasets through the existing processor/schema pipeline.Builds on Patrick Jiang's earlier
BaseKGDatasetwork on thekg_embeddingbranch, updated for PyHealth 2.0's processor architecture.What's included:
pyhealth.graph.KnowledgeGraph— Core data structure for medical knowledge graphs:edge_index+edge_typetensorssubgraph()extraction viatorch_geometric.utils.k_hop_subgraphpyhealth.processors.GraphProcessor— Registered processor bridging EHR codes to graphs:Datasubgraphmax_nodespruning (seeds always kept)FeatureProcessorinterface:is_token(),schema(),dim(),spatial()Collation update — Added PyG
Databranch tocollate_fn_dict_with_padding:Dataobjects and batches viaBatch.from_data_list()torch-geometricis optional — gracefully skips when not installedUsage
Design decisions:
torch-geometricis an optional dependency — imported only when graph features are usedTimeImageProcessorfor registration and integrationFiles to Review
New files:
pyhealth/graph/__init__.py— module exportspyhealth/graph/knowledge_graph.py— KnowledgeGraph classpyhealth/processors/graph_processor.py— GraphProcessortests/core/test_knowledge_graph.py— 22 unit teststests/core/test_graph_processor.py— 19 unit testsdocs/api/graph.rst— graph module docsdocs/api/graph/pyhealth.graph.KnowledgeGraph.rst— KG API docsdocs/api/processors/pyhealth.processors.GraphProcessor.rst— processor docsEdited files:
pyhealth/processors/__init__.py— added GraphProcessor importpyhealth/datasets/utils.py— added PyG collation branchdocs/api/processors.rst— added to toctreedocs/index.rst— added graph sectionTesting
Next steps (separate PRs)