Examples of observables/density operator for netket.experimental.TDVP #1754
Replies: 2 comments 1 reply
-
Hi!
No. Mainly because nobody found the time to contribute one.
There are two ways to do that. If your 'observable' was a NetKet observable, you could just pass it to the run method Instead, what you can do is use the much more flexible callback mechanism, which will execute (and potentially log the output) of an arbitrary function at every step of your algorithm: def compute_extra_stuff_callback(t, log_data, driver) -> bool:
# extract the current state
current_vstate = driver.state
# compute your observables
dists = minimum_distance(current_vstate.samples, current_vstate.hilbert.n_particles, sdim)
hist, bin_edges = np.histogram(dists.flatten(), bins=bins, range=(0,L/2))
....
density = ...
other_observable = ....
# put everything you want to log in the log data
log_data['density'] = density
log_data['other_observable'] = other_observable
# Always return true, if you return False you stop the driver.
return True Note that the callback can do pretty much anything. Then you pass it to the driver as follows te = TDVP(ha, variational_state=vstate, integrator=Euler(dt=0.1))
log = nk.logging.RuntimeLog()
te.run(T=T, out=log, callback = compute_extra_stuff_callback) Let me also add two points:
tstops = np.linspace(0.0, T, 20)
te.run(T=T, out=log, callback = compute_extra_stuff_callback, tstops= tstops) 2 - This is not very well documented, but If you want to use a time dependent Hamiltonian, you can do the following: ekin = nk.operator.KineticEnergy(hilb, mass=1.0)
pot = nk.operator.PotentialEnergy(hilb, lambda x: potential(x, N, epsilon, dim))
def timedep_hamiltonian(t):
return ekin + jnp.exp(-t)*pot
gs = TDVP(timedep_hamiltonian, variational_state=vstate, integrator=Euler(dt=0.1)) 3 - Your timestep of 4 - To simulate the dynamics, you must make sure that your ansatz can represent complex valued wave functions and their phase. In many ground-state tutorials we make use of real-valued wave functions because they are more well behaved, but those won't work for dynamics... 5 - Dynamics with continuous space systems is an hard problem and will take a lot of effort to get it right. I would suggest you first get familiar with how TDVP behaves and what regularisation it requires by playing with spin systems where you have an exact solution, and only then I would move on to continuous systems like yours here. I have some material here https://github.com/PhilipVinc/Lectures/blob/main/2301_Pisa/3-dynamics.ipynb (or https://github.com/PhilipVinc/Lectures/blob/main/2307_Trento/2_qgt_dynamics.ipynb if you want something more technical) |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your quick and detailed reply! It's a huge help. |
Beta Was this translation helpful? Give feedback.
-
Hey,$| \Psi(x, t) |^2$ . There is my code example, maybe it'd help:
I wonder if there is a tutorial for solving a time-dependent problem using netket.experimental.TDVP? Maybe there is something similar to this example with VMC https://netket.readthedocs.io/en/latest/tutorials/gs-continuous-space.html#neural-network-quantum-state ?
I think I managed to run tDVP for a setting from the mentioned tutorial, but it's not clear to me, for example, how to get the density of these particles? And what does the sampler sample after running tDVP? I expected it to be particles positions for different time, but I don't think there is any time evolution. I mostly wonder how to get the density
I'd really appreciate your help regarding my question! Thank you for this amazing library.
Beta Was this translation helpful? Give feedback.
All reactions