Skip to content

Conversation

@Zhang-S-S
Copy link
Collaborator

This PR introduces support for the Hypergraphs Interchange Format (HIF), enabling EasyGraph to exchange hypergraph data with other tools that support the HIF JSON standard.

It implements two main utility functions:

  1. hypergraph_to_hif: Converts an EasyGraph Hypergraph object to a HIF JSON dictionary/file.
  2. hif_to_hypergraph: Loads HIF JSON data into an EasyGraph Hypergraph object.

Key Changes

  • New Module: Added easygraph/utils/HIF.py containing the core conversion logic.
  • Unit Tests: Added easygraph/tests/test_hif.py to ensure conversion accuracy and structural validity.
  • API Exposure: Updated easygraph/utils/__init__.py to expose hypergraph_to_hif and hif_to_hypergraph for easier access.

Implementation Details

  1. Schema Validation:
    The converter attempts to fetch the official HIF schema (v0.1.0) to validate input/output data. It includes a fallback mechanism to skip validation if the schema cannot be fetched (offline mode).

  2. Round-Trip Data Preservation:

    • Implemented a "sidecar" mechanism (attaching custom_hif_* attributes to the object) to preserve original HIF data.
    • This ensures that attributes not natively supported by EasyGraph (e.g., incidence direction, nested attrs, or arbitrary metadata) are preserved during a Load -> EG -> Save cycle.
  3. Robust Structure Parsing:

    • Correctly handles the different internal storage structures of hg.e (e.g., standard lists vs. the (edges, weights, props) tuple generated when merge_op="sum").
    • Safely handles hg.N_e regardless of whether it is a property or a method in different EasyGraph versions.

Related Files

  • easygraph/utils/HIF.py (New)
  • easygraph/tests/test_hif.py (New)
  • easygraph/utils/__init__.py (Modified)

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.

2 participants