sci-run / tasks /surface-code-decoding /surface-code-decoding-astra-xhigh-1h100-48h-20261020b /finalization /submission /context_model.py
Download tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/context_model.py from s42chen/sci-run: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/s42chen/sci-run/resolve/main/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/context_model.py
- Command line
-
hf download hf://datasets/s42chen/sci-run/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/context_model.py
-
curl -L -o context_model.py https://huggingface.co/datasets/s42chen/sci-run/resolve/main/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/context_model.py
1.07 kB
| """A small contextual network reweights hyperedges before exact decoding.""" | |
| import numpy as np | |
| import jax | |
| import jax.numpy as jnp | |
| def initialize(seed,input_width,hidden=32): | |
| rng=np.random.default_rng(seed) | |
| return {'w1':jnp.asarray(rng.normal(0,1/np.sqrt(input_width),(input_width,hidden)),jnp.float32), | |
| 'b1':jnp.zeros(hidden),'w2':jnp.asarray(rng.normal(0,1/np.sqrt(hidden),(hidden,hidden)),jnp.float32), | |
| 'b2':jnp.zeros(hidden),'w3':jnp.asarray(rng.normal(0,.001,(hidden,1)),jnp.float32),'b3':jnp.zeros(1)} | |
| def probabilities(parameters,dets,context_indices,static,base_logits,valid): | |
| observed=dets[:,context_indices].astype(jnp.float32) | |
| features=jnp.concatenate([observed,jnp.broadcast_to(static[None,:,:],(len(dets),*static.shape))],axis=-1) | |
| hidden=jax.nn.silu(features@parameters['w1']+parameters['b1']) | |
| hidden=jax.nn.silu(hidden@parameters['w2']+parameters['b2']) | |
| delta=2*jnp.tanh((hidden@parameters['w3']+parameters['b3'])[...,0]) | |
| p=jax.nn.sigmoid(base_logits[None,:]+delta)*valid[None,:] | |
| return p.T | |