示例#1
0
    def __init__(self, model_params):
        model_params = asConfig(model_params, "AKLTModel")
        L = model_params.get('L', 2)
        site = SpinSite(S=1., conserve='Sz')

        # lattice
        bc_MPS = model_params.get('bc_MPS', 'finite')
        bc = 'open' if bc_MPS == 'finite' else 'periodic'
        lat = Chain(L, site, bc=bc, bc_MPS=bc_MPS)

        Sp, Sm, Sz = site.Sp, site.Sm, site.Sz
        S_dot_S = 0.5 * (kron(Sp, Sm) + kron(Sm, Sp)) + kron(Sz, Sz)
        S_dot_S_square = npc.tensordot(S_dot_S, S_dot_S, [['(p0*.p1*)'], ['(p0.p1)']])

        H_bond = S_dot_S + S_dot_S_square / 3.
        # P_2 = H_bond * 0.5 + 1/3 * npc.eye_like(S_dot_S)

        J = model_params.get('J', 1.)
        H_bond = J * H_bond.split_legs().transpose(['p0', 'p1', 'p0*', 'p1*'])
        H_bond = [H_bond] * L
        # H_bond[i] acts on sites (i-1, i)
        if bc_MPS == "finite":
            H_bond[0] = None
        # 7) initialize H_bond (the order of 7/8 doesn't matter)
        NearestNeighborModel.__init__(self, lat, H_bond)
        # 9) initialize H_MPO
        MPOModel.__init__(self, lat, self.calc_H_MPO_from_bond())
示例#2
0
def test_parameters():
    pars = Config(dict(), "Test empty")
    example_function(pars)
    pars = dict(
        a=None,
        b=2.5,
        d="dict-style access",
        e="non-used",
        sub=dict(x=10, y=20),
        verbose=1,
    )
    pars_copy = copy.deepcopy(pars)
    config = asConfig(pars, "Test parameters")
    example_function(config)
    assert config['d'] == "dict-style access"  # reads out d
    pars_copy['c'] = 2
    assert config.as_dict() == pars_copy
    sub = config.subconfig("sub")
    sub.setdefault('z', 30)
    pars_copy['sub']['z'] = 30
    pars_copy['sub']['verbose'] = pars['verbose'] / 10.
    assert config.as_dict() == pars_copy
    example_function(sub)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        assert len(config.unused) == 1
        del config  # catch the warning for 'e'
        del pars
        assert len(w) == 1
        sub.deprecated_alias('y', 'y_new')
        assert len(w) == 2

        assert len(sub.unused) == 2
        del sub  # catch warnings for 'x', y'
        assert len(w) == 3
示例#3
0
def test_parameters():
    pars = Config(dict(), "Test empty")
    example_function(pars)
    pars = dict(
        a=None,
        b=2.5,
        d="dict-style access",
        e="non-used",
        sub=dict(x=10, y=20),
    )
    pars_copy = copy.deepcopy(pars)
    config = asConfig(pars, "Test parameters")
    example_function(config)
    assert config['d'] == "dict-style access"  # reads out d
    pars_copy['c'] = 2
    assert config.as_dict() == pars_copy
    sub = config.subconfig("sub")
    sub.setdefault('z', 30)
    pars_copy['sub']['z'] = 30
    assert config.as_dict() == pars_copy
    example_function(sub)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        assert len(config.unused) == 1
        del config  # catch the warning for 'e'
        del pars
        # assert len(w) == 1
        sub.deprecated_alias('y', 'y_new')
        # assert len(w) == 2
        assert len(sub.unused) == 2
        sub.__del__()
        assert len(w) == 3
        sub.touch(
            'x', 'y_new'
        )  # avoid warnings when deconstructed outside of the catch_warning
示例#4
0
文件: tdvp.py 项目: ZehanLi/tenpy
 def __init__(self, psi, model, options, environment=None):
     if model.H_MPO.explicit_plus_hc:
         raise NotImplementedError("TDVP does not respect 'MPO.explicit_plus_hc' flag")
     self.options = options = asConfig(options, "TDVP")
     self.verbose = options.get('verbose', 1)
     self.lanczos_options = options.subconfig('lanczos_options')
     if environment is None:
         environment = MPOEnvironment(psi, model.H_MPO, psi)
     self.evolved_time = options.get('start_time', 0.)
     self.H_MPO = model.H_MPO
     self.environment = environment
     if not psi.finite:
         raise ValueError("TDVP is only implemented for finite boundary conditions")
     self.psi = psi
     self.L = self.psi.L
     self.dt = options.get('dt', 2)
     self.trunc_params = options.get('trunc_params', {})
     self.N_steps = options.get('N_steps', 10)
示例#5
0
def test_parameters():
    pars = Config(dict(), "Test empty")
    example_function(pars)
    pars = dict(a=None, b=2.5, d="dict-style", e="non-used", sub=dict(x=10, y=20), verbose=1)
    config = asConfig(pars, "Test parameters")
    example_function(config)
    assert config['d'] == "dict-style"
    sub = config.subconfig("sub")
    sub.setdefault('z', 30)
    example_function(sub)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        assert len(config.unused) == 1
        del config  # catch the warning for 'e'
        assert len(w) == 1
        sub.deprecated_alias('y', 'y_new')
        assert len(w) == 2

        assert len(sub.unused) == 2
        del sub  # catch warnings for 'x', y'
        assert len(w) == 3
示例#6
0
    def __init__(self, model_params):
        # model parameters
        model_params = asConfig(model_params,
                                "ExponentiallyDecayingHeisenberg")
        L = model_params.get('L', 2)
        xi = model_params.get('xi', 0.5)
        Jxx = model_params.get('Jxx', 1.)
        Jz = model_params.get('Jz', 1.5)
        hz = model_params.get('hz', 0.)
        conserve = model_params.get('conserve', 'Sz')
        if xi == 0.:
            g = 0.
        elif xi == np.inf:
            g = 1.
        else:
            g = np.exp(-1 / (xi))

        # Define the sites and the lattice, which in this case is a simple uniform chain
        # of spin 1/2 sites
        site = SpinHalfSite(conserve=conserve)
        lat = Chain(L, site, bc_MPS='infinite', bc='periodic')

        # The operators that appear in the Hamiltonian. Standard spin operators are
        # already defined for the spin 1/2 site, but it is also possible to add new
        # operators using the add_op method
        Sz, Sp, Sm, Id = site.Sz, site.Sp, site.Sm, site.Id

        # yapf:disable
        # The grid (list of lists) that defines the MPO. It is possible to define the
        # operators in the grid in the following ways:
        # 1) NPC arrays, defined above:
        grid = [[Id,   Sp,   Sm,   Sz,   -hz*Sz    ],
                [None, g*Id, None, None, 0.5*Jxx*Sm],
                [None, None, g*Id, None, 0.5*Jxx*Sp],
                [None, None, None, g*Id, Jz*Sz     ],
                [None, None, None, None, Id        ]]
        # 2) In the form [("OpName", strength)], where "OpName" is the name of the
        # operator (e.g. "Sm" for Sm) and "strength" is a number that multiplies it.
        grid = [[[("Id", 1)], [("Sp",1)], [("Sm",1)], [("Sz",1)], [("Sz", -hz)]    ],
                [None       , [("Id",g)], None      , None      , [("Sm", 0.5*Jxx)]],
                [None       , None      , [("Id",g)], None      , [("Sp", 0.5*Jxx)]],
                [None       , None      , None      , [("Id",g)], [("Sz",Jz)]      ],
                [None       , None      , None      , None      , [("Id",1)]       ]]
        # 3) It is also possible to write a single "OpName", equivalent to
        # [("OpName", 1)].
        grid = [["Id"       , "Sp"      , "Sm"      , "Sz"      , [("Sz", -hz)]    ],
                [None       , [("Id",g)], None      , None      , [("Sm", 0.5*Jxx)]],
                [None       , None      , [("Id",g)], None      , [("Sp", 0.5*Jxx)]],
                [None       , None      , None      , [("Id",g)], [("Sz",Jz)]      ],
                [None       , None      , None      , None      , "Id"             ]]
        # yapf:enable
        grids = [grid] * L

        # Generate the MPO from the grid. Note that it is not necessary to specify
        # the physical legs and their charges, since the from_grids method can extract
        # this information from the position of the operators inside the grid.
        H = MPO.from_grids(lat.mps_sites(),
                           grids,
                           bc='infinite',
                           IdL=0,
                           IdR=-1)
        MPOModel.__init__(self, lat, H)
示例#7
0
 def __init__(self, model_params):
     model_params = asConfig(model_params, self.__class__.__name__)
     model_params.setdefault('lattice', "Chain")
     CouplingMPOModel.__init__(self, model_params)