コード例 #1
0
ファイル: test_graph.py プロジェクト: chrisrothUT/netket
def test_graph_conversions():
    igraph = ig.Graph.Star(6)
    g = Graph.from_igraph(igraph)
    assert g.n_nodes == igraph.vcount()
    assert g.edges() == igraph.get_edgelist()
    assert all(c == 0 for c in g._edge_colors)

    nxg = nx.star_graph(5)
    g = Graph.from_networkx(nxg)
    assert g.n_nodes == igraph.vcount()
    assert g.edges() == igraph.get_edgelist()
    assert all(c == 0 for c in g._edge_colors)

    igraph = ig.Graph()
    igraph.add_vertices(3)
    igraph.add_edges(
        [(0, 1), (1, 2)],
        attributes={
            "color": ["red", "blue"],
        },
    )
    with pytest.raises(ValueError, match="not all colors are integers"):
        _ = Graph.from_igraph(igraph)

    igraph = ig.Graph()
    igraph.add_vertices(3)
    igraph.add_edges(
        [(0, 1), (1, 2)],
        attributes={
            "color": [0, 1],
        },
    )
    g = Graph.from_igraph(igraph)
    assert g.edges(color=0) == [(0, 1)]
    assert g.edges(color=1) == [(1, 2)]
コード例 #2
0
    Lattice,
    Edgeless,
    Triangular,
    Honeycomb,
    Kagome,
)
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(