cana.canalization.cm_lut module

Reconstruct a look-up table (LUT) from a Canalizing Map (CM) graph.

This module interprets a CM as a networkx.DiGraph of typed nodes. Evaluation is modular and topology-based: each node activates from its predecessors according to its node kind. Edge type attributes (if present) are ignored for scoring — they may still be used for drawing or legacy CANA compatibility.

Notes

A CM encodes schemata as McCulloch–Pitts-style threshold units, optionally nested to express two-symbol / permutation structure.

Node kinds

  • variable + mode=input : active iff the assignment matches value.

  • variable + mode=output : normally active iff any predecessor is active (used when asking whether the node itself is on). Autoregulation exception: CANA’s canalizing_map reuses the same var-{id}-out-{v} node as both the current-state literal and the next-state output, which creates a directed cycle. When that variable’s key appears in the assignment, evaluation treats the node as an input literal (assignment match) so thresholds can fire; output claims are still decided by claimed_outputs() via threshold predecessors.

  • threshold : active iff (# active predecessors) >= tau. Optional annotation role (see THRESHOLD_ROLES) describes the canalization layer; it does not change evaluation.

  • fusion : active iff any predecessor is active (logical OR). Equivalent to a threshold with tau=1; kept for legacy / drawing.

Firing / claim rule

score(thr) = # active predecessors
fire       <=>  score >= tau
claim(out) <=>  any predecessor of the output variable is active

Per input assignment, collect claimed output polarities:

  • {0} or {1} → that LUT entry.

  • {0, 1} → conflict at that row.

  • {} → uncovered (incomplete).

Inputs that never appear in the CM are free variables over the full 2^k table. Input order is taken from input_order if given, otherwise from sorted input ids discovered in the graph.

cana.canalization.cm_lut.ROLE_SCHEMA = 'schema'

Two-symbol schema unit (typically a root that feeds an output).

cana.canalization.cm_lut.ROLE_SYMMETRY = 'symmetry'

Permutation-symmetry aggregate over one or more polarity groups.

cana.canalization.cm_lut.ROLE_POLARITY0 = 'polarity0'

0-polarity fibre within a permutation symmetry.

cana.canalization.cm_lut.ROLE_POLARITY1 = 'polarity1'

1-polarity fibre within a permutation symmetry.

cana.canalization.cm_lut.THRESHOLD_ROLES = frozenset({'polarity0', 'polarity1', 'schema', 'symmetry'})

Allowed values for make_threshold()’s role argument.

class cana.canalization.cm_lut.CMLutResult(outputs, input_names, has_conflict, is_incomplete, conflict_states=<factory>, uncovered_states=<factory>)[source]

Bases: object

Result of reconstructing a LUT from a canalizing map.

Parameters:
  • outputs (List[int | None])

  • input_names (List[str | int])

  • has_conflict (bool)

  • is_incomplete (bool)

  • conflict_states (List[str])

  • uncovered_states (List[str])

outputs

LUT entries indexed by the integer whose binary representation is the input state (MSB = first input). None means uncovered or conflicted.

Type:

list of {0, 1, None}

input_names

Ordered input identifiers used for the LUT (MSB first).

Type:

list of int or str

has_conflict

True if at least one input state is claimed by both output polarities.

Type:

bool

is_incomplete

True if at least one input state is claimed by no t-unit.

Type:

bool

conflict_states

Binary state strings (MSB first) that are conflicted.

Type:

list of str

uncovered_states

Binary state strings (MSB first) that are uncovered.

Type:

list of str

outputs: List[int | None]
input_names: List[str | int]
has_conflict: bool
is_incomplete: bool
conflict_states: List[str]
uncovered_states: List[str]
lut_string(uncovered='?', conflict='X')[source]

Return a compact string view of the LUT.

Parameters:
  • uncovered (str, optional) – Character used for uncovered rows. Default is '?'.

  • conflict (str, optional) – Character used for conflicted rows. Default is 'X'.

Returns:

One character per LUT row, length 2**k.

Return type:

str

cana.canalization.cm_lut.iter_nodes_of_type(cm, node_type)[source]

Yield CM nodes whose type attribute equals node_type.

Parameters:
  • cm (networkx.DiGraph) – Canalizing map graph.

  • node_type (str) – Node type to select ('variable', 'threshold', or 'fusion').

Yields:
  • node_id (hashable) – Graph node identifier.

  • data (dict) – Node attribute dictionary.

Return type:

Iterable[Tuple[Any, dict]]

cana.canalization.cm_lut.discover_input_keys(cm)[source]

Discover input identifiers present in the CM.

Prefers numeric ids parsed from node names var-{id}-out-{val}, otherwise uses the node label (or the node id). Returned sorted for a stable LUT order.

Includes mode=input variables and mode=output variables that feed a threshold/fusion (CANA autoregulation reuses output node ids as self-literals).

Parameters:

cm (networkx.DiGraph) – Canalizing map graph.

Returns:

Sorted input keys (integers first, then string labels).

Return type:

list of int or str

cana.canalization.cm_lut.node_active(cm, node_id, assignment, memo=None)[source]

Return whether a CM node is active under an assignment.

Activation is defined by node kind and predecessors only (edge types are ignored):

  • input variable: assignment matches value

  • output variable: if the variable key is in assignment (self-loop / shared CANA id used as a literal), assignment matches value; otherwise any predecessor is active

  • fusion: any predecessor is active

  • threshold: number of active predecessors >= tau

Parameters:
  • cm (networkx.DiGraph) – Canalizing map graph.

  • node_id (hashable) – Node to evaluate.

  • assignment (dict) – Mapping from input key to 0 or 1.

  • memo (dict, optional) – Per-assignment cache. Values are True/False when resolved, or None while a node is on the recursion stack (cycle guard for non-variable combinational cycles).

Returns:

True if the node is active.

Return type:

bool

Raises:

ValueError – If evaluating node_id encounters a directed cycle among threshold/fusion nodes, or if node_id has an unknown type.

cana.canalization.cm_lut.fusion_active(cm, fusion_id, assignment)[source]

Return whether a fusion node is active under an assignment.

A fusion is active iff any of its predecessors is active (logical OR).

Parameters:
  • cm (networkx.DiGraph) – Canalizing map graph.

  • fusion_id (hashable) – Fusion node id.

  • assignment (dict) – Mapping from input key to 0 or 1.

Returns:

True if at least one predecessor is active.

Return type:

bool

Raises:

ValueError – If fusion_id is not a fusion node.

cana.canalization.cm_lut.tunit_score(cm, thr_id, assignment)[source]

Compute the score of a threshold unit under an assignment.

The score is the number of active predecessors (inputs, fusions, or nested thresholds).

Parameters:
  • cm (networkx.DiGraph) – Canalizing map graph.

  • thr_id (hashable) – Threshold (t-unit) node id.

  • assignment (dict) – Mapping from input key to 0 or 1.

Returns:

Non-negative contribution count.

Return type:

int

Raises:

ValueError – If thr_id is not a threshold node.

cana.canalization.cm_lut.tunit_fires(cm, thr_id, assignment)[source]

Return whether a threshold unit fires under an assignment.

Fires when tunit_score(cm, thr_id, assignment) >= tau.

Parameters:
  • cm (networkx.DiGraph) – Canalizing map graph.

  • thr_id (hashable) – Threshold (t-unit) node id.

  • assignment (dict) – Mapping from input key to 0 or 1.

Returns:

True if the t-unit fires.

Return type:

bool

Raises:

ValueError – If thr_id is not a threshold node.

cana.canalization.cm_lut.claimed_outputs(cm, assignment)[source]

Return output polarities claimed under an assignment.

An output variable claims its polarity when any of its predecessors is active (typically a firing schema-level threshold).

Parameters:
  • cm (networkx.DiGraph) – Canalizing map graph.

  • assignment (dict) – Mapping from input key to 0 or 1.

Returns:

Subset of {0, 1}. Empty if nothing claims; both values if there is a conflict.

Return type:

set of int

cana.canalization.cm_lut.lut_from_canalizing_map(cm, input_order=None)[source]

Build a (possibly partial or conflicting) LUT from a canalizing map.

Parameters:
  • cm (networkx.DiGraph) – Canalizing map as a directed graph of typed nodes. Evaluation uses topology and node kinds only (see module docstring).

  • input_order (sequence of int or str, optional) – Explicit input order (MSB first). If omitted, inputs are discovered from the graph and sorted via discover_input_keys().

Returns:

Reconstructed LUT together with conflict / incompleteness flags and the lists of affected binary states.

Return type:

CMLutResult

Notes

This function is purely graph-based. It does not call BooleanNode.canalizing_map or two-symbol canalization code.

cana.canalization.cm_lut.input_ids_in_order(G)[source]

Return input variable ids in first-seen label order.

Suitable as input_order for lut_from_canalizing_map().

Parameters:

G (DiGraph)

Return type:

List[int]

cana.canalization.cm_lut.connect(G, src, dst)[source]

Add an edge, inferring type from endpoint node kinds.

Does not mutate threshold attributes (no out stamping).

Parameters:
  • G (networkx.DiGraph) – CM graph.

  • src (hashable) – Existing node ids.

  • dst (hashable) – Existing node ids.

Raises:

ValueError – If the (src_kind, dst_kind) pair is not allowed.

Return type:

None

cana.canalization.cm_lut.make_input_node(G, label, value)[source]

Add an input variable node; label determines the shared var_id.

Parameters:
  • G (networkx.DiGraph) – Graph to mutate.

  • label (str) – Input name. New labels get a fresh id; existing labels reuse theirs.

  • value (int) – Polarity (0 or 1).

Returns:

Node name var-{id}-out-{value}.

Return type:

str

Raises:

ValueError – If this (label, value) pair already exists, or value is not 0/1.

cana.canalization.cm_lut.make_output_node(G, label, value)[source]

Add an output variable node for the CM’s single function label.

Parameters:
  • G (networkx.DiGraph) – Graph to mutate.

  • label (str) – Function / output name. Both polarities share one allocated id.

  • value (int) – Output polarity (0 or 1).

Returns:

Node name var-{output_id}-out-{value}.

Return type:

str

Raises:

ValueError – If a different output label is already registered, if this polarity already exists, or if value is not 0/1.

cana.canalization.cm_lut.make_threshold(G, tau, role='schema')[source]

Add a threshold (t-unit) node; tid is assigned automatically.

Thresholds do not store an out polarity — claims come only from edges into output variables, so build order does not matter.

Parameters:
  • G (networkx.DiGraph) – Graph to mutate.

  • tau (int) – Firing threshold.

  • role (str, optional) – Canalization-layer annotation (does not affect evaluation). One of THRESHOLD_ROLES. Default is 'schema'.

Returns:

Node name thr-{tid}.

Return type:

str

Raises:

ValueError – If role is not in THRESHOLD_ROLES.

cana.canalization.cm_lut.make_fusion(G)[source]

Add a fusion junction node; index is assigned automatically.

Fusion is legacy OR sugar (equivalent to a tau=1 threshold over inputs). Prefer nested thresholds for new maps.

Parameters:

G (networkx.DiGraph) – Graph to mutate.

Returns:

Node name fus-{index}.

Return type:

str