cana.canalization.canalizing_map module

Build Canalizing Map (CM) graphs from two-symbol schemata.

A canalizing map is a directed networkx.DiGraph that encodes how input literals (and permutation-symmetric groups of them) force a Boolean node’s output. Schemata come from two-symbol canalization; each schema becomes a threshold unit that claims one output polarity when enough of its inputs fire.

Graph vocabulary

  • variable nodes var-{id}-out-{0|1} — an input or output at a fixed polarity.

  • threshold nodes — fire when at least tau predecessors are active. Optional role annotates the canalization layer (schema, symmetry, polarity0, polarity1); evaluation ignores it.

  • fusion nodes — OR of predecessors (legacy builder only, when a symmetry fibre needs only one matching literal).

Builders

Callers may select a builder by name via CM_BUILDERS or pass a callable with the same signature as build_canalizing_map_legacy().

Simplification

simplify_canalizing_map() (re-exported here) applies deterministic farthest-from-out threshold-unit reduction (LINEAR / AND / OR / OTHER under a compatibility gate). See cana.canalization.cm_simplify.

cana.canalization.canalizing_map.CM_BUILDERS: Dict[str, Callable[[...], DiGraph]] = {'canonical': <function build_canalizing_map_canonical>, 'legacy': <function build_canalizing_map_legacy>}

Named CM builders (legacy, canonical).

cana.canalization.canalizing_map.build_canalizing_map(two_symbols, *, node_id, inputs, name, constant=False, polarity=None, input_labels=None, k=None, builder='legacy', output=None)[source]

Build a canalizing map using a named or callable builder.

Parameters:
  • builder (str or callable, optional) – Registry key in CM_BUILDERS (default 'legacy') or a callable with the same signature as build_canalizing_map_legacy().

  • two_symbols (Tuple[Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]], Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]]])

  • node_id (int)

  • inputs (Sequence[int])

  • name (str)

  • constant (bool)

  • polarity (int | None)

  • input_labels (Mapping[int, str] | None)

  • k (int | None)

  • output (int | None)

Return type:

DiGraph

:param Same as build_canalizing_map_legacy().:

Returns:

Canalizing map graph.

Return type:

networkx.DiGraph

Raises:
  • KeyError – If builder is a string not present in CM_BUILDERS.

  • TypeError – If builder is neither a string nor a callable.

Parameters:
  • two_symbols (Tuple[Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]], Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]]])

  • node_id (int)

  • inputs (Sequence[int])

  • name (str)

  • constant (bool)

  • polarity (int | None)

  • input_labels (Mapping[int, str] | None)

  • k (int | None)

  • builder (str | Callable[[...], DiGraph])

  • output (int | None)

cana.canalization.canalizing_map.build_canalizing_map_canonical(two_symbols, *, node_id, inputs, name, constant=False, output=None, input_labels=None, k=None)[source]

Build a CM graph with nested schema / symmetry / polarity thresholds.

Same parameters as build_canalizing_map_legacy(). Unlike the legacy builder, this never creates fusion nodes: every permutation group becomes a ROLE_SYMMETRY threshold, and every nonempty polarity fibre becomes a ROLE_POLARITY0 / ROLE_POLARITY1 threshold nested under that symmetry unit.

Schema tau is #fixed_literals + #active_permutation_groups. Symmetry tau is the number of polarity fibres in that group. Polarity tau is the fibre count in the representative schema.

Parameters:
  • two_symbols (Tuple[Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]], Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]]])

  • node_id (int)

  • inputs (Sequence[int])

  • name (str)

  • constant (bool)

  • output (int | None)

  • input_labels (Mapping[int, str] | None)

  • k (int | None)

Return type:

DiGraph

cana.canalization.canalizing_map.build_canalizing_map_legacy(two_symbols, *, node_id, inputs, name, constant=False, output=None, input_labels=None, k=None)[source]

Build a CM graph from two-symbol schemata (legacy CANA wiring).

Parameters:
  • two_symbols (tuple) – (schemata_for_0, schemata_for_1) as produced by two-symbol canalization. Each schema entry is (schema_str, permutation_groups, same_symbol_groups).

  • node_id (int) – Variable id for output nodes var-{node_id}-out-{0|1}.

  • inputs (sequence of int) – Input variable ids in LUT order (length k).

  • name (str) – Output variable label.

  • constant (bool, optional) – Stored on output variable nodes.

  • output (int or None, optional) – If 0 or 1, only that polarity is built; None builds both.

  • input_labels (mapping, optional) – Map from input variable id to display label. Defaults to str(id).

  • k (int, optional) – Number of inputs. Defaults to len(inputs).

Returns:

Canalizing map graph.

Return type:

networkx.DiGraph

cana.canalization.canalizing_map.simplify_canalizing_map(cm, *, copy=True, remove_isolates=True, skip_if_edges_increase=False)[source]

Simplify a CM / DCM by threshold-unit reduction (fixed point).

Safe rewrite rules applied until no candidate remains:

  1. Never remove or rewrite tau=0 thresholds (constant schemata).

  2. Threshold-unit reduction: if a threshold/fusion unit is LINEAR / AND / OR / OTHER and every successor class is compatible, wire all predecessors to all successors, bump each threshold/fusion successor by tau(T)-1, and delete T. Variables are never bumped. Compatibility:

    • LINEAR → AND, OR, LINEAR, OTHER

    • AND → AND, LINEAR

    • OR → OR, LINEAR

    • OTHER → LINEAR

    Non-schema OR/LINEAR units that claim variables are eligible.

Candidates are ordered farthest-from-out first (largest directed distance to a variable node), then by str(node_id). One rewrite is applied per iteration.

Parameters:
  • cm (networkx.DiGraph) – Canalizing map or dynamics canalization map.

  • copy (bool, optional) – If True (default), operate on a copy and leave cm unchanged.

  • remove_isolates (bool, optional) – If True (default), drop isolated nodes after rewriting.

  • skip_if_edges_increase (bool, optional) – If True, skip a reduction when wiring preds→succs would add more edges than removing the unit deletes. Reductions that leave the edge count unchanged are still applied. Default False.

Returns:

Simplified graph (a copy unless copy=False).

Return type:

networkx.DiGraph