cotengra.nodeops

Attributes

Classes

NodeOpsFrozenset

Namespace for interacting with frozenset[int] as contraction tree nodes.

BitSetInt

A bitset for keeping track of dense sets of integers. Subclass of

NodeOpsBitSetInt

Namespace for interacting with BitSetInt as contraction tree nodes.

NodeOpsSSA

Functions

get_nodeops(node_type_str[, N])

Get the node operations namespace for the given node type.

Module Contents

class cotengra.nodeops.NodeOpsFrozenset[source]

Namespace for interacting with frozenset[int] as contraction tree nodes.

__slots__ = ()
copy()[source]
node_type

The type used for nodes, to check isinstance with.

node_size

Function to get the size of a node.

node_from_seq

From a sequence of integers, construct node (frozenset).

new_node_for_seq
static node_from_single(x)[source]

From single integer x, construct node (frozenset).

static node_supremum(size)[source]

Return the node containing all elements up to size.

static node_get_single_el(node)[source]

Assuming node has one element, return it.

static node_tie_breaker(x)[source]

A tie breaker function for ordering nodes when they are the same size. Returns the negative of the smallest element in the node. Nodes with larger node_tie_breaker values get contracted first.

static is_valid_node(node)[source]

Check node is of type frozenset[int].

static node_union(x, y)[source]

Return the node given by the union of two nodes.

static node_union_it(bs)[source]

Return the node given by the union of an iterable of nodes.

new_node_for_union[source]
static node_issubset(x, y)[source]

Check if node x is a subset of node y.

static is_leaf(node)[source]
static is_supremum(node, N)[source]
class cotengra.nodeops.BitSetInt[source]

Bases: int

A bitset for keeping track of dense sets of integers. Subclass of int that overrides -, & and | and provides __len__ and __iter__. As of python 3.8 doesn’t seem much better than using frozenset[int] (slower and limited memory savings).

Parameters:

it (Iterable[int] or int) – If sequence of int, treat these as the set members. If raw int interpret as bitset directly.

__slots__ = ()
__hash__()[source]

Return hash(self).

classmethod infimum()[source]
classmethod supremum(size)[source]
__len__()[source]
iter_sparse()[source]
iter_dense()[source]
iter_numpy()[source]
__iter__()[source]
__contains__(i)[source]
__sub__(i)[source]

Return self-value.

difference(i)[source]
__and__(i)[source]

Return self&value.

intersection(i)[source]
__or__(i)[source]

Return self|value.

union()[source]
issubset(other)[source]

Check if this bitset is a subset of another bitset.

x.issubset(y) returns True if all bits set in x are also set in y. Equivalent to: x & y == x

__repr__()[source]

Return repr(self).

class cotengra.nodeops.NodeOpsBitSetInt[source]

Namespace for interacting with BitSetInt as contraction tree nodes.

__slots__ = ()
copy()[source]
node_type[source]
node_size[source]
node_from_seq[source]
new_node_for_seq[source]
static node_from_single(x)[source]
static node_supremum(size)[source]
static node_get_single_el(node)[source]
static node_tie_breaker(x)[source]
static is_valid_node(node)[source]
static node_union(x, y)[source]
static node_union_it(bs)[source]
new_node_for_union[source]
static node_issubset(x, y)[source]
static is_leaf(node)[source]
static is_supremum(node, N)[source]
class cotengra.nodeops.NodeOpsSSA(N)[source]
__slots__ = ('ssa', 'N')
ssa
N
copy()[source]
get_next_ssa()[source]
node_type
abstractmethod node_size(node)[source]
node_from_single(x)[source]
node_supremum(size)[source]
node_get_single_el(node)[source]
node_tie_breaker(x)[source]
is_valid_node(node)[source]
abstractmethod node_union(x, y)[source]
abstractmethod node_union_it(bs)[source]
new_node_for_union(nodes)[source]

Get a new node label for the union of nodes. We use this rather than the above methods to be explicit that we can only create new node labels, not reconstruct labels from the constituent nodes.

abstractmethod node_from_seq(seq)[source]
new_node_for_seq(seq)[source]

Get a new node for a sequence of raw input positions. We use this rather than the above method to be explicit that we can only create new node labels, not reconstruct labels from the constituent raw input positions.

abstractmethod node_issubset(x, y)[source]
is_leaf(node)[source]
is_supremum(node, N)[source]
cotengra.nodeops.nodeops_frozenset
cotengra.nodeops.nodeops_bitsetint
cotengra.nodeops.get_nodeops(node_type_str: str, N=None)[source]

Get the node operations namespace for the given node type.

Parameters:

node_type_str (str) – The node type as a string. One of “frozenset[int]”, “BitSetInt”.

Returns:

The corresponding node operations namespace.

Return type:

NodeOpsFrozenset or NodeOpsBitSetInt