Lattice geometry#
The test_SquareLattice()
function generates a few lattices and verifies the expected output of some functions. It checks the dimensions, sites, bonds, and nearest neighbor sites
of the lattice. The function is tested on both checkerboard and square lattices with infinite size and open boundary conditions.
def test_SquareLattice():
net = fpeps.SquareLattice(dims=(3, 2), boundary='obc')
assert net.dims == (3, 2)
assert net.sites() == ((0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1))
assert net.bonds(dirn='h') == (Bond((0, 0), (0, 1)),
Bond((1, 0), (1, 1)),
Bond((2, 0), (2, 1)))
assert net.bonds(dirn='v') == (Bond((0, 0), (1, 0)),
Bond((1, 0), (2, 0)),
Bond((0, 1), (1, 1)),
Bond((1, 1), (2, 1)))
assert net.nn_site((0, 1), d='r') is None
assert net.nn_site((0, 1), d='t') is None
assert net.nn_site((2, 0), d='l') is None
assert net.nn_site((2, 0), d='b') is None
assert net.nn_site(None, d='l') is None
assert net.nn_site((0, 1), d=(2, -1)) == Site(2, 0)
assert net.site2index((1, 0)) == (1, 0)
assert net.site2index(None) == None
assert net.nn_bond_type(Bond((0, 0), (0, 1))) == ('h', True) # 'lr'
assert net.nn_bond_type(Bond((0, 1), (0, 0))) == ('h', False) # 'rl'
assert net.nn_bond_type(Bond((2, 1), (1, 1))) == ('v', False) # 'bt'
assert net.nn_bond_type(Bond((1, 0), (2, 0))) == ('v', True) # 'tb'
with pytest.raises(yastn.YastnError):
net.nn_bond_type(Bond((0, 0), (2, 0)))
# Bond((0,0),(2,0)) is not a nearest-neighboor bond.
assert all(net.nn_bond_type(bond) == ('h', True) for bond in net.bonds(dirn='h'))
assert all(net.nn_bond_type(bond) == ('v', True) for bond in net.bonds(dirn='v'))
assert net.f_ordered(Bond((0, 0), (1, 0)))
assert net.f_ordered(Bond((0, 0), (0, 1)))
assert net.f_ordered(Bond((1, 0), (0, 1)))
assert all(net.f_ordered((s0, s1)) for s0, s1 in zip(net.sites(), net.sites()[1:]))
assert all(net.f_ordered(bond) for bond in net.bonds())
##########
net = fpeps.SquareLattice(dims=(3, 2), boundary='cylinder')
assert net.dims == (3, 2)
assert net.sites() == ((0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1))
assert net.bonds('h') == (Bond((0, 0), (0, 1)),
Bond((1, 0), (1, 1)),
Bond((2, 0), (2, 1)))
assert net.bonds('v') == (Bond((0, 0), (1, 0)),
Bond((1, 0), (2, 0)),
Bond((2, 0), (0, 0)),
Bond((0, 1), (1, 1)),
Bond((1, 1), (2, 1)),
Bond((2, 1), (0, 1)))
assert net.nn_site((0, 1), d='r') is None
assert net.nn_site((0, 1), d='t') == Site(2, 1)
assert net.nn_site((2, 0), d='l') is None
assert net.nn_site((2, 0), d='b') == Site(0, 0)
assert net.nn_site((0, 0), d=(4, 4)) is None
assert net.nn_site((2, 0), d=(2, 1)) == Site(1, 1)
assert net.nn_site((2, 0), d=(-3, 1)) == Site(2, 1)
assert net.nn_bond_type(Bond((0, 0), (0, 1))) == ('h', True) # 'lr'
assert net.nn_bond_type(Bond((0, 1), (0, 0))) == ('h', False) # 'rl'
assert net.nn_bond_type(Bond((2, 0), (0, 0))) == ('v', True) # 'tb'
assert net.nn_bond_type(Bond((0, 1), (2, 1))) == ('v', False) # 'bt'
with pytest.raises(yastn.YastnError):
net.nn_bond_type(Bond((3, 0), (2, 0)))
# Bond((3,0),(2,0)) is not a nearest-neighboor bond.
assert all(net.nn_bond_type(bond) == ('h', True) for bond in net.bonds(dirn='h'))
assert all(net.nn_bond_type(bond) == ('v', True) for bond in net.bonds(dirn='v'))
assert net.nn_bond_type(Bond((2, 0), (0, 0))) == ('v', True)
assert net.nn_bond_type(Bond((0, 0), (2, 0))) == ('v', False)
assert not net.f_ordered(Bond((2, 0), (0, 0)))
assert net.f_ordered(Bond((0, 0), (2, 0)))
assert all(net.f_ordered((s0, s1)) for s0, s1 in zip(net.sites(), net.sites()[1:]))
assert not all(net.f_ordered(bond) for bond in net.bonds()) # PBC bonds in cylinder are not fermionically alligned
##########
net = fpeps.SquareLattice(dims=(3, 2), boundary='infinite')
assert net.dims == (3, 2)
assert net.sites() == ((0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1))
assert net.bonds(dirn='h') == (Bond((0, 0), (0, 1)),
Bond((1, 0), (1, 1)),
Bond((2, 0), (2, 1)),
Bond((0, 1), (0, 2)),
Bond((1, 1), (1, 2)),
Bond((2, 1), (2, 2)))
assert net.bonds(dirn='v') == (Bond((0, 0), (1, 0)),
Bond((1, 0), (2, 0)),
Bond((2, 0), (3, 0)),
Bond((0, 1), (1, 1)),
Bond((1, 1), (2, 1)),
Bond((2, 1), (3, 1)))
assert net.nn_site((0, 1), d='r') == (0, 2)
assert net.nn_site((0, 1), d='t') == (-1, 1)
assert net.nn_site((2, 0), d='l') == (2, -1)
assert net.nn_site((2, 0), d='b') == (3, 0)
assert net.nn_site((0, 1), d=(3, 4)) == Site(3, 5)
assert net.site2index((1, 0)) == (1, 0)
assert net.site2index(None) == None
assert all(net.nn_bond_type(bond) == ('h', True) for bond in net.bonds(dirn='h'))
assert all(net.nn_bond_type(bond) == ('v', True) for bond in net.bonds(dirn='v'))
assert all(net.f_ordered((s0, s1)) for s0, s1 in zip(net.sites(), net.sites()[1:]))
assert all(net.f_ordered(bond) for bond in net.bonds())
##########
with pytest.raises(yastn.YastnError):
fpeps.SquareLattice(dims=(3, 2), boundary='some')