kwant.graph.CGraph

class kwant.graph.CGraph

Bases: object

A compressed graph which can be efficiently queried for the existence of edges and outgoing neighbors.

Objects of this class do not initialize the members themselves, but expect that they hold usable values. A good way to create them is by compressing a Graph.

Iterating over a graph yields a sequence of (tail, head) pairs of all edges. The number of an edge in this sequence equals its edge ID. The built-in function enumerate can thus be used to easily iterate over all edges along with their edge IDs.

Methods

all_edge_ids()

Return an iterator over all edge IDs of edges with a given tail and head.

Parameters:

tail : integer

head : integer

Returns:

edge_id : integer

Raises:

NodeDoesNotExist

EdgeDoesNotExistError

DisabledFeatureError

If tail is negative and the graph is not two-way compressed.

edge_id()

Return the edge ID of an edge given its sequential number.

Parameters:

edge_nr : integer

Returns:

edge_id : integer

Raises:

DisabledFeatureError

If edge_nr_translation was not enabled during graph compression.

EdgeDoesNotExistError

first_edge_id()

Return the edge ID of the first edge (tail, head).

Parameters:

tail : integer

head : integer

Returns:

edge_id : integer

Raises:

NodeDoesNotExist

EdgeDoesNotExistError

DisabledFeatureError

If tail is negative and the graph is not two-way compressed.

Notes

This method is useful for graphs where each edge occurs only once.

has_dangling_edges()
has_edge()

Does the graph contain the edge (tail, head)?

Parameters:

tail : integer

head : integer

Returns:

had_edge : boolean

Raises:

NodeDoesNotExistError

EdgeDoesNotExistError

DisabledFeatureError

If tail is negative and the graph is not two-way compressed.

head()

Return the head of an edge, given its edge ID.

Parameters:edge_id : integer
Raises:EdgeDoesNotExistError

Notes

This method executes in constant time. It works for all edge IDs, returning both positive and negative heads.

in_edge_ids()

Return the IDs of incoming edges of a node.

Parameters:

node : integer

Returns:

edge_ids : sequence of integers

Raises:

NodeDoesNotExistError

DisabledFeatureError

If the graph is not two-way compressed.

in_neighbors()

Return the nodes which point to a node.

Parameters:

node : integer

Returns:

nodes : sequence of integers

Raises:

NodeDoesNotExistError

DisabledFeatureError

If the graph is not two-way compressed.

out_edge_ids()

Return the IDs of outgoing edges of node.

Parameters:node : integer
Returns:edge_ids : sequence of integers
Raises:NodeDoesNotExistError
out_neighbors()

Return the nodes a node points to.

Parameters:node : integer
Returns:nodes : sequence of integers
Raises:NodeDoesNotExistError
tail()

Return the tail of an edge, given its edge ID.

Parameters:

edge_id : integer

Returns:

tail : integer

If the edge exists and is positive.

None

If the tail is negative.

Raises:

EdgeDoesNotExistError

Notes

The average performance of this method is O(log num_nodes) for non-negative tails and O(1) for negative ones.

write_dot()

Write a representation of the graph in dot format to file.

Parameters:file : file-like object

Notes

That resulting file can be visualized with dot(1) or neato(1) form the graphviz package.

Attributes

edge_nr_translation
num_edges
num_nodes
num_px_edges
num_xp_edges
twoway

Previous topic

kwant.graph.Graph

Next topic

kwant.graph.slice

This Page