Starters#

Factories producing initial Config instances.

A starter is a numba jitclass exposing draw() -> Config that returns a freshly initialized Config. Starters are consumed by tinto.runners.mc(), which calls draw() once per replica to seed the Monte-Carlo samples.

from_graph() covers both regimes from a fixed user-supplied graph: deterministic uniform coloring (color given as an integer, including 0 for the all-zeros default) and stochastic coloring (color=None).

from_cayley(), from_erdos_renyi() and from_bipartite() follow the same coloring contract but generate a fresh random graph on every draw() call, so that tinto.runners.mc() samples over a distribution of graphs (one Cayley tree, one \(G(n, p)\) or one \(G(n_1, n_2, p)\) per replica) rather than over a single fixed topology. They take the generator’s parameters at construction time, leaving (Config, color) as the sole compilation key — exactly as the graph is a construction-time argument of from_graph().

Every starter also takes, at construction time, the palette size k and the number of initial colors k_init (both 0 by default). In the stochastic regime, the initial colors are drawn among the first k_init colors (all of them when k_init is 0). When k is 0, the palette has max(k_init, Delta + 1) colors, so that a free color always exists: a start with k_init < Delta + 1 colors, as in the exact stabilization-time paper, keeps a palette of Delta + 1.

tinto.starters._from_bipartite(Config, color)[source]#
tinto.starters._from_cayley(Config, color)[source]#
tinto.starters._from_erdos_renyi(Config, color)[source]#
tinto.starters._from_graph(Config, color)[source]#
tinto.starters._palette(graph, k, k_init)[source]#

Palette size: k when given, else max(k_init, Delta + 1).

Examples

>>> from tinto.graphs import line
>>> _palette(line(5), 0, 0), _palette(line(5), 0, 2), _palette(line(5), 0, 5), _palette(line(5), 4, 2)
(3, 3, 5, 4)
tinto.starters.from_bipartite(Config, color=None)[source]#

Build a starter drawing configs over a fresh random bipartite \(G(n_1, n_2, p)\) graph.

Same contract as from_erdos_renyi(), with the generator tinto.graphs.bipartite(): the constructor takes the side sizes n1, n2 and the edge probability p, and each draw() call generates a new graph, allocates a fresh Config over it and seeds it according to color (None randomizes, 0 keeps the bare constructor, any other int forces a uniform coloring).

Parameters:
  • Config (type) – Jitclass returned by tinto.configs.make().

  • color (int or None, default=``None``) – Initial color. None randomizes every node; any integer in range(k) forces a uniform coloring at that value.

Returns:

A jitclass FromBipartiteStarter with constructor (n1=50, n2=50, p=0.5, k=0, k_init=0) and method draw() -> Config.

Return type:

type

Examples

>>> from tinto.io import set_seed
>>> from tinto.configs import make as make_config
>>> set_seed(0)
>>> Config = make_config()
>>> c = from_bipartite(Config)(3, 5, p=0.5).draw()
>>> c.graph.n
8
>>> c.total == int(c.enabled.sum())
True
>>> from_bipartite(Config, color=0)(2, 2, p=1.0).draw().colors.tolist()
[0, 0, 0, 0]
>>> from_bipartite(Config, color=1)(2, 2, p=1.0).draw().colors.tolist()
[1, 1, 1, 1]
>>> from_bipartite(Config) is from_bipartite(Config)
True
tinto.starters.from_cayley(Config, color=None)[source]#

Build a starter drawing configs over a fresh random Cayley tree.

The returned jitclass takes the tree size n at construction time; each draw() call generates a new random Cayley tree via tinto.graphs.cayley(), allocates a fresh Config over it, and seeds it according to color with the exact same contract as from_graph():

  • color=None (default): the config is randomized via color_randomize().

  • color=0: the bare Config constructor is used, which already initializes every node to color 0.

  • any other int: the config is forced to that uniform color via color_uniform().

Because a fresh graph is drawn per replica, tinto.runners.mc() samples the dynamics over the distribution of Cayley trees on n nodes rather than over a single fixed tree.

Parameters:
  • Config (type) – Jitclass returned by tinto.configs.make().

  • color (int or None, default=``None``) – Initial color. None randomizes every node; any integer in range(k) forces a uniform coloring at that value.

Returns:

A jitclass FromCayleyStarter with constructor (n=100, k=0, k_init=0) and method draw() -> Config.

Return type:

type

Examples

Stochastic regime (default, color=None); a fresh tree on n nodes is drawn each call:

>>> from tinto.io import set_seed
>>> from tinto.configs import make as make_config
>>> set_seed(0)
>>> Config = make_config()
>>> c = from_cayley(Config)(8).draw()
>>> c.graph.n
8
>>> bool(((c.colors >= 0) & (c.colors < c.k)).all())
True
>>> c.total == int(c.enabled.sum())
True

Uniform regimes behave like from_graph(), independently of the drawn topology:

>>> from_cayley(Config, color=0)(4).draw().colors.tolist()
[0, 0, 0, 0]
>>> from_cayley(Config, color=1)(4).draw().colors.tolist()
[1, 1, 1, 1]

Repeated calls with the same (Config, color) hit the cache:

>>> from_cayley(Config) is from_cayley(Config)
True
>>> from_cayley(Config, color=0) is from_cayley(Config, color=1)
False

Notes

Two calls with the same (Config, color) return the same compiled starter. Config is keyed by identity and color by value.

tinto.starters.from_erdos_renyi(Config, color=None)[source]#

Build a starter drawing configs over a fresh random \(G(n, p)\) graph.

The returned jitclass takes the node count n and edge probability p at construction time; each draw() call generates a new random Erdős–Rényi graph via tinto.graphs.erdos_renyi(), allocates a fresh Config over it, and seeds it according to color with the exact same contract as from_graph():

  • color=None (default): the config is randomized via color_randomize().

  • color=0: the bare Config constructor is used, which already initializes every node to color 0.

  • any other int: the config is forced to that uniform color via color_uniform().

Because a fresh graph is drawn per replica, tinto.runners.mc() samples the dynamics over the \(G(n, p)\) ensemble rather than over a single fixed graph.

Parameters:
  • Config (type) – Jitclass returned by tinto.configs.make().

  • color (int or None, default=``None``) – Initial color. None randomizes every node; any integer in range(k) forces a uniform coloring at that value.

Returns:

A jitclass FromErdosRenyiStarter with constructor (n=100, p=0.5, k=0, k_init=0) and method draw() -> Config.

Return type:

type

Examples

Stochastic regime (default, color=None); a fresh \(G(n, p)\) graph is drawn each call:

>>> from tinto.io import set_seed
>>> from tinto.configs import make as make_config
>>> set_seed(0)
>>> Config = make_config()
>>> c = from_erdos_renyi(Config)(8, p=0.5).draw()
>>> c.graph.n
8
>>> bool(((c.colors >= 0) & (c.colors < c.k)).all())
True
>>> c.total == int(c.enabled.sum())
True

Uniform regimes behave like from_graph(), independently of the drawn topology (p=1.0 guarantees enough colors for color=1):

>>> from_erdos_renyi(Config, color=0)(4, p=0.5).draw().colors.tolist()
[0, 0, 0, 0]
>>> from_erdos_renyi(Config, color=1)(4, p=1.0).draw().colors.tolist()
[1, 1, 1, 1]

Repeated calls with the same (Config, color) hit the cache:

>>> from_erdos_renyi(Config) is from_erdos_renyi(Config)
True
>>> from_erdos_renyi(Config, color=0) is from_erdos_renyi(Config, color=1)
False

Notes

Two calls with the same (Config, color) return the same compiled starter. Config is keyed by identity and color by value.

tinto.starters.from_graph(Config, color=None)[source]#

Build a starter class drawing configs over a fixed graph.

The returned jitclass takes a Graph at construction time; each draw() call allocates a fresh Config and seeds it according to color:

  • color=None (default): the config is randomized via color_randomize().

  • color=0: the bare Config constructor is used, which already initializes every node to color 0.

  • any other int: the config is forced to that uniform color via color_uniform().

The None sentinel for the stochastic regime follows the usual Python idiom (np.random.seed(None), open(..., encoding=None), …) and avoids overloading a positive integer to mean “no fixed color”.

Parameters:
  • Config (type) – Jitclass returned by tinto.configs.make().

  • color (int or None, default=``None``) – Initial color. None randomizes every node; any integer in range(k) forces a uniform coloring at that value.

Returns:

A jitclass FromGraphStarter with constructor (graph, k=0, k_init=0) and method draw() -> Config.

Return type:

type

Examples

Stochastic regime (default, color=None):

>>> from tinto.io import set_seed
>>> from tinto.graphs import line
>>> from tinto.configs import make as make_config
>>> set_seed(0)
>>> Config = make_config()
>>> Starter = from_graph(Config)
>>> c = Starter(line(8)).draw()
>>> bool(((c.colors >= 0) & (c.colors < c.k)).all())
True
>>> c.total == int(c.enabled.sum())
True

Two initial colors on a path, whose palette stays Delta + 1 = 3:

>>> c = Starter(line(8), k_init=2).draw()
>>> c.k, bool((c.colors < 2).all())
(3, True)

Uniform regime at color 0:

>>> c = from_graph(Config, color=0)(line(4)).draw()
>>> c.colors.tolist()
[0, 0, 0, 0]

A non-zero uniform color is equally accepted:

>>> c = from_graph(Config, color=1)(line(4)).draw()
>>> c.colors.tolist()
[1, 1, 1, 1]

Repeated calls with the same (Config, color) hit the cache:

>>> from_graph(Config) is from_graph(Config)
True
>>> from_graph(Config, color=None) is from_graph(Config)
True
>>> from_graph(Config, color=0) is from_graph(Config, color=1)
False

Notes

Two calls with the same (Config, color) return the same compiled starter. Config is keyed by identity and color by value.

Note

The FromGraphStarter, FromCayleyStarter and FromErdosRenyiStarter jitclasses are built dynamically by tinto.starters.from_graph(), tinto.starters.from_cayley() and tinto.starters.from_erdos_renyi() respectively, and cannot be reached by automodule. Their constructors and draw() methods are described in the docstrings of the factory functions above.