UserWarnings differ for identical initializations when run several times

How do I use this algorithm? What does that parameter do?
Post Reply
Posts: 10
Joined: 23 Apr 2021, 07:51

UserWarnings differ for identical initializations when run several times

Post by xaver »

I have a frequent issue with UserWarnings regarding unused options in as such that they differ for identical(?) code, run several times. Typically this happens when initializing some tenpy algorithm. E.g.:

Code: Select all

import logging
logging.basicConfig(level=logging.INFO) # allow for some UserWarnings

# Next, prepare some MPS 'psi' and have some model 'h'. Now do

# --------------------------- snip ---------------------
dt = 0.01
dtmes = 0.05
EMEopt = {
    'compression_method': 'SVD',
    'dt': dt,
    'N_steps': int(np.ceil(dtmes/dt)),
    'preserve_norm': True,
    'trunc_params': {
        'chi_max': 50,
        'svd_min': 1.e-10,
        'trunc_cut': None        
# set e.g. an evolution engine
eng = ExpMPOEvolution(psi,h,EMEopt)
# --------------------------- snap ---------------------
When run for the 1st time (i.e. with a freshly restarted python kernel), the last info by tenpy is

Code: Select all subconfig 'trunc_params'=Config(<3 options>, 'trunc_params')
However, running the code between '-- snip --' and '-- snap --' repeatedly, and starting with the 2nd run the info by tenpy changes into

Code: Select all subconfig 'trunc_params'=Config(<3 options>, 'trunc_params')
/home/xaver/.anaconda3/envs/py/lib/python3.9/site-packages/tenpy/tools/ UserWarning: unused options for config ExpMPOEvolution:
['N_steps', 'compression_method', 'dt', 'preserve_norm']
/home/xaver/.anaconda3/envs/py/lib/python3.9/site-packages/tenpy/tools/ UserWarning: unused options for config trunc_params:
['chi_max', 'svd_min', 'trunc_cut']
Why does
  • ExpMPOEvolution not use its options?
  • ExpMPOEvolution only complain about this starting with the 2nd run?
User avatar
Site Admin
Posts: 357
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: UserWarnings differ for identical initializations when run several times

Post by Johannes »

That's expected behaviour given the implmentation of these warnings.

The engine does use the options, but only once you actually time evolve the state with

This stems from the convention that options only need to be read out by the time when they are actually used: depending on previously read out options, the exact details of the algorithm might change, and hence it might require a different set of options. As another example, consider the simulations in TeNPy: e.g., the "algorithm" paramter says which algorithm you actually want to call, and depending on that you might need a completely different set of "algorithm_params"; or when you select a different model, you need a different set of coupling constants.
Due to this dynamical simulation setup, we only know which options we actually need once we ran the simulation. This is why you only get the warning of unused parameters in the end, after TeNPy actually ran the algorithm.
If you don't use the simulation setup, the "end" is defined once the initialized class get's deleted - that's why it appears the *second* time you run run example snippet, because then the first engine instance gets out of scope and deleted. Really, it doesn't complain at the start of the second run, but at the end of the first run.
Post Reply