Skip to main content

Graph

Python: phynexis.parsim Headers: src/parsim/graph/*.hpp

Graph data structures for particle simulations. ComputationalGraph is the top-level container holding NodeSet, EdgeSet, HyperEdgeSet, and ShapeStore.

ComputationalGraph

Top-level graph container.

Constructors

SignatureDescription
ComputationalGraph()Empty graph.

Methods

MethodReturnsDescription
nodes()NodeSetThe node set
edges()EdgeSetThe edge set
hyper_edges()HyperEdgeSetThe hyperedge set
shape_store()ShapeStoreThe shape store
node_count()intNumber of nodes
edge_count()intNumber of edges
hyper_edge_count()intNumber of hyperedges
clear()Clear all sets
is_empty()boolTrue if all sets are empty
save_to(path, file, opt)Save graph to file
load_from(path, file, opt)Load graph from file
inspect(filepath)Inspect file metadata

Example:

import phynexis
pm = phynexis.parsim

g = pm.ComputationalGraph()
print(g.is_empty()) # True

ns = g.nodes()
print(type(ns).__name__) # NodeSet

SetBase

Abstract base class for NodeSet, EdgeSet, HyperEdgeSet.

Methods

MethodReturnsDescription
ensure_fields()Ensure all schema fields exist
schema()FieldSchemaThe set's schema
field_manager()FieldManagerUnderlying field manager
set_view(layout)Bind a BoundLayout to this set
count() / size()intNumber of elements
empty()boolTrue if size == 0
clear()Remove all elements
emplace()intAdd a new element (returns ID)
emplace_with_id(id)Add a new element with given ID
erase(id)Remove element by ID
allocate_id()intAllocate a new unique ID
save_to(path, file, opt)Save set data
load_from(path, file, opt)Load set data
inspect(filepath)Inspect file metadata

NodeSet

Particle/node storage.

Constructors

SignatureDescription
NodeSet()Empty node set.

Methods

MethodDescription
add_node(id, data)Add a node with JSON data
add_nodes(data_list)Batch add nodes from list of JSON
remove_node(id)Remove node by ID
remove_nodes(ids)Batch remove nodes
has_node(id)Check if node exists
initialize()Initialize internal storage
print_info()Print debug info
inspect_fields()Inspect field layout
views()Return node views

Example:

import phynexis
pm = phynexis.parsim
F = phynexis.fields

ns = pm.NodeSet()

# Bind a schema layout
fm = F.FieldManager()
schema = pm.NodeKinematicsSchema()
layout = pm.BoundLayoutNodeKinematicsSchema.make_bound(fm, schema)
ns.set_view(layout)
ns.initialize()

# Add nodes
ns.add_node(0, {"pos": [0.0, 0.0, 0.0]})
ns.add_node(1, {"pos": [1.0, 0.0, 0.0]})
print(ns.size()) # 2

EdgeSet

Pairwise edge/link storage.

Constructors

SignatureDescription
EdgeSet()Empty edge set.

Methods

MethodDescription
initialize()Initialize internal storage
print_info()Print debug info
views()Return edge views

Note: No direct add_edge / remove_edge methods are exposed. Use SetBase.emplace() / erase() for bulk operations.

HyperEdgeSet

Many-to-many hyperedge storage.

Constructors

SignatureDescription
HyperEdgeSet()Empty hyperedge set.

Methods

MethodDescription
initialize()Initialize internal storage
print_info()Print debug info
views()Return hyperedge views

ShapeStore

Stores geometric shapes with stable handles.

Constructors

SignatureDescription
ShapeStore()Empty store.

Methods

MethodReturnsDescription
insert(shape)intInsert shape clone, returns auto-allocated ID
insert_with_id(id, shape)intInsert with specified ID
id_at(handle)intGet ID from handle (-1 if invalid)
find(id)ShapeStoreHandleFind handle by ID
get(handle)ShapeStoreEntryGet entry by handle
erase(id)Erase shape by ID
contains(id)boolCheck if ID exists
valid(handle)boolCheck if handle is valid
set_label(id, label)Set label
set_need_sync(id, need_sync)Set sync flag
get_label_of(id)strGet label
initialize_mpi()Initialize MPI support
sync()Sync across MPI ranks
get_shape_ids()list[int]All shape IDs
size()intNumber of shapes
to_json()dictExport all shapes as JSON
save_to(path, file, opt)Save to file
load_from(path, file, opt)Load from file
inspect(filepath)Inspect file metadata

Example:

import phynexis
pm = phynexis.parsim
U = phynexis.utils

ss = pm.ShapeStore()
sphere = U.shape.Sphere(0.5)
sid = ss.insert(sphere)
print(sid) # 0

entry = ss.get(ss.find(sid))
print(entry.label) # ''

ss.set_label(sid, "particle")
print(ss.get_label_of(sid)) # "particle"

ShapeStoreEntry

Read-only entry returned by ShapeStore.get().

AttributeTypeDescription
shapeShapeThe stored shape
labelstrUser-defined label
need_syncboolMPI sync flag

ShapeStoreHandle

Lightweight handle with index and epoch fields.

Views

NodeViewById / NodeViewByIndex

ClassDescription
NodeViewByIdView nodes by stable ID
NodeViewByIndexView nodes by contiguous index

EdgeViewById / EdgeViewByIndex

ClassDescription
EdgeViewByIdView edges by stable ID
EdgeViewByIndexView edges by contiguous index

HyperEdgeViewById / HyperEdgeViewByIndex

ClassDescription
HyperEdgeViewByIdView hyperedges by stable ID
HyperEdgeViewByIndexView hyperedges by contiguous index

PropertiesView

Generic property accessor view for nodes/edges.

Known Issues

EdgeSet / HyperEdgeSet lack add/remove convenience methods

Only initialize(), print_info(), and views() are exposed. Use SetBase.emplace() / erase() for modifications.

Status: noted

ShapeStoreHandle uses module_local()

ShapeStoreHandle is registered with pybind11::module_local() to avoid conflict with FieldHandle from phynexis.fields. Cross-module type checking (e.g., isinstance(handle, FieldHandle)) will not work.

Status: noted