def test_draw_pegasus_biases(self):
        G = dnx.pegasus_graph(2)
        h = {v: v % 12 for v in G}
        J = {(u, v) if u % 2 else (v, u): (u + v) % 24 for u, v in G.edges()}
        for v in G:
            J[v, v] = .1

        dnx.draw_pegasus(G, linear_biases=h, quadratic_biases=J)
Esempio n. 2
0
def draw_architecture(target_graph, **kwargs):
    """ Draws graph G according to G's family layout.
    """
    family = target_graph.graph['family']

    if family == 'chimera':
        dnx.draw_chimera(target_graph, **kwargs)

    elif family == 'pegasus':
        dnx.draw_pegasus(target_graph, **kwargs)

    else:
        nx.draw_spring(target_graph)
        warnings.warn(
            "Graph family not available. Using NetworkX spring layout")
Esempio n. 3
0
def yield_double_plot(P, filename):
    fig = plt.figure(figsize=(40, 20))
    axes = fig.subplots(nrows=1, ncols=2)

    dnx.draw_pegasus_yield(P, node_size=80, ax=axes[0])

    dnx.draw_pegasus(P,
                     crosses=True,
                     node_size=80,
                     node_color="#f37820",
                     edge_color="#17bebb",
                     ax=axes[1])

    fig.tight_layout()
    plt.savefig(filename)
    plt.close()
Esempio n. 4
0
    double_plot(K, P16, clique_embedding, 'clique_doubleplot.png',
                [{
                    'node_size': 100,
                    'pos': nx.circular_layout(K),
                    'width': 1,
                    'edge_color': (0, 0, 0, .1)
                }, {
                    'node_size': 10
                }])

    from embed_draw_sparse import C, layout_C, emb as sparse_embedding

    double_plot(C, P6, sparse_embedding, 'sparse_doubleplot.png',
                [{
                    'node_size': 70,
                    'pos': layout_C
                }, {
                    'node_size': 30
                }])

    fig = plt.figure(figsize=(20, 20))
    dnx.draw_pegasus(dnx.pegasus_graph(3),
                     node_color="#f37820",
                     edge_color="#17bebb",
                     crosses=True)
    plt.savefig("P3.png")
    plt.close()

    yield_double_plot(P6, "yield_doubleplot.png")
Esempio n. 5
0
# Copyright 2020 D-Wave Systems Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pegasus_graph import P6
import dwave_networkx as dnx

import matplotlib
try:
    import matplotlib.pyplot as plt
except ImportError:
    matplotlib.use("agg")
    import matplotlib.pyplot as plt

dnx.draw_pegasus_yield(P6, node_size=80)

dnx.draw_pegasus(P6, node_size=80)
classical_sampler = neal.SimulatedAnnealingSampler()
sampler = dimod.StructureComposite(classical_sampler, P6.nodes, P6.edges)

# %%
# Working With Embeddings
# 全結合の40ノードを作りたい
num_variables = 40
embedding = dwave.embedding.chimera.find_clique_embedding(num_variables, 16)
max(len(chain) for chain in embedding.values())
# チェーン数は11

# %%
# 680 node Pegasus
num_variables = 40
embedding = dwave.embedding.pegasus.find_clique_embedding(num_variables, 6)
max(len(chain) for chain in embedding.values())
# チェーン数は6

# %%
# https://qiita.com/YuichiroMinato/items/dbc142ecb1efbebd6adf
chimera = dnx.chimera_graph(2, 2, 4)
dnx.draw_chimera(chimera)
plt.show()

# %%
P3 = dnx.pegasus_graph(2)
dnx.draw_pegasus(P3)
plt.show()

# %%