sci-run / tasks /surface-code-decoding /surface-code-decoding-astra-xhigh-1h100-48h-20261020b /finalization /submission /conditional_edge_features.py
Download tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/conditional_edge_features.py from s42chen/sci-run: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/datasets/s42chen/sci-run/resolve/main/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/conditional_edge_features.py
- Command line
-
hf download hf://datasets/s42chen/sci-run/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/conditional_edge_features.py
-
curl -L -o conditional_edge_features.py https://huggingface.co/datasets/s42chen/sci-run/resolve/main/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/conditional_edge_features.py
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) | |