Configs#
Coloring configuration of a Graph.
This module defines make(), a factory that builds a numba
jitclass container. A Config tracks the
color assigned to each node of a graph and maintains, in sync, the set of
nodes for which a user-supplied guard predicate currently fires.
- tinto.configs.make(guard=None)[source]#
Build a
Configjitclass wired to guard.Because
numbarequires everyjitclass()method to be specialized at class-definition time, the guard predicate is captured here as a closure rather than passed at instantiation.- Parameters:
guard (callable or
None, default=``None``) – Predicateguard(config, i) -> booldeciding whether node i is enabled. WhenNone,color_clash()is used, which enables a node iff it shares its color with a neighbor.- Returns:
A jitclass implementing the API documented on
Config.- Return type:
Notes
Two calls with the same (normalized) guard return the same compiled jitclass — the class is built only once per distinct guard. Guards are keyed by identity;
Noneandcolor_clash()are treated as the same key. Usetinto.configs._make_config.cache_clear()to drop the cache in the rare cases it is needed.Examples
>>> from tinto.graphs import line >>> from tinto.configs import make >>> Config = make() >>> c = Config(line(4)) >>> c.total 4
Passing an explicit guard wires the returned class to it rather than to
color_clash():>>> from tinto.guards import color_min >>> ConfigMin = make(color_min) >>> cm = ConfigMin(line(4)) >>> cm.total > 0 True
The number of available colors is adjustable post-construction:
>>> c.set_k(5) >>> c.k 5 >>> c.local_count.shape (5,)
And
Config.shuffle_ids()reseeds the per-Config id permutation without rebuilding the graph — useful between replicas when a guard breaks ties onids. With the default guard (color_clash(), which ignores ids),idsstarts empty and is populated on demand:>>> c.ids.tolist() [] >>> c.shuffle_ids() >>> sorted(c.ids.tolist()) [0, 1, 2, 3]
A guard that reads ids (e.g.
color_clash_tie()) flips theConfig.uses_idsflag and makesConfig.__init__draw a fresh permutation directly, so thatConfig.check_all()sees a valid tie-breaking order on the first call:>>> from tinto.guards import color_clash_tie >>> ConfigTie = make(color_clash_tie) >>> ConfigTie.uses_ids True >>> ct = ConfigTie(line(4)) >>> sorted(ct.ids.tolist()) [0, 1, 2, 3]
Repeated calls with the same (normalized) guard hit the cache:
>>> make() is make() True >>> make() is make(color_clash) True >>> make(color_clash) is make(color_min) False
Note
The Config jitclass is built dynamically by tinto.configs.make() and
cannot be reached by automodule. Its full API — attributes, methods and
examples — lives in the docstring of make() above.