Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit 0c73647

Browse files
committed
Fix matplotlib import; spacing
1 parent b2a40ea commit 0c73647

File tree

7 files changed

+58
-28
lines changed

7 files changed

+58
-28
lines changed

Exploring_Pegasus/biclique_embedding.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
from minorminer import find_embedding
2020
from dwave.system.samplers import DWaveSampler
2121

22-
import matplotlib
23-
matplotlib.use("agg")
24-
import matplotlib.pyplot as plt
22+
try:
23+
import matplotlib.pyplot as plt
24+
except ImportError:
25+
matplotlib.use("agg")
26+
import matplotlib.pyplot as plt
2527

2628
# Form the biclique
2729
N = int(sys.argv[1])

Exploring_Pegasus/clique_embedding.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
from minorminer.busclique import find_clique_embedding
1919
from dwave.system.samplers import DWaveSampler
2020

21-
import matplotlib
22-
matplotlib.use("agg")
23-
import matplotlib.pyplot as plt
21+
try:
22+
import matplotlib.pyplot as plt
23+
except ImportError:
24+
matplotlib.use("agg")
25+
import matplotlib.pyplot as plt
2426

2527
N = int(sys.argv[1])
2628
G = nx.complete_graph(N)

Pegasus_Embedding_Video/double_plot.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import matplotlib
16-
matplotlib.use("agg")
17-
from matplotlib import pyplot as plt, colors as mpl_color
1815
import networkx as nx, dwave_networkx as dnx
1916

17+
try:
18+
import matplotlib.pyplot as plt
19+
import matplotlib.colors as mpl_color
20+
except ImportError:
21+
matplotlib.use("agg")
22+
import matplotlib.pyplot as plt
23+
import matplotlib.colors as mpl_color
24+
2025
def color(i, n):
2126
r, g, b = mpl_color.hsv_to_rgb((i/n, .25 + (i%4)/4, 1))
2227
return r, g, b, 1.

Pegasus_Embedding_Video/draw_yield.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
# limitations under the License.
1414

1515
from pegasus_graph import P6
16-
import matplotlib
17-
matplotlib.use("agg")
18-
from matplotlib import pyplot as plt
1916
import dwave_networkx as dnx
2017

18+
try:
19+
import matplotlib.pyplot as plt
20+
except ImportError:
21+
matplotlib.use("agg")
22+
import matplotlib.pyplot as plt
23+
2124
dnx.draw_pegasus_yield(P6, node_size = 80)
2225

2326
dnx.draw_pegasus(P6, node_size = 80)

Pegasus_Embedding_Video/embed_draw_clique.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
# limitations under the License.
1414

1515
from pegasus_graph import P16
16-
import matplotlib
17-
matplotlib.use("agg")
18-
from matplotlib import pyplot as plt
1916
import networkx as nx, dwave_networkx as dnx
20-
2117
from minorminer import busclique
2218

19+
try:
20+
import matplotlib.pyplot as plt
21+
except ImportError:
22+
matplotlib.use("agg")
23+
import matplotlib.pyplot as plt
24+
2325
clique_cache = busclique.busgraph_cache(P16)
2426
clique_embedding = clique_cache.largest_clique()
2527

Pegasus_Embedding_Video/embed_draw_random.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
# limitations under the License.
1414

1515
from pegasus_graph import P6
16-
import matplotlib
17-
matplotlib.use("agg")
18-
from matplotlib import pyplot as plt, colors as mpl_color
1916
import networkx as nx, dwave_networkx as dnx, minorminer
2017

18+
try:
19+
import matplotlib.pyplot as plt
20+
import matplotlib.colors as mpl_color
21+
except ImportError:
22+
matplotlib.use("agg")
23+
import matplotlib.pyplot as plt
24+
import matplotlib.colors as mpl_color
25+
2126
nodes = 80
2227
edge_probability = 0.1
2328
G = nx.gnp_random_graph(nodes, edge_probability, seed = 0)

Pegasus_Embedding_Video/embed_draw_sparse.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@
1414

1515
from pegasus_graph import P16, P6
1616
import minorminer.layout as mml, dwave_networkx as dnx, networkx as nx
17-
import matplotlib
18-
matplotlib.use("agg")
19-
from matplotlib import pyplot as plt, colors as mpl_color
17+
18+
try:
19+
import matplotlib.pyplot as plt
20+
import matplotlib.colors as mpl_color
21+
except ImportError:
22+
matplotlib.use("agg")
23+
import matplotlib.pyplot as plt
24+
import matplotlib.colors as mpl_color
2025

2126
# Draw a small P6 graph
2227
n = 200
2328
C = nx.random_regular_graph(3, n)
2429

25-
emb, (layout_C, layout_P) = mml.find_embedding(C, P6, random_seed = 1,
26-
return_layouts = True,
27-
threads = 3)
30+
emb, (layout_C, layout_P) = mml.find_embedding(C, P6, random_seed=1,
31+
return_layouts=True,
32+
threads=3)
2833

2934
plt.figure(figsize=(20, 20))
3035

@@ -44,9 +49,15 @@
4449
n = 850
4550
C = nx.random_regular_graph(3, n)
4651

47-
emb, (layout_C, layout_P) = mml.find_embedding(C, P16, random_seed = 2,
48-
return_layouts = True, layout = (None, None),
49-
threads = 3, verbose = 2, interactive = True, tries = 30, max_no_improvement = 10000, timeout = 10000000)
52+
emb, (layout_C, layout_P) = mml.find_embedding(C, P16, random_seed=2,
53+
return_layouts=True,
54+
layout=(None, None),
55+
threads=3,
56+
verbose=2,
57+
interactive=True,
58+
tries=30,
59+
max_no_improvement=10000,
60+
timeout=10000000)
5061

5162
plt.figure(figsize=(20, 20))
5263

0 commit comments

Comments
 (0)