예제 #1
0
def test_symmgroup():
    def assert_eq_hash(a, b):
        assert hash(a) == hash(b)
        assert a == b

    assert_eq_hash(group.Identity(), group.Identity())

    tr = Grid([8, 4, 3]).translation_group
    assert_eq_hash(tr(), tr(0) @ tr(1) @ tr(2))

    assert_eq_hash(tr().remove_duplicates(), tr())

    assert tr() @ tr() != tr()
    assert_eq_hash((tr() @ tr()).remove_duplicates(), tr())
예제 #2
0
def test_grid_translations():

    for ndim in 1, 2:
        g = Grid([4] * ndim, pbc=True)
        translations = g.translation_group()

        assert len(translations) == g.n_nodes

        _check_symmgroup(g.automorphisms(), translations)

        g = Grid([4] * ndim, pbc=False)
        translations = g.translation_group()
        assert translations.elems == [group.Identity()]  # only identity

    g = Grid([8, 4, 3], pbc=[True, False, False])
    assert len(g.translation_group()) == 8

    g = Grid([8, 4, 3], pbc=[True, True, False])
    assert len(g.translation_group()) == 8 * 4
    assert g.translation_group(2).elems == [group.Identity()]  # only identity

    g = Grid([8, 4, 3], pbc=[True, True, True])
    assert len(g.translation_group()) == 8 * 4 * 3
    assert len(g.translation_group(dim=0)) == 8
    assert len(g.translation_group(dim=1)) == 4
    assert len(g.translation_group(dim=2)) == 3

    t1 = g.translation_group()
    t2 = (
        g.translation_group(dim=0)
        @ g.translation_group(dim=1)
        @ g.translation_group(dim=2)
    )
    assert t1 == t2
    t2 = (
        g.translation_group(dim=2)
        @ g.translation_group(dim=1)
        @ g.translation_group(dim=0)
    )
    assert t1 != t2

    assert g.translation_group(dim=(0, 1)) == g.translation_group(
        0
    ) @ g.translation_group(1)
예제 #3
0
def test_no_redundant_edges(size, n_nodes, n_edges):
    g = Grid(size)
    print(g.edges())
    assert g.n_nodes == n_nodes
    assert g.n_edges == n_edges
예제 #4
0
from netket.graph import _lattice
from netket.utils import group

from .. import common

pytestmark = common.skipif_mpi

graphs = [
    # star and tree
    Graph.from_igraph(ig.Graph.Star(5)),
    Graph.from_igraph(ig.Graph.Tree(n=3, children=2)),
    # Grid graphs
    Hypercube(length=10, n_dim=1, pbc=True),
    Hypercube(length=4, n_dim=2, pbc=True),
    Hypercube(length=5, n_dim=1, pbc=False),
    Grid([2, 2], pbc=False),
    Grid([4, 2], pbc=[True, False]),
    # lattice graphs
    Lattice(
        basis_vectors=[[1.0, 0.0], [1.0 / 2.0, math.sqrt(3) / 2.0]],
        extent=[3, 3],
        pbc=[False, False],
        site_offsets=[[0, 0]],
    ),
    Lattice(
        basis_vectors=[[1.5, math.sqrt(3) / 2.0], [0, math.sqrt(3)]],
        extent=[3, 5],
        site_offsets=[[0, 0], [1, 1]],
    ),
    Lattice(
        basis_vectors=[
예제 #5
0
def test_no_redundant_edges():
    g = Grid([3, 2])
    print(g.edges())
    assert g.n_nodes == 6
    assert g.n_edges == 9
예제 #6
0
파일: test_graph.py 프로젝트: yannra/netket
def test_grid_color_pbc():
    # compute length from iterator
    count = lambda it: sum(1 for _ in it)

    g = Grid([4, 4], pbc=True, color_edges=True)
    assert count(g.edges(filter_color=0)) == 16
    assert count(g.edges(filter_color=1)) == 16
    assert g.n_edges == 32

    g = Grid([4, 2], pbc=True, color_edges=True)
    assert count(g.edges(filter_color=0)) == 8
    assert count(g.edges(filter_color=1)) == 8

    g = Grid([4, 2], pbc=[True, False], color_edges=True)
    assert count(g.edges(filter_color=0)) == 8
    assert count(g.edges(filter_color=1)) == 4

    g = Grid([4, 2], pbc=False, color_edges=True)
    assert count(g.edges(filter_color=0)) == 6
    assert count(g.edges(filter_color=1)) == 4

    # with pytest.raises(ValueError, match="Directions with length <= 2 cannot have PBC"):
    #    g = Grid([2, 4], pbc=[True, True])

    g1 = Grid([7, 5], pbc=False)
    g2 = Grid([7, 5], pbc=[False, False])
    assert sorted(g1.edges()) == sorted(g2.edges())

    g1 = Grid([7, 5], pbc=True)
    g2 = Grid([7, 5], pbc=[True, True])
    assert sorted(g1.edges()) == sorted(g2.edges())