<jupyter_start><jupyter_text>Testssome consistency tests for magnets and MCMC samplers for magnets  Test the equivalence of MCMC SMC Sampler weights and manual MCMC-imposed SMC Sampler weights<jupyter_code>from melange_lite.magnets.ising_modell import IsingsModellSMCMCMCSampler, TrainableIsingsModellSMCSampler<jupyter_output><empty_output><jupyter_text>define some parameters for SMCSampler<jupyter_code>T=10
N=248
L=32
IW_parameters = jnp.hstack([jnp.ones(T)[..., jnp.newaxis], #J
                                                                         jnp.zeros(T)[..., jnp.newaxis], #h
                                                                         jnp.linspace(0,1,T)[..., jnp.newaxis] #beta
                                                                          ])<jupyter_output><empty_output><jupyter_text>build the smc factory<jupyter_code>smc_factory = TrainableIsingsModellSMCSampler(T=T, 
                                              N=N, 
                                              IW_parameters= IW_parameters,
                                              L=L, 
                                              full_scan=True,
                                              MCMC=False
                                              )<jupyter_output><empty_output><jupyter_text>make a parameter dictionary for propagation<jupyter_code>param_dict = {'seed': random.PRNGKey(2342), 'kernel_parameters': IW_parameters[1:]}<jupyter_output><empty_output><jupyter_text>generate the positions at time `t=0`<jupyter_code>X0s = smc_factory.M0(param_dict)<jupyter_output><empty_output><jupyter_text>then generate the positions at time `t=1`<jupyter_code>X1s = smc_factory.M(X0s, param_dict, 0)<jupyter_output><empty_output><jupyter_text>compute the weights at time `t=1`<jupyter_code>logG1s = smc_factory.logG(X0s, X1s, param_dict, 0)<jupyter_output><empty_output><jupyter_text>define the importance weight function (vmapped) so we can manually compute the log weights.<jupyter_code>vIW_energy_fn = vmap(smc_factory._IW_energy_fn, in_axes=(0,None))<jupyter_output><empty_output><jupyter_text>manually compute the log weights from the $\pi_t$-invariant $k_t$ forward kernel.<jupyter_code>MCMC_lws = -(vIW_energy_fn(X0s['x'], smc_factory.IW_parameters[1]) - vIW_energy_fn(X0s['x'], smc_factory.IW_parameters[0]))<jupyter_output><empty_output><jupyter_text>assert that these are all close, and then the test is complete.<jupyter_code>assert jnp.allclose(logG1s, MCMC_lws)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09463220675944334, 'fraction_numerical': 0.012723658051689861, 'mean_word_length': 2.7329376854599405, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '274442', 'license': 'MIT', 'n_tokens_mistral': 814, 'n_tokens_neox': 787, 'n_words': 131, 'path': 'notebooks/isings_sandbox.ipynb', 'repo_name': 'dominicrufa/melange_lite', 'size': '2515'}