TimeDependentCorrelationEvolveBraKet
full name: tenpy.simulations.time_evolution.TimeDependentCorrelationEvolveBraKet
parent module:
tenpy.simulations.time_evolution
type: class
Inheritance Diagram
Methods
|
|
|
|
Accumulated eps error since the start of the time-evolution. |
|
Estimates the RAM usage for the simulation, without running it. |
|
Do nothing. |
|
Determine the output filenames. |
|
|
Re-initialize a given simulation class from checkpoint results. |
|
Extract the name used for backups of output_filename. |
|
Get psi for measurements. |
Read out the output_filename from the options. |
|
Get resume data for a Simulation for two engines. |
|
Try to save version info which is necessary to allow reproducibility. |
|
|
Coarse-grain the model and state for the algorithm. |
Split sites of psi that were grouped in |
|
|
Handle a SIGINT signal, usually caused by a CTRL-C press. |
Initialize the algorithm. |
|
Initialize the |
|
Initialize and prepare measurements. |
|
Initialize a |
|
Initialize a tensor network |
|
|
Equivalent to |
Perform measurements and merge the results into |
|
Total ov error of the time-evolution. |
|
Emits the |
|
|
Bring the results into a state suitable for saving. |
Resume a simulation that was initialized from a checkpoint. |
|
Resume running the algorithm. |
|
Run the whole simulation. |
|
Run the algorithm. |
|
Apply (several) post-processing steps. |
|
|
Save the intermediate results at the checkpoint of an algorithm. |
Save the |
|
Wall time evolved since initialization of the simulation class. |
Class Attributes and Properties
name of the default algorithm engine class |
|
tuples as for |
|
|
tuples as for |
class attribute. |
- class tenpy.simulations.time_evolution.TimeDependentCorrelationEvolveBraKet(*args, **kwargs)[source]
Bases:
TimeDependentCorrelation
Evolving the bra and ket state in
TimeDependentCorrelation
.This class allows the calculation of a time-dependent correlation function for arbitrary states \(|\psi>\) (not necessarily ground-states). The time-dependent correlation function is \(C(r, t) = <\psi| e^{i H t} A e^{-i H t} B |\psi>\) where A is an operator out of the list of
operator_t
and B is theoperator_t0
at the given site.Note
Any (custom) measurement function and default measurement are measuring with respect to the state where the
operator_t0
was already applied, that is w.r.t. \(B |\psi>\)Options
- config TimeDependentCorrelationEvolveBraKet
option summary algorithm_class (from Simulation) in Simulation.init_algorithm
Class or name of a subclass of :class:`~tenpy.algorithms.algorithm.Algorith [...]
algorithm_params (from Simulation) in Simulation.init_algorithm
Dictionary with parameters for the algorithm; see the documentation of the [...]
cache_params (from Simulation) in GroundStateSearch.init_cache
Dictionary with parameters for the cache, see [...]
cache_threshold_chi (from Simulation) in GroundStateSearch.init_cache
If the `algorithm_params.trunc_params.chi_max` in :attr:`options` is smalle [...]
canonicalize_before_measurement (from Simulation) in GroundStateSearch.init_measurements
If True, call `psi.canonical_form()` on the state used for measurement.
connect_algorithm_checkpoint (from Simulation) in Simulation.init_algorithm
Functions to connect to the :attr:`~tenpy.algorithms.Algorithm.checkpoint` [...]
connect_measurements (from Simulation) in GroundStateSearch.init_measurements
Functions to connect to the :attr:`measurement_event`. [...]
directory (from Simulation) in Simulation
If not None (default), switch to that directory at the beginning of the sim [...]
final_time (from TimeEvolution) in RealTimeEvolution
Mandatory. Perform time evolution until ``engine.evolved_time`` reaches thi [...]
ground_state_filename (from TimeDependentCorrelation) in TimeDependentCorrelation
a filename of a given ground state search (ideally a hdf5 file coming from [...]
group_sites (from Simulation) in GroundStateSearch.group_sites_for_algorithm
How many sites to group. 1 means no grouping.
group_to_NearestNeighborModel (from Simulation) in GroundStateSearch.group_sites_for_algorithm
If True, convert the grouped model to a [...]
initial_state_builder_class (from Simulation) in GroundStateSearch.init_state
Class or name of a subclass of :class:`~tenpy.networks.mps.InitialStateBuil [...]
initial_state_params (from Simulation) in GroundStateSearch.init_state
Dictionary with parameters for building `psi`; see the documentation of the [...]
log_params (from Simulation) in Simulation
Log parameters; see :cfg:config:`log`.
max_errors_before_abort (from Simulation) in Simulation
We safeguard measurements with a try-except block to avoid loosing results [...]
measure_at_algorithm_checkpoints (from Simulation) in GroundStateSearch.init_measurements
Defaults to False. If True, make measurements at each algorithm checkpoint. [...]
measure_initial (from Simulation) in GroundStateSearch.init_measurements
Whether to perform a measurement on the initial state, i.e., before startin [...]
model_class (from Simulation) in GroundStateSearch.init_model
Mandatory. Class or name of a subclass of :class:`~tenpy.models.model.Model`.
model_params (from Simulation) in GroundStateSearch.init_model
Dictionary with parameters for the model; see the documentation of the [...]
operator_t (from TimeDependentCorrelation) in SpectralSimulation.m_correlation_function
The (on-site) operator(s) as string(s) to apply at each measurement step. [...]
output_filename (from Simulation) in GroundStateSearch.get_output_filename
If ``None`` (default), no output is written to files. [...]
output_filename_params (from Simulation) in GroundStateSearch.get_output_filename
Instead of specifying the `output_filename` directly, this dictionary descr [...]
overwrite_output (from Simulation) in GroundStateSearch.fix_output_filenames
Only makes a difference if `skip_if_output_exists` is False and the file ex [...]
random_seed (from Simulation) in Simulation
If not ``None``, initialize the (legacy) numpy random generator with the gi [...]
safe_write (from Simulation) in GroundStateSearch.fix_output_filenames
If True (default), perform a "safe" overwrite of `output_filename` as descr [...]
save_every_x_seconds (from Simulation) in GroundStateSearch.save_at_checkpoint
By default (``None``), this feature is disabled. [...]
save_psi (from Simulation) in GroundStateSearch.init_state
Whether the final :attr:`psi` should be included into the output :attr:`res [...]
sequential (from Simulation) in Simulation
Parameters for running simulations sequentially, see :cfg:config:`sequentia [...]
skip_if_output_exists (from Simulation) in GroundStateSearch.fix_output_filenames
If True, raise :class:`Skip` if the output file already exists.
use_default_measurements (from Simulation) in GroundStateSearch.init_measurements
Each Simulation class defines a list of :attr:`default_measurements` in the [...]
- init_algorithm(**kwargs)[source]
Initialize the algorithm.
If
results
has ‘resume_data’, it is read out, used for initialization and removed from the results.- Parameters:
**kwargs – Extra keyword arguments passed on to the Algorithm.__init__(), for example the resume_data when calling resume_run.
Options
- option Simulation.algorithm_class: str | class
Class or name of a subclass of
Algorithm
. The engine of the algorithm to be run.
- option Simulation.algorithm_params: dict
Dictionary with parameters for the algorithm; see the documentation of the algorithm_class.
- option Simulation.connect_algorithm_checkpoint: list of tuple
Functions to connect to the
checkpoint
event of the algorithm. Each tuple can be of length 2 to 4, with entries(module, function, kwargs, priority)
, the last two optionally. The mandatory module and function specify a callback measurement function. kwargs can specify extra keyword-arguments for the function, priority allows to tune the order in which the measurement functions get called. Seeconnect_by_name()
for more details.
- run_algorithm()[source]
Run the algorithm.
Calls
self.engine.run()
andmake_measurements()
.
- m_correlation_function(results, psi, model, simulation, **kwargs)[source]
Equivalent to
TimeDependentCorrelation.m_correlation_function()
.
- estimate_RAM()[source]
Estimates the RAM usage for the simulation, without running it.
- Returns:
RAM – The expected RAM usage in kB.
- Return type:
- group_sites_for_algorithm()[source]
Coarse-grain the model and state for the algorithm.
Options
- option Simulation.group_sites: int
How many sites to group. 1 means no grouping.
- option Simulation.group_to_NearestNeighborModel: bool
If True, convert the grouped model to a
NearestNeighborModel
. Use this if you want to run TEBD with a model that was originally next-nearest neighbor.
- group_split()[source]
Split sites of psi that were grouped in
group_sites_for_algorithm()
.
- default_algorithm = 'TEBDEngine'
name of the default algorithm engine class
- default_measurements = [('tenpy.simulations.measurement', 'm_measurement_index', {}, 1), ('tenpy.simulations.measurement', 'm_bond_dimension'), ('tenpy.simulations.measurement', 'm_entropy'), ('tenpy.simulations.measurement', 'm_evolved_time'), ('simulation_method', 'wrap eps_error'), ('simulation_method', 'wrap ov_error'), ('simulation_method', 'm_correlation_function')]
tuples as for
Simulation.connect_measurements
that get added if theSimulation.use_default_measurements
is True.
- default_post_processing = []
tuples as for
Simulation.run_post_processing
, same structure as for measurements
- eps_error()[source]
Accumulated eps error since the start of the time-evolution.
To get the eps error induced at each loop of
'N_steps'
in the time evolution, a finite difference scheme could be used as the eps errors get simply added i.e.,np.diff(eps_error)
. Utility measurement method similar towalltime()
, but appended todefault_measurements
of this simulation class.Warning
This is only the sum of the discarded Schmidt values and does not take into account e.g., errors induced by time discretization. See
truncation
.- Returns:
eps – Accumulated eps error (sum of the discarded Schmidt values) since the start of the time-evolution.
- Return type:
- final_measurements()[source]
Do nothing.
We already performed a set of measurements after the evolution in
run_algorithm()
.
- fix_output_filenames()[source]
Determine the output filenames.
This function determines the
output_filename
and writes a one-line text into that file to indicate that we’re running a simulation generating it. Further,_backup_filename
is determined.Options
- option Simulation.skip_if_output_exists: bool
If True, raise
Skip
if the output file already exists.
- option Simulation.overwrite_output: bool
Only makes a difference if skip_if_output_exists is False and the file exists. In that case, with overwrite_output, just save everything under that name again, or with overwrite_output`=False, replace ``filename.ext` with
filename_01.ext
(and further increasing numbers) until we get a filename that doesn’t exist yet.
- option Simulation.safe_write: bool
If True (default), perform a “safe” overwrite of output_filename as described in
save_results()
.
- classmethod from_saved_checkpoint(filename=None, checkpoint_results=None, **kwargs)[source]
Re-initialize a given simulation class from checkpoint results.
You should probably call
resume_run()
after successful initialization.Instead of calling this directly, consider using
resume_from_checkpoint()
.- Parameters:
filename (None | str) – The filename of the checkpoint to be loaded. You can either specify the filename or the checkpoint_results.
checkpoint_results (None | dict) – Alternatively to filename the results of the simulation so far, i.e. directly the data dictionary saved at a simulation checkpoint.
**kwargs – Further keyword arguments given to the Simulation.__init__.
- get_backup_filename(output_filename)[source]
Extract the name used for backups of output_filename.
- Parameters:
output_filename (pathlib.Path) – The filename where data is saved.
- Returns:
backup_filename – The filename where to keep a backup while writing files to avoid.
- Return type:
- get_measurement_psi_model(psi, model)[source]
Get psi for measurements.
Sometimes, the psi we want to use for measurements is different from the one the algorithm actually acts on. Here, we split sites, if they were grouped in
group_sites_for_algorithm()
.- Parameters:
psi – Tensor network; initially just
self.psi
. The method should make a copy before modification.model – Model matching psi (in terms of indexing, MPS order, grouped sites, …) Initially just
self.model
.
- Returns:
psi – The psi suitable as argument for generic measurement functions.
model – Model matching psi (in terms of indexing, MPS order, grouped sites, …)
- get_output_filename()[source]
Read out the output_filename from the options.
You can easily overwrite this method in subclasses to customize the outputfilename depending on the options passed to the simulations.
Options
- option Simulation.output_filename: path_like | None
If
None
(default), no output is written to files. If a string, this filename is used for output (up to modifications byfix_output_filenames()
to avoid overwriting previous results).
- option Simulation.output_filename_params: dict
Instead of specifying the output_filename directly, this dictionary describes the parameters that should be included into it. Entries of the dictionary are keyword arguments to
output_filename_from_dict()
with the simulation parameters (Simulation
, or equivalentlyoptions
) as options.
- Returns:
output_filename – Filename for output; None disables any writing to files. Relative to
Simulation.directory
, if specified. The file ending determines the output format.- Return type:
str | None
- handle_abort_signal(signum, frame)[source]
Handle a SIGINT signal, usually caused by a CTRL-C press.
When the user presses Ctrl-C the first time, we just print a message to stderr that we received the signal and set the flag
received_signal_sigint
. This allows the simulation to “exit gracefully”: it will continue until the next algorithm checkpoint, wheresave_at_checkpoint()
checks for this flag, and if set, saves the results obtained so far and only then raises KeyboardInterrupt.When Ctrl-C is presssed a second time, we immediately raise a KeyboardInterrupt.
This feature is especially handy to gracefully interrupt long-running simulations. When running in an HPC cluster linux environment, you can usually still send the SIGINT signal, e.g. with SLURM you can call
scancel --signal=INT 1234
for the job ide 1234.
- init_cache()[source]
Initialize the
cache
from the options.This method is only called automatically when the simulation is used in a
with ...
statement. This is the case if you userun_simulation()
, etc.Options
- option Simulation.cache_threshold_chi: int
If the algorithm_params.trunc_params.chi_max in
options
is smaller than this threshold, do not initialize a (non-trivial) cache.
- option Simulation.cache_params: dict
Dictionary with parameters for the cache, see
open()
.
- init_measurements()[source]
Initialize and prepare measurements.
Options
- option Simulation.connect_measurements: list of tuple
Functions to connect to the
measurement_event
. Each tuple can be of length 2 to 4, with entries(module, function, kwargs, priority)
, the last two optionally. The mandatory module and function specify a callback measurement function. kwargs can specify extra keyword-arguments for the function, priority allows to tune the order in which the measurement functions get called. Seeconnect_by_name()
for more details.
- option Simulation.use_default_measurements: bool
Each Simulation class defines a list of
default_measurements
in the same format asSimulation.connect_measurements
. This flag allows to explicitly disable them.
- option Simulation.measure_initial: bool
Whether to perform a measurement on the initial state, i.e., before starting the algorithm run.
- option Simulation.measure_at_algorithm_checkpoints: bool
Defaults to False. If True, make measurements at each algorithm checkpoint. This can be useful to study e.g. the DMRG convergence with the number of sweeps. Note that (depending on the algorithm) psi might not be in canonical form during the algorithm run. In that case, you might need to also enable the canonicalize_before_measurement option to get correct e.g. correct long-range correlation functions. (On the other hand, local onsite expectation values are likely fine without the explicit canonical_form() call.)
- option Simulation.canonicalize_before_measurement: bool
If True, call psi.canonical_form() on the state used for measurement.
- init_model()[source]
Initialize a
model
from the model parameters.Skips initialization if
model
is already set.Options
- option Simulation.model_class: str | class
Mandatory. Class or name of a subclass of
Model
.
- option Simulation.model_params: dict
Dictionary with parameters for the model; see the documentation of the corresponding model_class.
- init_state()[source]
Initialize a tensor network
psi
.Skips initialization if
psi
is already set.Options
- option Simulation.initial_state_builder_class: str | class
Class or name of a subclass of
InitialStateBuilder
. Used to initialize psi according to the initial_state_params.
- option Simulation.initial_state_params: dict
Dictionary with parameters for building psi; see the documentation of the initial_state_builder_class, e.g.
InitialStateBuilder
.
- option Simulation.save_psi: bool
Whether the final
psi
should be included into the outputresults
.
- logger = <Logger tenpy.simulations.simulation.Simulation (WARNING)>
class attribute.
- Type:
logger
- Type:
An instance of a logger; see Logging and terminal output. NB
- make_measurements()[source]
Perform measurements and merge the results into
self.results['measurements']
.
- ov_error()[source]
Total ov error of the time-evolution.
Similar to
eps_error()
, but for the overlap (which gets multiplied at each step).- Returns:
ov – Total ov error since the start of the time-evolution.
- Return type:
- perform_measurements()[source]
Emits the
measurement_event
to call measurement functions and collect results.- Returns:
results – The results from calling the measurement functions.
- Return type:
- prepare_results_for_save()[source]
Bring the results into a state suitable for saving.
For example, this can be used to convert lists to numpy arrays, to add more meta-data, or to clean up unnecessarily large entries.
Options
- Cfg:configoptions ::
Simulation
- save_resume_databool
If True, include data returned by
get_resume_data()
into the output as resume_data.
- Returns:
results – A copy of
results
containing everything to be saved. Measurement results are converted into a numpy array (if possible).- Return type:
- resume_run()[source]
Resume a simulation that was initialized from a checkpoint.
- Returns:
results – The
results
as returned byprepare_results_for_save()
.- Return type:
- run()[source]
Run the whole simulation.
- Returns:
results – The
results
as returned byprepare_results_for_save()
.- Return type:
- run_post_processing()[source]
Apply (several) post-processing steps.
- post_processinglist of tuple
Functions to perform post-processing with the
DataLoader
. This uses a similar syntax to the attr:connect_measurements in meth:init_measurements. Each tuple can be of length 2 to 3, with entries(module, function, kwargs)
. The kwargs can contain aresults_key
under which the results (unless None is returned) are saved. All other kwargs are passed on to the function.Note
All post-processing functions should follow the syntax:
def pp_function(DL, *, kwarg1, kwarg_2=default_2):
whereDL
is an instance of theDataLoader
,kwarg_1
is a necessary keyword argument (no default value), whilekwarg_2
is an optional keyword argument (with default value)
- save_at_checkpoint(alg_engine)[source]
Save the intermediate results at the checkpoint of an algorithm.
- Parameters:
alg_engine (
Algorithm
) – The engine of the algorithm. Not used in this function, mostly there for compatibility with thecheckpoint
event.
Options
- option Simulation.save_every_x_seconds: float | None
By default (
None
), this feature is disabled. If given, save theresults
obtained so far at eachcheckpoint
when at least save_every_x_seconds seconds evolved since the last save (or since starting the algorithm). To avoid unnecessary, slow disk input/output, the value will be increased if saving takes longer than 10% of save_every_x_seconds. Use0.
to force saving at each checkpoint.
- save_results(results=None)[source]
Save the
results
to an output file.Performs a “safe” overwrite of
output_filename
by first moving the old file to_backup_filename
, then writing the new file, and finally removing the backup.- Parameters:
results (dict | None) – The results to be saved. If not specified, call
prepare_results_for_save()
to allow last-minute adjustments to the savedresults
.
- walltime()[source]
Wall time evolved since initialization of the simulation class.
Utility measurement method. To measure it, add the following entry to the
Simulation.connect_measurements
option:- - simulation_method - wrap walltime
- Returns:
seconds – Elapsed (wall clock) time in seconds since the initialization of the simulation.
- Return type: