s42chen's picture
Publish 11 evaluated Astra histories with reproducible checkpoint artifacts (part 51)
32d1b4a verified
Raw History Blame Contribute Delete
1.48 kB
"""Frozen reconstruction features at fault endpoints, with no logical inputs."""
import numpy as np
import jax
import jax.numpy as jnp
from conditional_edge_aux_encoder import features as masked_features,encode
def endpoint_plan(context,static,valid,measurement_indices):
context=np.asarray(context);static=np.asarray(static);valid=np.asarray(valid);mapping=np.asarray(measurement_indices);support=static[:,:120]>0;counts=support.sum(axis=1);assert counts.max()<=4
indices=np.full((len(context),4),624,np.int32);weights=np.zeros((len(context),4),np.float32)
for op in range(len(context)):
selected=context[op,support[op]]
if not valid[op] or not len(selected):continue
assert np.all(selected<600);tokens=mapping[selected];assert np.all(tokens<624) and len(np.unique(tokens))==len(tokens)
indices[op,:len(tokens)]=tokens;weights[op,:len(tokens)]=1/len(tokens)
return indices,weights
def token_embeddings(encoder,dets,grid,basis,rounds):
from conditional_edge_tokens import conditional_tokens,COLORS
# Explicit float32 precision avoids compile-context-dependent encoder approximations.
with jax.default_matmul_precision('highest'):
return conditional_tokens(encoder,dets,grid,basis,rounds,jnp.asarray(COLORS,jnp.int32))
def pool_endpoints(tokens,indices,weights):
flat=tokens.reshape(len(tokens),624,64);flat=jnp.pad(flat,((0,0),(0,1),(0,0)))
return (flat[:,indices,:]*weights[None,:,:,None]).sum(axis=2)