"""Parallel chains: samplers are vectorized over the batch dimension.The 10,000 Langevin chains below advance as one tensor program, and on a GPUthe same call runs millions of chains. Population statistics come from manyparallel chains at once; contrastive divergence draws its negatives the sameway. The target is a double well whose first coordinate has two symmetricmodes, at -b and +b."""importosimporttorchfromtorchebm.coreimportDoubleWellModelfromtorchebm.samplersimportLangevinDynamicsSMOKE=os.getenv("TORCHEBM_SMOKE")=="1"N_STEPS=20ifSMOKEelse500N_CHAINS=10_000model=DoubleWellModel(barrier_height=2.0)sampler=LangevinDynamics(step_size=0.01,noise_scale=1.0)samples=sampler(model,torch.randn(N_CHAINS,2),n_steps=N_STEPS)left=(samples[:,0]<0).float().mean()print("samples:",tuple(samples.shape))print(f"basin occupancy: left {left:.1%} / right {1-left:.1%} (symmetric target: 50/50)")print(f"mean energy: {model(samples).mean():.2f}")