Optimisation and Free up Memory #1471
|
I’m working with a 1-D system and I want to approximate its ground state with an RBM and capture the correct phase diagram. The Hamiltonian has 5 free parameters, but I want to scan a grid of two of these parameters inside a for loop, say alpha and beta. I think that if I reuse variational states the optimisation will be better, that is, the first state will take completely random parameters (of the RBM) until the first optimisation is finished, however, I want that from the second optimisation the previous optimised state is taken and that is how the new optimisation begins because I think by changing alpha and beta in small steps the energy minima are not very far from each other. First question is: How can I take previous optimised state to make next optimisation? I have noticed that my computer's RAM memory saturates when I run a "heavy" Netket script, for example, when I do a grid of parameters in a for loop, and when that happens the run is interrupted. Second question is: Is there any way to free up RAM memory on the fly? |
Replies: 1 comment
there are a few ways. You can either use a previously constructed variational state and pass it to a new vs = nk.vqs.MCState(..)
ham_1 = nk.operator.LocalOperator(...)
optim_1 = nk.VMC(ham_1, ..., variational_state=vs)
optim_1.run(...)
ham_2 = nk.operator.LocalOperator(...)
optim_2 = nk.VMC(ham_2, ..., variational_state=vs)
optim_2.run(...)you can also create a new variational state and pass it the parameters you obtained before vs1 = nk.vqs.MCState(...)
# optimize vs1...
vs2 = nk.vqs.MCState(..., parameters=vs1.parameters)
# or also
vs2 - nk.vqs.MCState(...)
vs2.parameters = vs1.parametersyou can also save and reload the variational states..
It's a difficult question. It really depends why your RAM is occupied. vs = nk.vqs.MCState(...)
# this takes up memory
vs = nk.vqs.MCState(...)
# Python should release the memory of the old object.if instead you call your objects with different names, eg vs1 = nk.vqs.MCState(...)
vs2 = nk.vqs.MCState(...)python will keep both around. the way to deallocate one would be to do del vs1
# and if you really really really want to oblige python do free memory
import gc
gc.collect()In general, however, if you don't keep tons of objects around I don' see what fills your memory up. To be sure, however, you can add a Netket computations that use a lot of samples might saturate your memory. In that case you can try to set |
there are a few ways. You can either use a previously constructed variational state and pass it to a new
VMCoptimiser, something likeyou can also create a new variational state and pass it the parameters you obtained before