Menu

Users.Saving.Main

Anonymous Burkhard Schmidt

About saving and loading of wavefunctions or trajectory bundles in the Matlab/Octave version of WavePacket

Saving wavefunctions or trajectories

To save the result of a calculation (in a MATLAB/Octave formatted binary file), you have to set a couple of properties of object "state", normally within the ''qm_init.m'' function. A typical setting is shown here

state.save_export = true;
state.save_dir    = '/scratch/wavepacket_saves';
state.save_file   = 'MyFirstSave';

where state can be an object of class wave (wavefunction) or class traj (trajectory swarm) or any of the other WavePacket main classes.

  1. The first parameter tells WavePacket to actually save the calculation. If this parameter is not specified, no saves will be made (default: false).
  2. The second parameter gives the name of the directory where the calculation should be saved to. If this parameter is not specified, all data will be saved in the directory where you are running your simulation (default: Matlab's or Octave's "pwd").
  3. The third parameter is the template for the file names. If this parameter is not specified, a standard name is chosen (default: wave or traj or etc, according to the class of object "state"). Note that the file name extension is always .mat, as is usual for a MATLAB/Octave formatted binary file.

With this setup, WavePacket will save the calculated wavefunctions or trajectory bundles or etc at each main time step. After the calculation, the directory ''/scratch/wavepacket_saves'' will contain two or more files. The file ''wave_0.mat'' contains all global variables saved in the standard Matlab/Octave formatted binary file format. The other files called ''wave_1.mat'', ''wave_2.mat'', ... 'or 'traj_1.mat'', ''traj_2.mat'', ... store the actual wavefunctions or trajectory bundles. Note that data to be saved are first cached in memory until a certain limit is reached (by default 500 MB to avoid blowing up a typical user's memory), after which this cache is written to a file, after which the process is repeated.

Additional parameters

As mentioned above, wavefunctions or trajectory bundles or etc that are to be saved are first cached in memory before being written to a file. This consumes some amount of memory, which you also have to plan for later when you load the wave function again. Note that this strategy avoids producing too many data files, which would be a bit annoying. To fine-tune the behavior, you can set two variables

state.save_mem
state.save_step

The first variable (default: 500×220B → 500 MB) gives the (approximate) maximum amount of memory (in units of bytes) that should be used for caching. The second parameter gives a number of time-steps after which the cache is written to a file. You can set both parameters, in which case the tighter limit applies. However, at least one wavefunction is always cached.

Loading wave functions or trajectories

Loading proceeds in two steps. First, you retrieve all the global variables of the saved calculation, then you can load the wave functions or trajectory bundles at various time steps.

The first step is using the function ''load_0'' to retrieve the setup that was used in the saved calculation. The syntax is

load_0 ( state, choice );

where the directory and the file template for the saved calculation are taken from the respective properties of object "state" given as the first argument, see above. If a second (integer) parameter "choice" is supplied and set to 1 or 2, this function will also overwrite the following global variables with those from the saved calculation: expect, hamilt, info, space, time. (Global variable "plots" is not set because that would interfere with the functionality of qm_movie).

After you have loaded the general setup, you can then go on to retrieve the saved (wave function or trajectory bundle) objects. The syntax is

load (state, step)

Required parameters are the object "state", into which the desired data will be loaded, and an integer that gives the time step at which you want to retrieve the wave function or trajectory bundle or etc. Counting starts at 1 for the initial state at the starting time. You will find the loaded data in the following places

  • If state is an object of class wave, the property state.dvr will hold the wave function in position space (DVR), as the usual cell vector for the different (coupled) channels. These wave functions are always in the diabatic representation.
  • If state is an object of class traj, the properties state.pos and state.mom will hold the positions and momenta, respectively, as the usual cell vectors for the spatial components. The assignment to the different (coupled) channels (used for surface hopping etc) can be found in state.cha.

Related

Wiki: FAQ.Main
Wiki: Reference.Classes.Main
Wiki: Reference.Classes.traj
Wiki: Reference.Classes.wave
Wiki: Reference.Files.Main
Wiki: Reference.Programs.qm_bound
Wiki: Reference.Programs.qm_matrix
Wiki: Reference.Programs.qm_movie
Wiki: Reference.Programs.qm_propa
Wiki: Users.Basics.Main
Wiki: Users.Main

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.