Datasets:
Formats:
json
Languages:
English
Size:
1K - 10K
Tags:
matter-embryogenesis
developmental-fabrication
nanotechnology
self-assembly
materials-science
passive-networks
| """A fixed interpreter for a bounded, nonperiodic passive network family. | |
| Gene inheritance and frame/counter copying are IDEAL in this demonstrator. | |
| JSON capsule size is reported separately from this charged interpreter. | |
| Physical positions are a fixed nearest-neighbour embedding, not Brownian growth. | |
| """ | |
| import json | |
| import numpy as np | |
| def capsule(n, dim): | |
| return {'version': 2, 'extent': n, 'dimension': dim, | |
| 'motif': 'parity_conductance', 'ports': 2, | |
| 'eta': .08, 'seal_bound': .01, 'reserve_ratio': .9} | |
| def canonical(g): | |
| return json.dumps(g, sort_keys=True, separators=(',', ':')).encode() | |
| def parity(x): | |
| return int(x).bit_count() % 2 | |
| def role(g, inherited_coordinate, axis): | |
| # Thue-Morse parity produces a deterministic nonperiodic size family. | |
| v = sum((j+1)*int(x) for j, x in enumerate(inherited_coordinate)) | |
| return .7 + .2*parity(v) + .15*axis | |
| def compile_grid(g): | |
| n, dim = g['extent'], g['dimension'] | |
| shape = (n,)*dim | |
| xyz = np.array(list(np.ndindex(shape))) | |
| index = {tuple(x): i for i, x in enumerate(xyz)} | |
| parent = np.full(len(xyz), -1, int) | |
| children = [[] for _ in xyz] | |
| # Parent is the neighbour obtained by reducing the first nonzero coordinate. | |
| # Each node can discover exactly these children using its local counters. | |
| for i, x in enumerate(xyz): | |
| nz = np.flatnonzero(x) | |
| if len(nz): | |
| y=x.copy(); y[nz[0]]-=1 | |
| parent[i]=index[tuple(y)]; children[parent[i]].append(i) | |
| edges, target, owner = [], [], [] | |
| for i, x in enumerate(xyz): | |
| for ax in range(dim): | |
| if x[ax] > 0: | |
| y=x.copy(); y[ax]-=1 | |
| edges.append([index[tuple(y)], i]); owner.append(i) | |
| target.append(role(g, x, ax)) | |
| return {'coordinates': xyz, 'parent': parent, 'children': children, | |
| 'edges': np.array(edges), 'target': np.array(target), | |
| 'owner': np.array(owner), 'depth': xyz.sum(axis=1), | |
| 'left': np.flatnonzero(xyz[:,0]==0), | |
| 'right': np.flatnonzero(xyz[:,0]==n-1)} | |
| def access_from_root(parent, sealed): | |
| """Local acknowledgements on the known acyclic service tree. | |
| A node may receive service until it seals; sealing a parent removes service | |
| from descendants. The root inlet is kept open until final completion. | |
| """ | |
| access = np.zeros(len(parent), bool); access[0] = not sealed[0] | |
| for i in range(1,len(parent)): | |
| access[i] = access[parent[i]] and not sealed[i] | |
| return access | |
| def seal_ready(own_ready, sealed, children, preserve_descendants=True): | |
| result=sealed.copy() | |
| # One hop of ACK propagation per round, never an instantaneous global oracle. | |
| for i in range(1,len(sealed)): | |
| if own_ready[i] and not sealed[i]: | |
| if not preserve_descendants or all(sealed[j] for j in children[i]): | |
| result[i]=True | |
| if own_ready[0] and all(sealed[j] for j in children[0]): | |
| result[0]=True | |
| return result | |