igraph Adapter
igraph conversion helpers from annnet.adapters.igraph_adapter.
annnet.adapters.igraph_adapter
Classes
IGraphAdapter
Legacy adapter class for backward compatibility.
Methods:
| Name | Description |
|---|---|
export |
Export AnnNet to igraph.AnnNet without manifest (lossy). |
Functions
export(graph, **kwargs)
Export AnnNet to igraph.AnnNet without manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
AnnNet
|
|
required |
**kwargs
|
See to_backend() for supported parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
AnnNet
|
|
Functions
to_igraph(graph, directed=True, hyperedge_mode='skip', slice=None, slices=None, public_only=False, reify_prefix='he::')
Export AnnNet → (igraph.AnnNet, manifest).
hyperedge_mode: {"skip","expand","reify"} - "skip": drop HE edges from igG (manifest keeps them) - "expand": cartesian product (directed) / clique (undirected) - "reify": add a node per HE and membership edges V↔HE carrying roles/coeffs
save_manifest(manifest, path)
Write manifest to JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
dict
|
Manifest dictionary from to_igraph(). |
required |
path
|
str
|
Output file path (typically .json extension). |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
OSError
|
If file cannot be written. |
load_manifest(path)
Load manifest from JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to manifest JSON file created by save_manifest(). |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Manifest dictionary suitable for from_igraph(). |
Raises:
| Type | Description |
|---|---|
OSError
|
If file cannot be read. |
JSONDecodeError
|
If file contains invalid JSON. |
from_igraph(igG, manifest, *, hyperedge='none', he_node_flag='is_hyperedge', he_id_attr='eid', reify_prefix='he::')
Reconstruct a AnnNet from igraph.AnnNet + manifest.
hyperedge: "none" (default) | "reified" When "reified", also detect hyperedge nodes in igG and rebuild true hyperedges that are NOT present in the manifest.
to_backend(graph, **kwargs)
Export AnnNet to igraph without manifest (legacy compatibility).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
AnnNet
|
Source AnnNet instance to export. |
required |
**kwargs
|
Forwarded to _export_legacy(). Supported: - directed : bool, default True Export as directed igraph.AnnNet (True) or undirected (False). - skip_hyperedges : bool, default True If True, drop hyperedges. If False, expand them (cartesian product for directed, clique for undirected). - public_only : bool, default False Strip attributes starting with "__" if True. |
{}
|
Returns:
| Type | Description |
|---|---|
AnnNet
|
igraph.AnnNet with integer vertex indices. External vertex IDs are stored in vertex attribute 'name'. Edge IDs stored in edge attribute 'eid'. Hyperedges are either dropped or expanded into multiple binary edges. No manifest is returned, so round-tripping will lose hyperedge structure, slices, and precise edge IDs. |
Notes
This is a lossy export. Use to_igraph() with manifest for full fidelity. igraph requires integer vertex indices internally; the 'name' attribute preserves your original string IDs.
from_ig_only(igG, *, hyperedge='none', he_node_flag='is_hyperedge', he_id_attr='eid', role_attr='role', coeff_attr='coeff', membership_attr='membership_of')
Best-effort import from a plain igraph.AnnNet (no manifest). Preserves all vertex/edge attributes. hyperedge: "none" | "reified" When "reified", rebuild true hyperedges and skip membership edges from binary import.