morphogen.design.csp¶
Constraint solvers for tile assemblies.
wave_function_collapseRandom compatible assemblies of any size: arc consistency (each tile left in the domain of a cell has a compatible tile in every neighbouring domain), then cells of least entropy are given a tile at random (with the tile weights) and the choice is propagated, backtracking on contradictions (domains are bit sets, Numba).
TransferMatrixExact counting and exact uniform sampling of the compatible assemblies of a box, with a transfer matrix between the admissible cross-sections along x (statistical physics). It needs few admissible cross-sections: small sections, or constrained tile sets.
count_polarized_blocksExact number of compatible assemblies of polarized blocks, for larger boxes: the strain sign along every line of blocks alternates, which reduces the problem to sign variables on the faces of the box (a gauge), summed by dynamic programming.
- morphogen.design.csp.initial_domains(tileset: TileSet, shape, *, periodic: bool = True, boundary=None, allowed=None) ndarray[source]¶
Boolean domains
(n0, n1, n2, n_tiles): tiles of positive weight, restricted byallowed(same shape) and, on the faces of non-periodic boxes, to tiles whose outer faces match the labelboundary.
- morphogen.design.csp.wave_function_collapse(tileset: TileSet, shape, rng: Generator, *, periodic: bool = True, boundary: int | None = None, allowed=None, max_backtracks: int | None = None, restarts: int = 5) ndarray[source]¶
A random compatible assembly of
shapetiles ((n0, n1, 1)for planar sets).allowed(boolean,shape + (n_tiles,)) restricts the tiles of each cell, e.g. to grade a design in space;boundaryis the label the outer faces of a non-periodic box must match. Raises ValueError when no assembly exists, or when the search gave up afterrestartsattempts ofmax_backtracksbacktracks.
- class morphogen.design.csp.TransferMatrix(tileset: TileSet, section, *, periodic: bool = False, max_states: int = 20000)[source]¶
Bases:
objectAdmissible cross-sections
(n1, n2)of a tile set and the transfer matrix between consecutive sections along x (T[s, s'] = 1when section s’ may follow section s).Counting and sampling use exact integer arithmetic. Periodic boxes need the closed walks of the transfer matrix (one sum per section): keep the number of sections modest (
max_states).- property n_states: int¶
- morphogen.design.csp.count_assemblies(tileset: TileSet, shape, *, periodic: bool = False, max_states: int = 20000) int[source]¶
Exact number of compatible assemblies of a box of
shapetiles.
- morphogen.design.csp.sample_uniform(tileset: TileSet, shape, rng: Generator, *, periodic: bool = False, max_states: int = 20000) ndarray[source]¶
A compatible assembly drawn uniformly at random (exact, by transfer matrix).
- morphogen.design.csp.count_polarized_blocks(shape, *, periodic: bool = False) int[source]¶
Number of compatible assemblies of polarized blocks in a box of
shapeblocks.Writing the strain signs of the block (i, j, k) as
e_x = F_x(j, k) (-1)^i,e_y = F_y(i, k) (-1)^j,e_z = F_z(i, j) (-1)^k(alternation along every line), an assembly is a choice of the sign arrays such that no block has three equal signs. The sum overF_zfactorizes over the columns, then overF_yover the rows i, which leaves a sum overF_x(2^(ny nz)terms, the smallest section is chosen). Periodic boxes need even numbers of blocks. Exact up to 2^62.