Views
No views yet
| Revision | Variational energy | Time per sweep | Description |
|---|---|---|---|
| main | -0.497505103 | 41s | Plain ViT with translation invariance among patches |
| symm_t | -0.49760546 | 166s | ViT with translational symmetry |
| symm_trxy_ising | -0.497676335 | 3317s | ViT with translational, point group and sz inversion symmetries |
1import jax
2import jax.numpy as jnp
3import netket as nk
4import flax
5from flax.training import checkpoints
6flax.config.update('flax_use_orbax_checkpointing', False)
7# Load the model from HuggingFace
8from transformers import FlaxAutoModel
9wf = FlaxAutoModel.from_pretrained("nqs-models/j1j2_square_10x10", trust_remote_code=True)
10N_params = nk.jax.tree_size(wf.params)
11print('Number of parameters = ', N_params, flush=True)
12lattice = nk.graph.Hypercube(length=10, n_dim=2, pbc=True, max_neighbor_order=2)
13hilbert = nk.hilbert.Spin(s=1/2, N=lattice.n_nodes, total_sz=0)
14hamiltonian = nk.operator.Heisenberg(hilbert=hilbert,
15 graph=lattice,
16 J=[1.0, 0.5],
17 sign_rule=[False, False]).to_jax_operator() # No Marshall sign rule
18sampler = nk.sampler.MetropolisExchange(hilbert=hilbert,
19 graph=lattice,
20 d_max=2,
21 n_chains=16384,
22 sweep_size=lattice.n_nodes)
23key = jax.random.PRNGKey(0)
24key, subkey = jax.random.split(key, 2)
25vstate = nk.vqs.MCState(sampler=sampler,
26 apply_fun=wf.__call__,
27 sampler_seed=subkey,
28 n_samples=16384,
29 n_discard_per_chain=0,
30 variables=wf.params,
31 chunk_size=16384)
32# Overwrite samples with already thermalized ones
33from huggingface_hub import hf_hub_download
34path = hf_hub_download(repo_id="nqs-models/j1j2_square_10x10", filename="spins")
35samples = checkpoints.restore_checkpoint(ckpt_dir=path, prefix="spins", target=None)
36samples = jnp.array(samples, dtype='int8')
37vstate.sampler_state = vstate.sampler_state.replace(σ = samples)
38# Sample the model
39for _ in range(10):
40 E = vstate.expect(hamiltonian)
41 print("Mean: ", E.mean.real / lattice.n_nodes / 4)
42 vstate.sample()Number of parameters = 434760
Mean: -0.4975034481394982
Mean: -0.4975697817150899
Mean: -0.49753878662981793
Mean: -0.49749150331671876
Mean: -0.4975093308123018
Mean: -0.49755810175173776
Mean: -0.49753726455462444
Mean: -0.49748956161946795
Mean: -0.497479875901942
Mean: -0.49752966071413424
wf = FlaxAutoModel.from_pretrained("nqs-models/j1j2_square_10x10", trust_remote_code=True, revision="symm_t")revision="symm_trxy_ising" for a wavefunction including also the point group and the sz inversion symmetries.1wf = FlaxAutoModel.from_pretrained("nqs-models/j1j2_square_10x10", trust_remote_code=True, return_z=True)
2
3z = wf(wf.params, samples)