diff --git a/.circleci/config.yml b/.circleci/config.yml index 1d3b71ba..daa3cc15 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -197,7 +197,7 @@ jobs: command: | . env/bin/activate pip install . - [[ "$(pip show dwave-networkx 2>/dev/null | grep Version)" == "Version: $CIRCLE_TAG" ]] + [[ "$(pip show dwave-graphs 2>/dev/null | grep Version)" == "Version: $CIRCLE_TAG" ]] - run: name: Build sdist and bdist @@ -219,17 +219,17 @@ workflows: matrix: parameters: python-version: &python-versions ["3.10", "3.11", "3.12", "3.13", "3.14"] - dependency-versions: ["dimod==0.12.5 networkx==2.4 oldest-supported-numpy", # oldest supported - "dimod networkx numpy", # latest + dependency-versions: [&dependencies-oldest "dimod==0.12.5 networkx==2.4 oldest-supported-numpy", + &dependencies-latest "dimod networkx numpy", ] exclude: # dimod < 0.12.13 not supported on py312+ - python-version: "3.12" - dependency-versions: "dimod==0.12.5 networkx==2.4 oldest-supported-numpy" + dependency-versions: *dependencies-oldest - python-version: "3.13" - dependency-versions: "dimod==0.12.5 networkx==2.4 oldest-supported-numpy" + dependency-versions: *dependencies-oldest - python-version: "3.14" - dependency-versions: "dimod==0.12.5 networkx==2.4 oldest-supported-numpy" + dependency-versions: *dependencies-oldest - test-osx: matrix: parameters: diff --git a/.coveragerc b/.coveragerc index a8fd2ff1..98635e7f 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,8 +1,9 @@ [run] -# omit virtualenv and test files -omit = venv/*, */tests/* -source=dwave_networkx +source = dwave.graphs +omit = env/*, venv/*, */tests/* [report] -exclude_lines: +include_namespace_packages = True +exclude_lines = pragma: no cover + raise NotImplementedError diff --git a/.gitignore b/.gitignore index 519d747d..ee51c183 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ build _build dist -dwave_networkx.egg-info +*.egg-info/ *.pyc venv/ diff --git a/README.rst b/README.rst index feece838..79c52200 100644 --- a/README.rst +++ b/README.rst @@ -1,21 +1,19 @@ -.. image:: https://img.shields.io/pypi/v/dwave-networkx.svg - :target: https://pypi.org/project/dwave-networkx +.. image:: https://img.shields.io/pypi/v/dwave-graphs.svg + :target: https://pypi.org/project/dwave-graphs -.. image:: https://codecov.io/gh/dwavesystems/dwave-networkx/branch/main/graph/badge.svg - :target: https://codecov.io/gh/dwavesystems/dwave-networkx +.. image:: https://codecov.io/gh/dwavesystems/dwave-graphs/branch/main/graph/badge.svg + :target: https://codecov.io/gh/dwavesystems/dwave-graphs .. image:: https://circleci.com/gh/dwavesystems/dwave-networkx.svg?style=svg - :target: https://circleci.com/gh/dwavesystems/dwave-networkx + :target: https://circleci.com/gh/dwavesystems/dwave-graphs -============== -dwave-networkx -============== +============ +dwave-graphs +============ -.. start_dnx_about +.. start_graphs_about -dwave-networkx is an extension of `NetworkX `_\ ---a -Python language package for exploration and analysis of networks and network -algorithms---for users of D-Wave quantum computers. It provides tools for +dwave-graphs provides tools for working with quantum processing unit (QPU) topology graphs, such as the Pegasus used on the Advantage\ :sup:`TM` quantum computer, and implementations of graph-theory algorithms on D-Wave quantum computers and other binary quadratic @@ -23,10 +21,10 @@ model (BQM) samplers. This example generates a Pegasus graph of the size used by Advantage QPUs. ->>> import dwave_networkx as dnx ->>> graph = dnx.pegasus_graph(16) +>>> import dwave.graphs +>>> graph = dwave.graphs.pegasus_graph(16) -.. end_dnx_about +.. end_graphs_about Installation ============ @@ -35,7 +33,7 @@ Installation .. code-block:: bash - pip install dwave_networkx + pip install dwave-graphs **Installation from source:** diff --git a/docs/Makefile b/docs/Makefile index 0a24773c..e0457e84 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -4,7 +4,7 @@ # You can set these variables from the command line. SPHINXOPTS = -q SPHINXBUILD = sphinx-build -SPHINXPROJ = DWaveNetworkx +SPHINXPROJ = dwave SOURCEDIR = . BUILDDIR = build diff --git a/docs/algorithms.rst b/docs/algorithms.rst index fdeebbe9..119d03be 100644 --- a/docs/algorithms.rst +++ b/docs/algorithms.rst @@ -1,4 +1,4 @@ -.. _dnx_algorithms: +.. _graphs_algorithms: ========== Algorithms @@ -7,21 +7,21 @@ Algorithms Implementations of graph-theory algorithms on the D-Wave system and other binary quadratic model samplers. -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.graphs -.. _dnx_canonicalization: +.. _graphs_canonicalization: Canonicalization ================ -.. automodule:: dwave_networkx.algorithms.canonicalization +.. automodule:: dwave.graphs.algorithms.canonicalization .. autosummary:: :toctree: generated/ canonical_chimera_labeling -.. _dnx_clique: +.. _graphs_clique: Clique ====== @@ -35,7 +35,7 @@ that for every two vertices in C there exists an edge connecting the two. :align: center :scale: 40 % -.. automodule:: dwave_networkx.algorithms.clique +.. automodule:: dwave.graphs.algorithms.clique .. autosummary:: :toctree: generated/ @@ -44,7 +44,7 @@ that for every two vertices in C there exists an edge connecting the two. clique_number is_clique -.. _dnx_coloring: +.. _graphs_coloring: Coloring ======== @@ -67,7 +67,7 @@ The map-coloring problem is to assign a color to each region of a map Coloring a map of Canada with four colors. -.. automodule:: dwave_networkx.algorithms.coloring +.. automodule:: dwave.graphs.algorithms.coloring .. autosummary:: :toctree: generated/ @@ -78,7 +78,7 @@ The map-coloring problem is to assign a color to each region of a map vertex_color vertex_color_qubo -.. _dnx_cover: +.. _graphs_cover: Cover ===== @@ -96,7 +96,7 @@ edges of the graph are incident to at least one of the vertices in the set. (the horizontal tile of the Chimera unit cell) and the red set (vertical tile) connect to all 16 edges of the graph. -.. automodule:: dwave_networkx.algorithms.cover +.. automodule:: dwave.graphs.algorithms.cover .. autosummary:: :toctree: generated/ @@ -105,7 +105,7 @@ edges of the graph are incident to at least one of the vertices in the set. min_weighted_vertex_cover min_vertex_cover -.. _dnx_elimination_ordering: +.. _graphs_elimination_ordering: Elimination Ordering ==================== @@ -122,7 +122,7 @@ whose neighborhood induces a clique. A perfect elimination ordering is an ordering of vertices :math:`1..n` such that any vertex :math:`i` is simplicial for the subset of vertices :math:`i..n`. -.. automodule:: dwave_networkx.algorithms.elimination_ordering +.. automodule:: dwave.graphs.algorithms.elimination_ordering .. autosummary:: :toctree: generated/ @@ -138,12 +138,12 @@ for the subset of vertices :math:`i..n`. pegasus_elimination_order treewidth_branch_and_bound -.. _dnx_markov: +.. _graphs_markov: Markov Networks =============== -.. automodule:: dwave_networkx.algorithms.markov +.. automodule:: dwave.graphs.algorithms.markov .. autosummary:: :toctree: generated/ @@ -151,7 +151,7 @@ Markov Networks sample_markov_network markov_network_bqm -.. _dnx_matching: +.. _graphs_matching: Matching ======== @@ -167,7 +167,7 @@ A matching is a subset of graph edges in which no vertex occurs more than once. A matching for a Chimera unit cell: no vertex is incident to more than one edge in the set of blue edges -.. automodule:: dwave_networkx.algorithms.matching +.. automodule:: dwave.graphs.algorithms.matching .. autosummary:: :toctree: generated/ @@ -177,7 +177,7 @@ A matching is a subset of graph edges in which no vertex occurs more than once. min_maximal_matching_bqm min_maximal_matching -.. _dnx_maximum_cut: +.. _graphs_maximum_cut: Maximum Cut =========== @@ -195,7 +195,7 @@ between this subset and the remaining vertices is as large as possible. nodes {4, 5, 6, 7} cuts 16 edges; adding or removing a node decreases the number of edges between the two complementary subsets of the graph. -.. automodule:: dwave_networkx.algorithms.max_cut +.. automodule:: dwave.graphs.algorithms.max_cut .. autosummary:: :toctree: generated/ @@ -203,7 +203,7 @@ between this subset and the remaining vertices is as large as possible. maximum_cut weighted_maximum_cut -.. _dnx_independent_set: +.. _graphs_independent_set: Independent Set =============== @@ -222,7 +222,7 @@ its member pairs. (vertical tile) are independent sets of the graph, with no blue node adjacent to another blue node and likewise for red nodes. -.. automodule:: dwave_networkx.algorithms.independent_set +.. automodule:: dwave.graphs.algorithms.independent_set .. autosummary:: :toctree: generated/ @@ -239,7 +239,7 @@ Helper Functions maximum_weighted_independent_set_qubo -.. _dnx_partitioning: +.. _graphs_partitioning: Partitioning ============ @@ -258,14 +258,14 @@ is as small as possible. and the nodes in red are in the '1' subset. There are no other arrangements with fewer edges between two equally sized subsets. -.. automodule:: dwave_networkx.algorithms.partition +.. automodule:: dwave.graphs.algorithms.partition .. autosummary:: :toctree: generated/ partition -.. _dnx_social: +.. _graphs_social: Social ====== @@ -284,7 +284,7 @@ friendly/hostile interactions between vertices. cleanly divided into two subsets, {Bob, Eve} and {Alice}, with friendly relations within each subset and only hostile relations between the subsets. -.. automodule:: dwave_networkx.algorithms.social +.. automodule:: dwave.graphs.algorithms.social .. autosummary:: :toctree: generated/ @@ -292,7 +292,7 @@ friendly/hostile interactions between vertices. structural_imbalance structural_imbalance_ising -.. _dnx_traveling_salesperson: +.. _graphs_traveling_salesperson: Traveling Salesperson ===================== @@ -308,7 +308,7 @@ weighted graph. A traveling salesperson route of [2, 1, 0, 3]. -.. automodule:: dwave_networkx.algorithms.tsp +.. automodule:: dwave.graphs.algorithms.tsp .. autosummary:: :toctree: generated/ diff --git a/docs/api_ref.rst b/docs/api_ref.rst index 9c2f59a7..be9bbe3b 100644 --- a/docs/api_ref.rst +++ b/docs/api_ref.rst @@ -1,4 +1,4 @@ -.. _dnx_api_ref: +.. _graphs_api_ref: ============= API Reference diff --git a/docs/conf.py b/docs/conf.py index c3649ce3..92cf72ec 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,10 +1,3 @@ -# DWaveNetworkX documentation build configuration file, created by -# sphinx-quickstart on Wed Jul 26 10:55:26 2017. -# -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html - import os import sys sys.path.insert(0, os.path.abspath('.')) @@ -32,13 +25,13 @@ master_doc = 'index' # General information about the project. -project = u'D-Wave NetworkX' -copyright = u'2017, D-Wave Systems Inc' -author = u'D-Wave Systems Inc' +project = u'D-Wave Graphs' +copyright = u'2025, D-Wave Inc' +author = u'D-Wave Inc' -import dwave_networkx -version = dwave_networkx.__version__ -release = dwave_networkx.__version__ +import dwave.graphs +version = dwave.graphs.__version__ +release = dwave.graphs.__version__ language = 'en' @@ -56,11 +49,11 @@ todo_include_todos = True -modindex_common_prefix = ['dwave_networkx.'] +modindex_common_prefix = ['dwave.graphs.'] doctest_global_setup = \ """ -import dwave_networkx as dnx +import dwave.graphs import networkx as nx """ diff --git a/docs/default_sampler.rst b/docs/default_sampler.rst index 9540c0d2..1c4c7ad5 100644 --- a/docs/default_sampler.rst +++ b/docs/default_sampler.rst @@ -1,12 +1,12 @@ -.. _dnx_default_sampler: +.. _graphs_default_sampler: =============== Default sampler =============== -.. currentmodule:: dwave_networkx.default_sampler +.. currentmodule:: dwave.graphs.default_sampler -.. automodule:: dwave_networkx.default_sampler +.. automodule:: dwave.graphs.default_sampler Functions ========= diff --git a/docs/drawing.rst b/docs/drawing.rst index 74b00105..848129ff 100644 --- a/docs/drawing.rst +++ b/docs/drawing.rst @@ -1,4 +1,4 @@ -.. _dnx_drawing: +.. _graphs_drawing: ======= Drawing @@ -7,12 +7,12 @@ Drawing Tools to visualize topologies of D-Wave QPUs and weighted :term:`graph` problems on them. -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.graphs Chimera Graph Functions ======================= -.. automodule:: dwave_networkx.drawing.chimera_layout +.. automodule:: dwave.graphs.drawing.chimera_layout .. autosummary:: :toctree: generated/ @@ -34,12 +34,12 @@ positions on a Chimera unit cell. .. code-block:: python >>> import networkx as nx - >>> import dwave_networkx as dnx >>> import matplotlib.pyplot as plt + >>> import dwave.graphs >>> H = nx.Graph() >>> H.add_nodes_from([0, 4, 5, 6, 7]) >>> H.add_edges_from([(0, 4), (0, 5), (0, 6), (0, 7)]) - >>> pos=dnx.chimera_layout(H) + >>> pos = dwave.graphs.chimera_layout(H) >>> pos {0: array([ 0. , -0.5]), 4: array([ 0.5, 0. ]), @@ -48,9 +48,9 @@ positions on a Chimera unit cell. 7: array([ 0.5, -1. ])} >>> # Show graph H on a Chimera unit cell >>> f, axes = plt.subplots(1, 1) - >>> G=dnx.chimera_graph(1, 1, 4) # Draw a Chimera unit cell - >>> dnx.draw_chimera(G, node_color='r', ax=axes) - >>> dnx.draw_chimera(H, node_color='b', node_shape='*', style='dashed', edge_color='b', width=3, ax=axes) + >>> G = dwave.graphs.chimera_graph(1, 1, 4) # Draw a Chimera unit cell + >>> dwave.graphs.draw_chimera(G, node_color='r', ax=axes) + >>> dwave.graphs.draw_chimera(H, node_color='b', node_shape='*', style='dashed', edge_color='b', width=3, ax=axes) >>> plt.show() >>> # matplotlib commands to add labels to graphic not shown @@ -67,7 +67,7 @@ positions on a Chimera unit cell. Pegasus Graph Functions ======================= -.. automodule:: dwave_networkx.drawing.pegasus_layout +.. automodule:: dwave.graphs.drawing.pegasus_layout .. autosummary:: :toctree: generated/ @@ -86,15 +86,15 @@ of nodes of a simple 5-node graph on a small Pegasus lattice. .. code-block:: python - >>> import dwave_networkx as dnx + >>> import dwave.graphs >>> import matplotlib.pyplot as plt - >>> G = dnx.pegasus_graph(2) - >>> H = dnx.pegasus_graph(2, node_list=[4, 40, 41, 42, 43], + >>> G = dwave.graphs.pegasus_graph(2) + >>> H = dwave.graphs.pegasus_graph(2, node_list=[4, 40, 41, 42, 43], edge_list=[(4, 40), (4, 41), (4, 42), (4, 43)]) >>> # Show graph H on a small Pegasus lattice >>> f, axes = plt.subplots(1, 1) - >>> dnx.draw_pegasus(G, with_labels=True, crosses=True, node_color="Yellow", ax=axes) - >>> dnx.draw_pegasus(H, crosses=True, node_color='b', style='dashed', + >>> dwave.graphs.draw_pegasus(G, with_labels=True, crosses=True, node_color="Yellow", ax=axes) + >>> dwave.graphs.draw_pegasus(H, crosses=True, node_color='b', style='dashed', edge_color='b', width=3, ax=axes) >>> plt.show() @@ -110,7 +110,7 @@ of nodes of a simple 5-node graph on a small Pegasus lattice. Zephyr Graph Functions ====================== -.. automodule:: dwave_networkx.drawing.zephyr_layout +.. automodule:: dwave.graphs.drawing.zephyr_layout .. autosummary:: :toctree: generated/ @@ -129,15 +129,15 @@ of a five-node clique on a small Zephyr graph. .. code-block:: python - >>> import dwave_networkx as dnx + >>> import dwave.graphs >>> import matplotlib.pyplot as plt >>> import networkx as nx ... - >>> G = dnx.zephyr_graph(1) + >>> G = dwave.graphs.zephyr_graph(1) >>> embedding = {"N1": [13, 44], "N2": [11], "N3": [41], "N4": [40], "N5": [9, 37]} ... >>> plt.ion() - >>> dnx.draw_zephyr_embedding(G, embedding, show_labels=True) + >>> dwave.graphs.draw_zephyr_embedding(G, embedding, show_labels=True) .. figure:: _images/zephyr_embedding_5clique.png :align: center diff --git a/docs/generators.rst b/docs/generators.rst index f70fe3bd..e903a649 100644 --- a/docs/generators.rst +++ b/docs/generators.rst @@ -1,4 +1,4 @@ -.. _dnx_generators: +.. _graphs_generators: ================ Graph Generators @@ -6,7 +6,7 @@ Graph Generators Generators for graphs, such the graphs (topologies) of D-Wave System QPUs. -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.graphs D-Wave Systems ============== @@ -28,9 +28,9 @@ the `find_chimera()` function to determine the Chimera indices. .. code-block:: python >>> import networkx as nx - >>> import dwave_networkx as dnx - >>> G = dnx.chimera_graph(1, 1, 4) - >>> chimera_indices = dnx.find_chimera_indices(G) + >>> import dwave.graphs + >>> G = dwave.graphs.chimera_graph(1, 1, 4) + >>> chimera_indices = dwave.graphs.find_chimera_indices(G) >>> print chimera_indices {0: (0, 0, 0, 0), 1: (0, 0, 0, 1), diff --git a/docs/index.rst b/docs/index.rst index 9e0fe511..052b6eb2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,28 +1,28 @@ -.. _index_dnx: +.. _index_graphs: -============== -dwave-networkx -============== +============ +dwave-graphs +============ .. toctree:: - :caption: Reference documentation for dwave-networkx: + :caption: Reference documentation for dwave-graphs: :maxdepth: 1 api_ref -About dwave-networkx -==================== +About dwave-graphs +================== .. include:: README.rst - :start-after: start_dnx_about - :end-before: end_dnx_about + :start-after: start_graphs_about + :end-before: end_graphs_about Functions such as :func:`.draw_pegasus` provide easy visualization for :term:`Pegasus` graphs while functions such as -:func:`~dwave_networkx.algorithms.max_cut.maximum_cut` or -:func:`~dwave_networkx.algorithms.cover.min_vertex_cover` provide graph +:func:`~dwave.graphs.algorithms.max_cut.maximum_cut` or +:func:`~dwave.graphs.algorithms.cover.min_vertex_cover` provide graph algorithms useful to optimization problems that fit well with |dwave_short| quantum computers. @@ -30,7 +30,7 @@ Like |dwave_short| quantum computers, all other supported samplers must have ``sample_qubo`` and ``sample_ising`` methods for solving :term:`Ising` and :term:`QUBO` models and return an iterable of samples in order of increasing energy. You can set a default sampler using the -:func:`~dwave_networkx.default_sampler.set_default_sampler` function. +:func:`~dwave.graphs.default_sampler.set_default_sampler` function. Usage Information ================= diff --git a/docs/utilities.rst b/docs/utilities.rst index 78f2f018..e6bc42a9 100644 --- a/docs/utilities.rst +++ b/docs/utilities.rst @@ -1,27 +1,27 @@ -.. _dnx_utilities: +.. _graphs_utilities: ========= Utilities ========= -.. automodule:: dwave_networkx.utils -.. currentmodule:: dwave_networkx.utils +.. automodule:: dwave.graphs.utils +.. currentmodule:: dwave.graphs.utils Decorators ========== -.. automodule:: dwave_networkx.utils.decorators +.. automodule:: dwave.graphs.utils.decorators .. autosummary:: :toctree: generated/ binary_quadratic_model_sampler -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.graphs Graph Indexing ============== -See the :ref:`dnx_coordinates_conversion` subsection on instantiating the needed +See the :ref:`graphs_coordinates_conversion` subsection on instantiating the needed lattice size and setting correct domain and range for coordinates in a QPU working graph. For the iterator versions of these functions, see the code. @@ -69,12 +69,12 @@ Zephyr zephyr_sublattice_mappings -.. _dnx_coordinates_conversion: +.. _graphs_coordinates_conversion: Coordinates Conversion ---------------------- -.. automodule:: dwave_networkx +.. automodule:: dwave.graphs .. autoclass:: chimera_coordinates @@ -87,7 +87,7 @@ Coordinates Conversion Exceptions ========== -.. automodule:: dwave_networkx.exceptions +.. automodule:: dwave.graphs.exceptions .. autosummary:: :toctree: generated/ diff --git a/dwave_networkx/__init__.py b/dwave/graphs/__init__.py similarity index 60% rename from dwave_networkx/__init__.py rename to dwave/graphs/__init__.py index f948c483..fbd1b8c8 100644 --- a/dwave_networkx/__init__.py +++ b/dwave/graphs/__init__.py @@ -12,20 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -import dwave_networkx.generators -from dwave_networkx.generators import * +import dwave.graphs.generators +from dwave.graphs.generators import * -import dwave_networkx.algorithms -from dwave_networkx.algorithms import * +import dwave.graphs.algorithms +from dwave.graphs.algorithms import * -import dwave_networkx.utils -from dwave_networkx.exceptions import * +import dwave.graphs.utils +from dwave.graphs.exceptions import * -import dwave_networkx.default_sampler -from dwave_networkx.default_sampler import * +import dwave.graphs.default_sampler +from dwave.graphs.default_sampler import * -import dwave_networkx.drawing -from dwave_networkx.drawing import * +import dwave.graphs.drawing +from dwave.graphs.drawing import * -from dwave_networkx.package_info import __version__, __author__, \ +from dwave.graphs.package_info import __version__, __author__, \ __authoremail__, __description__ diff --git a/dwave/graphs/algorithms/__init__.py b/dwave/graphs/algorithms/__init__.py new file mode 100644 index 00000000..5361374e --- /dev/null +++ b/dwave/graphs/algorithms/__init__.py @@ -0,0 +1,26 @@ +# Copyright 2018 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 dwave.graphs.algorithms.independent_set import * +from dwave.graphs.algorithms.canonicalization import * +from dwave.graphs.algorithms.clique import * +from dwave.graphs.algorithms.cover import * +from dwave.graphs.algorithms.matching import * +from dwave.graphs.algorithms.social import * +from dwave.graphs.algorithms.elimination_ordering import * +from dwave.graphs.algorithms.coloring import * +from dwave.graphs.algorithms.max_cut import * +from dwave.graphs.algorithms.markov import * +from dwave.graphs.algorithms.tsp import * +from dwave.graphs.algorithms.partition import * diff --git a/dwave_networkx/algorithms/canonicalization.py b/dwave/graphs/algorithms/canonicalization.py similarity index 98% rename from dwave_networkx/algorithms/canonicalization.py rename to dwave/graphs/algorithms/canonicalization.py index af4f90c0..79d85593 100644 --- a/dwave_networkx/algorithms/canonicalization.py +++ b/dwave/graphs/algorithms/canonicalization.py @@ -14,8 +14,6 @@ import math -from dwave_networkx.generators.chimera import chimera_coordinates - __all__ = ['canonical_chimera_labeling'] diff --git a/dwave_networkx/algorithms/clique.py b/dwave/graphs/algorithms/clique.py similarity index 94% rename from dwave_networkx/algorithms/clique.py rename to dwave/graphs/algorithms/clique.py index 0b65f085..3ab793e0 100644 --- a/dwave_networkx/algorithms/clique.py +++ b/dwave/graphs/algorithms/clique.py @@ -13,12 +13,13 @@ # limitations under the License. import networkx as nx -import dwave_networkx as dnx -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.algorithms import maximum_independent_set +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ["maximum_clique", "clique_number", "is_clique"] + @binary_quadratic_model_sampler(1) def maximum_clique(G, sampler=None, lagrange=2.0, **sampler_args): r"""Returns an approximate maximum clique. @@ -87,7 +88,7 @@ def maximum_clique(G, sampler=None, lagrange=2.0, **sampler_args): # finding the maximum clique in a graph is equivalent to finding # the independent set in the complementary graph complement_G = nx.complement(G) - return dnx.maximum_independent_set(complement_G, sampler, lagrange, **sampler_args) + return maximum_independent_set(complement_G, sampler, lagrange, **sampler_args) @binary_quadratic_model_sampler(1) @@ -172,11 +173,11 @@ def is_clique(G, clique_nodes): the horizontal tile's nodes; the second has nodes from the horizontal and verical tiles. - >>> import dwave_networkx as dnx - >>> G = dnx.chimera_graph(1, 1, 4) - >>> dnx.is_clique(G, [0, 1, 2, 3]) + >>> import dwave.graphs + >>> G = dwave.graphs.chimera_graph(1, 1, 4) + >>> dwave.graphs.is_clique(G, [0, 1, 2, 3]) False - >>> dnx.is_clique(G, [0, 4]) + >>> dwave.graphs.is_clique(G, [0, 4]) True """ for x in clique_nodes: diff --git a/dwave_networkx/algorithms/coloring.py b/dwave/graphs/algorithms/coloring.py similarity index 98% rename from dwave_networkx/algorithms/coloring.py rename to dwave/graphs/algorithms/coloring.py index 3ce60432..f4189508 100644 --- a/dwave_networkx/algorithms/coloring.py +++ b/dwave/graphs/algorithms/coloring.py @@ -17,7 +17,7 @@ import networkx as nx -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ["is_vertex_coloring", "is_cycle", @@ -391,12 +391,12 @@ def is_vertex_coloring(G, coloring): and another (1) for the four vertical qubits, in which case there are no adjacencies; the second coloring swaps the color of one node. - >>> G = dnx.chimera_graph(1,1,4) + >>> G = dwave.graphs.chimera_graph(1,1,4) >>> colors = {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1} - >>> dnx.is_vertex_coloring(G, colors) + >>> dwave.graphs.is_vertex_coloring(G, colors) True >>> colors[4]=0 - >>> dnx.is_vertex_coloring(G, colors) + >>> dwave.graphs.is_vertex_coloring(G, colors) False """ diff --git a/dwave_networkx/algorithms/cover.py b/dwave/graphs/algorithms/cover.py similarity index 93% rename from dwave_networkx/algorithms/cover.py rename to dwave/graphs/algorithms/cover.py index 6abfa6c7..b77a9e08 100644 --- a/dwave_networkx/algorithms/cover.py +++ b/dwave/graphs/algorithms/cover.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from dwave_networkx.algorithms.independent_set import maximum_weighted_independent_set -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.algorithms.independent_set import maximum_weighted_independent_set +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ['min_weighted_vertex_cover', 'min_vertex_cover', 'is_vertex_cover'] @@ -125,12 +125,12 @@ def min_vertex_cover(G, sampler=None, lagrange=2.0, **sampler_args): vertical (vertices 4,5,6,7) tiles connect to all 16 edges, so repeated executions can return either set. - >>> import dwave_networkx as dnx + >>> import dwave.graphs >>> import dimod >>> sampler = dimod.ExactSolver() # small testing sampler - >>> G = dnx.chimera_graph(1, 1, 4) + >>> G = dwave.graphs.chimera_graph(1, 1, 4) >>> G.remove_node(7) # to give a unique solution - >>> dnx.min_vertex_cover(G, sampler, lagrange=2.0) + >>> dwave.graphs.min_vertex_cover(G, sampler, lagrange=2.0) [4, 5, 6] Notes @@ -177,13 +177,13 @@ def is_vertex_cover(G, vertex_cover): unit cell. The first uses the set of the four horizontal qubits, which do constitute a cover; the second set removes one node. - >>> import dwave_networkx as dnx - >>> G = dnx.chimera_graph(1, 1, 4) + >>> from dwave.graphs import chimera_graph, is_vertex_cover + >>> G = chimera_graph(1, 1, 4) >>> cover = [0, 1, 2, 3] - >>> dnx.is_vertex_cover(G,cover) + >>> is_vertex_cover(G,cover) True >>> cover = [0, 1, 2] - >>> dnx.is_vertex_cover(G,cover) + >>> is_vertex_cover(G,cover) False """ diff --git a/dwave_networkx/algorithms/elimination_ordering.py b/dwave/graphs/algorithms/elimination_ordering.py similarity index 96% rename from dwave_networkx/algorithms/elimination_ordering.py rename to dwave/graphs/algorithms/elimination_ordering.py index c47675e2..4d3a29cd 100644 --- a/dwave_networkx/algorithms/elimination_ordering.py +++ b/dwave/graphs/algorithms/elimination_ordering.py @@ -14,13 +14,13 @@ import itertools -from random import random, sample +from random import random import networkx as nx -from dwave_networkx.generators.pegasus import pegasus_coordinates -from dwave_networkx.generators.zephyr import zephyr_coordinates -from dwave_networkx.generators.chimera import chimera_coordinates +from dwave.graphs.generators.pegasus import pegasus_coordinates +from dwave.graphs.generators.zephyr import zephyr_coordinates +from dwave.graphs.generators.chimera import chimera_coordinates __all__ = ['is_almost_simplicial', 'is_simplicial', @@ -57,11 +57,11 @@ def is_simplicial(G, n): single Chimera unit cell, which is bipartite, and K_5, the :math:`K_5` complete graph. - >>> G = dnx.chimera_graph(1, 1, 4) + >>> G = dwave.graphs.chimera_graph(1, 1, 4) >>> K_5 = nx.complete_graph(5) - >>> dnx.is_simplicial(G, 0) + >>> dwave.graphs.is_simplicial(G, 0) False - >>> dnx.is_simplicial(K_5, 0) + >>> dwave.graphs.is_simplicial(K_5, 0) True """ @@ -90,9 +90,9 @@ def is_almost_simplicial(G, n): >>> K_5 = nx.complete_graph(5) >>> K_5.remove_edge(1,3) - >>> dnx.is_simplicial(K_5, 0) + >>> dwave.graphs.is_simplicial(K_5, 0) False - >>> dnx.is_almost_simplicial(K_5, 0) + >>> dwave.graphs.is_almost_simplicial(K_5, 0) True """ @@ -121,7 +121,7 @@ def minor_min_width(G): complete graph. >>> K_7 = nx.complete_graph(7) - >>> dnx.minor_min_width(K_7) + >>> dwave.graphs.minor_min_width(K_7) 6 References @@ -192,7 +192,7 @@ def min_fill_heuristic(G): complete graph. >>> K_4 = nx.complete_graph(4) - >>> tw, order = dnx.min_fill_heuristic(K_4) + >>> tw, order = dwave.graphs.min_fill_heuristic(K_4) References ---------- @@ -262,7 +262,7 @@ def min_width_heuristic(G): complete graph. >>> K_4 = nx.complete_graph(4) - >>> tw, order = dnx.min_width_heuristic(K_4) + >>> tw, order = dwave.graphs.min_width_heuristic(K_4) References ---------- @@ -322,7 +322,7 @@ def max_cardinality_heuristic(G): complete graph. >>> K_4 = nx.complete_graph(4) - >>> tw, order = dnx.max_cardinality_heuristic(K_4) + >>> tw, order = dwave.graphs.max_cardinality_heuristic(K_4) References ---------- @@ -423,10 +423,10 @@ def elimination_order_width(G, order): heuristic. >>> K_4 = nx.complete_graph(4) - >>> tw, order = dnx.min_width_heuristic(K_4) + >>> tw, order = dwave.graphs.min_width_heuristic(K_4) >>> print(tw) 3 - >>> dnx.elimination_order_width(K_4, order) + >>> dwave.graphs.elimination_order_width(K_4, order) 3 @@ -492,7 +492,7 @@ def treewidth_branch_and_bound(G, elimination_order=None, treewidth_upperbound=N ordering of the nodes, arbitrally chosen). >>> K_7 = nx.complete_graph(7) - >>> dnx.treewidth_branch_and_bound(K_7, [0, 1, 2, 3, 4, 5, 6]) + >>> dwave.graphs.treewidth_branch_and_bound(K_7, [0, 1, 2, 3, 4, 5, 6]) (6, [0, 1, 2, 3, 4, 5, 6]) References @@ -835,7 +835,7 @@ def chimera_elimination_order(m, n=None, t=4, coordinates=False): Examples -------- - >>> G = dnx.chimera_elimination_order(1, 1, 4) # a single Chimera tile + >>> G = dwave.graphs.chimera_elimination_order(1, 1, 4) # a single Chimera tile """ if n is None: diff --git a/dwave_networkx/algorithms/independent_set.py b/dwave/graphs/algorithms/independent_set.py similarity index 95% rename from dwave_networkx/algorithms/independent_set.py rename to dwave/graphs/algorithms/independent_set.py index 798437ce..8ba12dde 100644 --- a/dwave_networkx/algorithms/independent_set.py +++ b/dwave/graphs/algorithms/independent_set.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ["maximum_weighted_independent_set", "maximum_weighted_independent_set_qubo", @@ -145,8 +145,8 @@ def maximum_independent_set(G, sampler=None, lagrange=2.0, **sampler_args): >>> import dimod >>> sampler = dimod.SimulatedAnnealingSampler() - >>> G = dnx.chimera_graph(1, 1, 4) - >>> indep_nodes = dnx.maximum_independent_set(G, sampler) + >>> G = dwave.graphs.chimera_graph(1, 1, 4) + >>> indep_nodes = dwave.graphs.maximum_independent_set(G, sampler) Notes ----- @@ -195,11 +195,11 @@ def is_independent_set(G, indep_nodes): the horizontal tile's nodes; the second has nodes from the horizontal and verical tiles. - >>> import dwave_networkx as dnx - >>> G = dnx.chimera_graph(1, 1, 4) - >>> dnx.is_independent_set(G, [0, 1, 2, 3]) + >>> from dwave.graphs import chimera_graph, is_independent_set + >>> G = chimera_graph(1, 1, 4) + >>> is_independent_set(G, [0, 1, 2, 3]) True - >>> dnx.is_independent_set(G, [0, 4]) + >>> is_independent_set(G, [0, 4]) False """ @@ -230,7 +230,7 @@ def maximum_weighted_independent_set_qubo(G, weight=None, lagrange=2.0): Examples -------- - >>> from dwave_networkx.algorithms.independent_set import maximum_weighted_independent_set_qubo + >>> from dwave.graphs.algorithms.independent_set import maximum_weighted_independent_set_qubo ... >>> G = nx.path_graph(3) >>> Q = maximum_weighted_independent_set_qubo(G, weight='weight', lagrange=2.0) diff --git a/dwave_networkx/algorithms/markov.py b/dwave/graphs/algorithms/markov.py similarity index 93% rename from dwave_networkx/algorithms/markov.py rename to dwave/graphs/algorithms/markov.py index 22a7d970..72ab9e1c 100644 --- a/dwave_networkx/algorithms/markov.py +++ b/dwave/graphs/algorithms/markov.py @@ -14,7 +14,7 @@ import dimod -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ['sample_markov_network', 'markov_network_bqm'] @@ -95,9 +95,9 @@ def sample_markov_network(MN, sampler=None, fixed_variables=None, ... (0, 1): .5, ... (1, 0): .5, ... (1, 1): 2}} - >>> MN = dnx.markov_network(potentials) + >>> MN = dwave.graphs.markov_network(potentials) >>> sampler = dimod.ExactSolver() - >>> samples = dnx.sample_markov_network(MN, sampler) + >>> samples = dwave.graphs.sample_markov_network(MN, sampler) >>> samples[0] # doctest: +SKIP {'a': 0, 'b': 0} @@ -107,9 +107,9 @@ def sample_markov_network(MN, sampler=None, fixed_variables=None, ... (0, 1): .5, ... (1, 0): .5, ... (1, 1): 2}} - >>> MN = dnx.markov_network(potentials) + >>> MN = dwave.graphs.markov_network(potentials) >>> sampler = dimod.ExactSolver() - >>> samples = dnx.sample_markov_network(MN, sampler, return_sampleset=True) + >>> samples = dwave.graphs.sample_markov_network(MN, sampler, return_sampleset=True) >>> samples.first # doctest: +SKIP Sample(sample={'a': 0, 'b': 0}, energy=-1.0, num_occurrences=1) @@ -123,9 +123,9 @@ def sample_markov_network(MN, sampler=None, fixed_variables=None, ... (0, 1): 1.2, ... (1, 0): 7.2, ... (1, 1): 5}} - >>> MN = dnx.markov_network(potentials) + >>> MN = dwave.graphs.markov_network(potentials) >>> sampler = dimod.ExactSolver() - >>> samples = dnx.sample_markov_network(MN, sampler, fixed_variables={'b': 0}) + >>> samples = dwave.graphs.sample_markov_network(MN, sampler, fixed_variables={'b': 0}) >>> samples[0] # doctest: +SKIP {'a': 0, 'c': 0, 'b': 0} diff --git a/dwave_networkx/algorithms/matching.py b/dwave/graphs/algorithms/matching.py similarity index 96% rename from dwave_networkx/algorithms/matching.py rename to dwave/graphs/algorithms/matching.py index 4b32ce85..75c2d163 100644 --- a/dwave_networkx/algorithms/matching.py +++ b/dwave/graphs/algorithms/matching.py @@ -13,13 +13,11 @@ # limitations under the License. import itertools -import numbers import warnings import dimod -import networkx as nx -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ['is_matching', 'is_maximal_matching', @@ -285,8 +283,8 @@ def min_maximal_matching(G, sampler=None, **sampler_args): >>> import dimod >>> sampler = dimod.ExactSolver() - >>> G = dnx.chimera_graph(1, 1, 4) - >>> matching = dnx.min_maximal_matching(G, sampler) + >>> G = dwave.graphs.chimera_graph(1, 1, 4) + >>> matching = dwave.graphs.min_maximal_matching(G, sampler) Notes ----- @@ -322,8 +320,8 @@ def is_matching(edges): Deprecated in favour of :func:`networkx.is_matching`. """ warnings.warn("This method is deprecated, please use NetworkX's" - "nx.is_matching(G, edges) rather than dwave-networkx's " - "dnx.is_matching(edges)", DeprecationWarning, stacklevel=2) + "nx.is_matching(G, edges) rather than " + "dwave.graphs.is_matching(edges)", DeprecationWarning, stacklevel=2) return len(set().union(*edges)) == len(edges) * 2 @@ -334,7 +332,7 @@ def is_maximal_matching(G, matching): """ warnings.warn("This method is deprecated, please use NetworkX's" "nx.is_maximal_matching(G, edges) rather than " - "dwave-networkx's dnx.is_maximal_matching(G, edges)", + "dwave.graphs.is_maximal_matching(G, edges)", DeprecationWarning, stacklevel=2) touched_nodes = set().union(*matching) diff --git a/dwave_networkx/algorithms/max_cut.py b/dwave/graphs/algorithms/max_cut.py similarity index 95% rename from dwave_networkx/algorithms/max_cut.py rename to dwave/graphs/algorithms/max_cut.py index 6c776762..73dcd9a0 100644 --- a/dwave_networkx/algorithms/max_cut.py +++ b/dwave/graphs/algorithms/max_cut.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from dwave_networkx.exceptions import DWaveNetworkXException -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.exceptions import DWaveNetworkXException +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ["maximum_cut", "weighted_maximum_cut"] @@ -62,8 +62,8 @@ def maximum_cut(G, sampler=None, **sampler_args): >>> import dimod ... >>> sampler = dimod.SimulatedAnnealingSampler() - >>> G = dnx.chimera_graph(1, 1, 4) - >>> cut = dnx.maximum_cut(G, sampler) + >>> G = dwave.graphs.chimera_graph(1, 1, 4) + >>> cut = dwave.graphs.maximum_cut(G, sampler) Notes ----- diff --git a/dwave_networkx/algorithms/partition.py b/dwave/graphs/algorithms/partition.py similarity index 95% rename from dwave_networkx/algorithms/partition.py rename to dwave/graphs/algorithms/partition.py index 42812bcc..dc812481 100644 --- a/dwave_networkx/algorithms/partition.py +++ b/dwave/graphs/algorithms/partition.py @@ -63,8 +63,8 @@ def partition(G, num_partitions=2, sampler=None, **sampler_args): >>> import dimod >>> sampler = dimod.ExactCQMSolver() - >>> G = dnx.chimera_graph(1, 1, 4) - >>> partitions = dnx.partition(G, sampler=sampler) + >>> G = dwave.graphs.chimera_graph(1, 1, 4) + >>> partitions = dwave.graphs.partition(G, sampler=sampler) Notes ----- diff --git a/dwave_networkx/algorithms/social.py b/dwave/graphs/algorithms/social.py similarity index 95% rename from dwave_networkx/algorithms/social.py rename to dwave/graphs/algorithms/social.py index a861832d..8d0cb6bf 100644 --- a/dwave_networkx/algorithms/social.py +++ b/dwave/graphs/algorithms/social.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ["structural_imbalance"] @@ -70,7 +70,7 @@ def structural_imbalance(S, sampler=None, **sampler_args): >>> S.add_edge('Alice', 'Bob', sign=1) # Alice and Bob are friendly >>> S.add_edge('Alice', 'Eve', sign=-1) # Alice and Eve are hostile >>> S.add_edge('Bob', 'Eve', sign=-1) # Bob and Eve are hostile - >>> frustrated_edges, colors = dnx.structural_imbalance(S, sampler) + >>> frustrated_edges, colors = dwave.graphs.structural_imbalance(S, sampler) >>> print(frustrated_edges) {} >>> print(colors) # doctest: +SKIP @@ -78,7 +78,7 @@ def structural_imbalance(S, sampler=None, **sampler_args): >>> S.add_edge('Ted', 'Bob', sign=1) # Ted is friendly with all >>> S.add_edge('Ted', 'Alice', sign=1) >>> S.add_edge('Ted', 'Eve', sign=1) - >>> frustrated_edges, colors = dnx.structural_imbalance(S, sampler) + >>> frustrated_edges, colors = dwave.graphs.structural_imbalance(S, sampler) >>> print(frustrated_edges) # doctest: +SKIP {('Ted', 'Eve'): {'sign': 1}} >>> print(colors) # doctest: +SKIP @@ -159,7 +159,7 @@ def structural_imbalance_ising(S): Examples -------- >>> import dimod - >>> from dwave_networkx.algorithms.social import structural_imbalance_ising + >>> from dwave.graphs.algorithms.social import structural_imbalance_ising ... >>> S = nx.Graph() >>> S.add_edge('Alice', 'Bob', sign=1) # Alice and Bob are friendly diff --git a/dwave_networkx/algorithms/tsp.py b/dwave/graphs/algorithms/tsp.py similarity index 98% rename from dwave_networkx/algorithms/tsp.py rename to dwave/graphs/algorithms/tsp.py index 576b6665..e8a36f10 100644 --- a/dwave_networkx/algorithms/tsp.py +++ b/dwave/graphs/algorithms/tsp.py @@ -16,7 +16,7 @@ from collections import defaultdict -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.graphs.utils import binary_quadratic_model_sampler __all__ = ["traveling_salesperson", "traveling_salesperson_qubo", @@ -80,7 +80,7 @@ def traveling_salesperson(G, sampler=None, lagrange=None, weight='weight', >>> G = nx.Graph() >>> G.add_weighted_edges_from({(0, 1, .1), (0, 2, .5), (0, 3, .1), (1, 2, .1), ... (1, 3, .5), (2, 3, .1)}) - >>> dnx.traveling_salesperson(G, dimod.ExactSolver(), start=0) # doctest: +SKIP + >>> dwave.graphs.traveling_salesperson(G, dimod.ExactSolver(), start=0) # doctest: +SKIP [0, 1, 2, 3] Notes diff --git a/dwave_networkx/default_sampler.py b/dwave/graphs/default_sampler.py similarity index 81% rename from dwave_networkx/default_sampler.py rename to dwave/graphs/default_sampler.py index 8763e663..b14ce086 100644 --- a/dwave_networkx/default_sampler.py +++ b/dwave/graphs/default_sampler.py @@ -54,15 +54,15 @@ ... >>> # Identify the new sampler as the default sampler >>> sampler0 = ExampleSampler('sampler0') ->>> dnx.set_default_sampler(sampler0) +>>> dwave.graphs.set_default_sampler(sampler0) >>> # Find an independent set using the default sampler >>> G = nx.complete_graph(5) ->>> dnx.maximum_independent_set(G) +>>> dwave.graphs.maximum_independent_set(G) [0] """ -from dwave_networkx.utils.decorators import binary_quadratic_model_sampler +from dwave.graphs.utils.decorators import binary_quadratic_model_sampler __all__ = ['set_default_sampler', 'get_default_sampler', 'unset_default_sampler'] @@ -90,9 +90,9 @@ def set_default_sampler(sampler): set for graph G, first using the default sampler and then overriding it by specifying a different sampler. - >>> dnx.set_default_sampler(sampler0) # doctest: +SKIP - >>> indep_set = dnx.maximum_independent_set_dm(G) # doctest: +SKIP - >>> indep_set = dnx.maximum_independent_set_dm(G, sampler1) # doctest: +SKIP + >>> dwave.graphs.set_default_sampler(sampler0) # doctest: +SKIP + >>> indep_set = dwave.graphs.maximum_independent_set_dm(G) # doctest: +SKIP + >>> indep_set = dwave.graphs.maximum_independent_set_dm(G, sampler1) # doctest: +SKIP """ global _SAMPLER @@ -107,11 +107,11 @@ def unset_default_sampler(): This example sets sampler0 as the default sampler, verifies the setting, then resets the default, and verifies the resetting. - >>> dnx.set_default_sampler(sampler0) # doctest: +SKIP - >>> print(dnx.get_default_sampler()) # doctest: +SKIP + >>> dwave.graphs.set_default_sampler(sampler0) # doctest: +SKIP + >>> print(dwave.graphs.get_default_sampler()) # doctest: +SKIP 'sampler0' - >>> dnx.unset_default_sampler() # doctest: +SKIP - >>> print(dnx.get_default_sampler()) # doctest: +SKIP + >>> dwave.graphs.unset_default_sampler() # doctest: +SKIP + >>> print(dwave.graphs.get_default_sampler()) # doctest: +SKIP None """ global _SAMPLER @@ -126,10 +126,10 @@ def get_default_sampler(): This example queries the default sampler before and after specifying a default sampler. - >>> print(dnx.get_default_sampler()) # doctest: +SKIP + >>> print(dwave.graphs.get_default_sampler()) # doctest: +SKIP None - >>> dnx.set_default_sampler(sampler) # doctest: +SKIP - >>> print(dnx.get_default_sampler()) # doctest: +SKIP + >>> dwave.graphs.set_default_sampler(sampler) # doctest: +SKIP + >>> print(dwave.graphs.get_default_sampler()) # doctest: +SKIP 'sampler' """ diff --git a/dwave_networkx/drawing/__init__.py b/dwave/graphs/drawing/__init__.py similarity index 74% rename from dwave_networkx/drawing/__init__.py rename to dwave/graphs/drawing/__init__.py index 01cfaa14..e3c8beea 100644 --- a/dwave_networkx/drawing/__init__.py +++ b/dwave/graphs/drawing/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from dwave_networkx.drawing.chimera_layout import * -from dwave_networkx.drawing.pegasus_layout import * -from dwave_networkx.drawing.zephyr_layout import * -from dwave_networkx.drawing.parallel_embeddings import * +from dwave.graphs.drawing.chimera_layout import * +from dwave.graphs.drawing.pegasus_layout import * +from dwave.graphs.drawing.zephyr_layout import * +from dwave.graphs.drawing.parallel_embeddings import * diff --git a/dwave_networkx/drawing/chimera_layout.py b/dwave/graphs/drawing/chimera_layout.py similarity index 95% rename from dwave_networkx/drawing/chimera_layout.py rename to dwave/graphs/drawing/chimera_layout.py index 89db7f4d..ede9e29e 100644 --- a/dwave_networkx/drawing/chimera_layout.py +++ b/dwave/graphs/drawing/chimera_layout.py @@ -11,17 +11,15 @@ # 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. -# -# ================================================================================================ + """ Tools to visualize :term:`Chimera` lattices and weighted :term:`graph` problems on them. """ import networkx as nx -from networkx import draw -from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield -from dwave_networkx.generators.chimera import chimera_graph, find_chimera_indices, chimera_coordinates +from dwave.graphs.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield +from dwave.graphs.generators.chimera import chimera_graph, find_chimera_indices, chimera_coordinates __all__ = ['chimera_layout', 'draw_chimera', 'draw_chimera_embedding', 'draw_chimera_yield'] @@ -59,8 +57,8 @@ def chimera_layout(G, scale=1., center=None, dim=2): Examples -------- - >>> G = dnx.chimera_graph(1) - >>> pos = dnx.chimera_layout(G) + >>> G = dwave.graphs.chimera_graph(1) + >>> pos = dwave.graphs.chimera_layout(G) """ @@ -220,10 +218,10 @@ def draw_chimera(G, **kwargs): -------- >>> # Plot 2x2 Chimera unit cells >>> import networkx as nx - >>> import dwave_networkx as dnx + >>> import dwave.graphs >>> import matplotlib.pyplot as plt # doctest: +SKIP - >>> G = dnx.chimera_graph(2, 2, 4) - >>> dnx.draw_chimera(G) # doctest: +SKIP + >>> G = dwave.graphs.chimera_graph(2, 2, 4) + >>> dwave.graphs.draw_chimera(G) # doctest: +SKIP >>> plt.show() # doctest: +SKIP """ diff --git a/dwave_networkx/drawing/distinguishable_colors.py b/dwave/graphs/drawing/distinguishable_colors.py similarity index 100% rename from dwave_networkx/drawing/distinguishable_colors.py rename to dwave/graphs/drawing/distinguishable_colors.py diff --git a/dwave_networkx/drawing/parallel_embeddings.py b/dwave/graphs/drawing/parallel_embeddings.py similarity index 95% rename from dwave_networkx/drawing/parallel_embeddings.py rename to dwave/graphs/drawing/parallel_embeddings.py index 6775f4f5..6a3a4fd1 100644 --- a/dwave_networkx/drawing/parallel_embeddings.py +++ b/dwave/graphs/drawing/parallel_embeddings.py @@ -11,15 +11,16 @@ # 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 typing import Optional import math import networkx as nx import numpy -from dwave_networkx.drawing.chimera_layout import draw_chimera, chimera_layout -from dwave_networkx.drawing.pegasus_layout import draw_pegasus, pegasus_layout -from dwave_networkx.drawing.zephyr_layout import draw_zephyr, zephyr_layout +from dwave.graphs.drawing.chimera_layout import draw_chimera, chimera_layout +from dwave.graphs.drawing.pegasus_layout import draw_pegasus, pegasus_layout +from dwave.graphs.drawing.zephyr_layout import draw_zephyr, zephyr_layout __all__ = ["draw_parallel_embeddings"] @@ -155,7 +156,7 @@ def draw_parallel_embeddings( use_plt: bool = True, **kwargs, ): - """Visualizes the embeddings using dwave_networkx's layout functions. + """Visualizes the embeddings using dwave-graphs layout functions. Args: G: The target graph to be visualized. @@ -178,13 +179,13 @@ def draw_parallel_embeddings( no embedding in the bottom right. >>> import networkx as nx - >>> import dwave_networkx as dnx + >>> import dwave.graphs >>> import matplotlib.pyplot as plt # doctest: +SKIP - >>> G = dnx.chimera_graph(2) + >>> G = dwave.graphs.chimera_graph(2) >>> S = nx.from_edgelist({(i,i+1) for i in range(7)}) >>> emb = {i: (i // 2) + 4*(i % 2) for i in range(8)} # Top-left embedding >>> embs = [{k: (v+8*offset,) for k,v in emb.items()} for offset in range(3)] - >>> dnx.draw_parallel_embeddings(G, embs) # doctest: +SKIP + >>> dwave.graphs.draw_parallel_embeddings(G, embs) # doctest: +SKIP >>> plt.show() # doctest: +SKIP """ try: diff --git a/dwave_networkx/drawing/pegasus_layout.py b/dwave/graphs/drawing/pegasus_layout.py similarity index 94% rename from dwave_networkx/drawing/pegasus_layout.py rename to dwave/graphs/drawing/pegasus_layout.py index 30ac3d16..dd125cf1 100644 --- a/dwave_networkx/drawing/pegasus_layout.py +++ b/dwave/graphs/drawing/pegasus_layout.py @@ -16,12 +16,11 @@ Tools to visualize :term:`Pegasus` lattices and weighted :term:`graph` problems on them. """ import networkx as nx -from networkx import draw import numpy as np -from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield -from dwave_networkx.generators.pegasus import pegasus_graph, pegasus_coordinates -from dwave_networkx.drawing.chimera_layout import chimera_node_placer_2d +from dwave.graphs.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield +from dwave.graphs.generators.pegasus import pegasus_graph, pegasus_coordinates +from dwave.graphs.drawing.chimera_layout import chimera_node_placer_2d __all__ = ['pegasus_layout', @@ -38,7 +37,7 @@ def pegasus_layout(G, scale=1., center=None, dim=2, crosses=False): ---------- G : NetworkX graph :term:`Pegasus` :term:`graph` or a :term:`subgraph` of a Pegasus graph as produced by - the :func:`dwave_networkx.pegasus_graph` function. + the :func:`dwave.graphs.pegasus_graph` function. scale : float (default 1.) Scale factor. If ``scale`` = 1, all positions fit within @@ -65,13 +64,13 @@ def pegasus_layout(G, scale=1., center=None, dim=2, crosses=False): -------- This example gives the positions of a Pegasus lattice of size 2. - >>> G = dnx.pegasus_graph(2) - >>> pos = dnx.pegasus_layout(G) + >>> G = dwave.graphs.pegasus_graph(2) + >>> pos = dwave.graphs.pegasus_layout(G) """ if not isinstance(G, nx.Graph) or G.graph.get("family") != "pegasus": - raise ValueError("G must be generated by dwave_networkx.pegasus_graph") + raise ValueError("G must be generated by dwave.graphs.pegasus_graph") if G.graph.get('labels') == 'nice': m = 3*(G.graph['rows']-1) @@ -117,7 +116,7 @@ def pegasus_node_placer_2d(G, scale=1., center=None, dim=2, crosses=False): ---------- G : NetworkX graph :term:`Pegasus` :term:`graph` or a :term:`subgraph` of a Pegasus graph as produced by - the :func:`dwave_networkx.pegasus_graph` function. + the :func:`dwave.graphs.pegasus_graph` function. scale : float (default 1.) Scale factor. If ``scale`` = 1, all positions fit within @@ -196,7 +195,7 @@ def draw_pegasus(G, crosses=False, **kwargs): ---------- G : NetworkX graph :term:`Pegasus` :term:`graph` or a :term:`subgraph` of a Pegasus graph as produced by - the :func:`dwave_networkx.pegasus_graph` function. + the :func:`dwave.graphs.pegasus_graph` function. linear_biases : dict (optional, default {}) Linear biases as a dict of the form ``{node: bias, ...}``, where keys are @@ -225,10 +224,10 @@ def draw_pegasus(G, crosses=False, **kwargs): This example plots a Pegasus graph with size parameter 2. >>> import networkx as nx - >>> import dwave_networkx as dnx + >>> import dwave.graphs >>> import matplotlib.pyplot as plt # doctest: +SKIP - >>> G = dnx.pegasus_graph(2) - >>> dnx.draw_pegasus(G) # doctest: +SKIP + >>> G = dwave.graphs.pegasus_graph(2) + >>> dwave.graphs.draw_pegasus(G) # doctest: +SKIP >>> plt.show() # doctest: +SKIP """ @@ -243,7 +242,7 @@ def draw_pegasus_embedding(G, *args, **kwargs): ---------- G : NetworkX graph :term:`Pegasus` :term:`graph` or a :term:`subgraph` of a Pegasus graph as produced by - the :func:`dwave_networkx.pegasus_graph` function. + the :func:`dwave.graphs.pegasus_graph` function. emb : dict Chains as a dict of the form ``{qubit: chain, ...}``, where qubits are diff --git a/dwave_networkx/drawing/qubit_layout.py b/dwave/graphs/drawing/qubit_layout.py similarity index 99% rename from dwave_networkx/drawing/qubit_layout.py rename to dwave/graphs/drawing/qubit_layout.py index cb379b5d..ae66ce5f 100644 --- a/dwave_networkx/drawing/qubit_layout.py +++ b/dwave/graphs/drawing/qubit_layout.py @@ -22,7 +22,7 @@ from networkx import draw -from dwave_networkx.drawing.distinguishable_colors import distinguishable_color_map +from dwave.graphs.drawing.distinguishable_colors import distinguishable_color_map __all__ = ['draw_qubit_graph'] diff --git a/dwave_networkx/drawing/zephyr_layout.py b/dwave/graphs/drawing/zephyr_layout.py similarity index 93% rename from dwave_networkx/drawing/zephyr_layout.py rename to dwave/graphs/drawing/zephyr_layout.py index 4ac869d1..0317ea5c 100644 --- a/dwave_networkx/drawing/zephyr_layout.py +++ b/dwave/graphs/drawing/zephyr_layout.py @@ -17,11 +17,10 @@ """ import networkx as nx -from networkx import draw import numpy as np -from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield -from dwave_networkx.generators.zephyr import zephyr_graph, zephyr_coordinates +from dwave.graphs.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield +from dwave.graphs.generators.zephyr import zephyr_graph, zephyr_coordinates __all__ = ['zephyr_layout', @@ -38,7 +37,7 @@ def zephyr_layout(G, scale=1., center=None, dim=2): ---------- G : NetworkX graph :term:`Zephyr` :term:`graph` or a :term:`subgraph` of a Zephyr graph as produced by - the :func:`dwave_networkx.zephyr_graph` function. + the :func:`dwave.graphs.zephyr_graph` function. scale : float (default 1.) Scale factor. If ``scale`` = 1, all positions fit within @@ -60,13 +59,13 @@ def zephyr_layout(G, scale=1., center=None, dim=2): -------- This example gives the positions of a Zephyr lattice of size 2. - >>> G = dnx.zephyr_graph(2) - >>> pos = dnx.zephyr_layout(G) + >>> G = dwave.graphs.zephyr_graph(2) + >>> pos = dwave.graphs.zephyr_layout(G) """ if not isinstance(G, nx.Graph) or G.graph.get("family") != "zephyr": - raise ValueError("G must be generated by dwave_networkx.zephyr_graph") + raise ValueError("G must be generated by dwave.graphs.zephyr_graph") xy_coords = zephyr_node_placer_2d(G, scale, center, dim) @@ -107,7 +106,7 @@ def zephyr_node_placer_2d(G, scale=1., center=None, dim=2): ---------- G : NetworkX graph :term:`Zephyr` :term:`graph` or a :term:`subgraph` of a Zephyr graph as produced by - the :func:`dwave_networkx.zephyr_graph` function. + the :func:`dwave.graphs.zephyr_graph` function. scale : float (default 1.) Scale factor. If ``scale`` = 1, all positions fit within @@ -167,7 +166,7 @@ def draw_zephyr(G, **kwargs): ---------- G : NetworkX graph :term:`Zephyr` :term:`graph` or a :term:`subgraph` of a Zephyr graph as produced by - the :func:`dwave_networkx.zephyr_graph` function. + the :func:`dwave.graphs.zephyr_graph` function. linear_biases : dict (optional, default {}) Linear biases as a dict of the form ``{node: bias, ...}``, where keys are @@ -191,10 +190,10 @@ def draw_zephyr(G, **kwargs): This example plots a Zephyr graph with size parameter 2. >>> import networkx as nx - >>> import dwave_networkx as dnx + >>> import dwave.graphs >>> import matplotlib.pyplot as plt # doctest: +SKIP - >>> G = dnx.zephyr_graph(2) - >>> dnx.draw_zephyr(G) # doctest: +SKIP + >>> G = dwave.graphs.zephyr_graph(2) + >>> dwave.graphs.draw_zephyr(G) # doctest: +SKIP >>> plt.show() # doctest: +SKIP """ @@ -209,7 +208,7 @@ def draw_zephyr_embedding(G, *args, **kwargs): ---------- G : NetworkX graph :term:`Zephyr` :term:`graph` or a :term:`subgraph` of a Zephyr graph as produced by - the :func:`dwave_networkx.zephyr_graph` function. + the :func:`dwave.graphs.zephyr_graph` function. emb : dict Minor-embedding as a dict of the form ``{node: chain, ...}``, where ``node`` is diff --git a/dwave_networkx/examples/chimera_graph.py b/dwave/graphs/examples/chimera_graph.py similarity index 86% rename from dwave_networkx/examples/chimera_graph.py rename to dwave/graphs/examples/chimera_graph.py index 073c61c3..cab6d2c9 100644 --- a/dwave_networkx/examples/chimera_graph.py +++ b/dwave/graphs/examples/chimera_graph.py @@ -14,9 +14,8 @@ # import matplotlib.pyplot as plt -import dwave_networkx as dnx -import networkx as nx +import dwave.graphs -G = dnx.chimera_graph(2, 2, 4) -dnx.draw_chimera(G) +G = dwave.graphs.chimera_graph(2, 2, 4) +dwave.graphs.draw_chimera(G) plt.show() diff --git a/dwave_networkx/examples/max_cut.py b/dwave/graphs/examples/max_cut.py similarity index 93% rename from dwave_networkx/examples/max_cut.py rename to dwave/graphs/examples/max_cut.py index 98fd1ae0..0cbb3196 100644 --- a/dwave_networkx/examples/max_cut.py +++ b/dwave/graphs/examples/max_cut.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import dwave_networkx as dnx +import dwave.graphs import networkx as nx import dimod @@ -24,7 +24,7 @@ G.add_edges_from([(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (1, 4), (2, 4), (3, 4), (3, 5), (4, 5), (5, 2)]) # Get the max cut -candidate = dnx.maximum_cut(G, sampler) +candidate = dwave.graphs.maximum_cut(G, sampler) if len(candidate) == 3: print (candidate, " is the right length") else: diff --git a/dwave_networkx/examples/max_independent_set.py b/dwave/graphs/examples/max_independent_set.py similarity index 86% rename from dwave_networkx/examples/max_independent_set.py rename to dwave/graphs/examples/max_independent_set.py index 194e0f46..bb4b5737 100644 --- a/dwave_networkx/examples/max_independent_set.py +++ b/dwave/graphs/examples/max_independent_set.py @@ -13,7 +13,7 @@ # limitations under the License. import networkx as nx -import dwave_networkx as dnx +import dwave.graphs import dimod # Use basic simulated annealer @@ -24,8 +24,8 @@ G.add_edges_from([(1,2),(1,3),(2,3),(3,4),(3,5),(4,5),(4,6),(5,6),(6,7)]) # Find the maximum independent set, which is known in this case to be of length 3 -candidate = dnx.maximum_independent_set(G, sampler) -if dnx.is_independent_set(G, candidate) and len(candidate) == 3: +candidate = dwave.graphs.maximum_independent_set(G, sampler) +if dwave.graphs.is_independent_set(G, candidate) and len(candidate) == 3: print(candidate, " is a maximum independent set") else: print(candidate, " is not a minimum vertex coloring") \ No newline at end of file diff --git a/dwave_networkx/examples/min_maximal_matching.py b/dwave/graphs/examples/min_maximal_matching.py similarity index 82% rename from dwave_networkx/examples/min_maximal_matching.py rename to dwave/graphs/examples/min_maximal_matching.py index 82697ee2..f8af6b49 100644 --- a/dwave_networkx/examples/min_maximal_matching.py +++ b/dwave/graphs/examples/min_maximal_matching.py @@ -12,18 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import dwave_networkx as dnx +import dwave.graphs import dimod # Use basic simulated annealer sampler = dimod.SimulatedAnnealingSampler() -G = dnx.chimera_graph(1, 1, 4) +G = dwave.graphs.chimera_graph(1, 1, 4) # Get the minimum maximal matching, which is known in this case to be of # length 4 -candidate = dnx.min_maximal_matching(G, sampler) +candidate = dwave.graphs.min_maximal_matching(G, sampler) -if dnx.is_maximal_matching(G, candidate) and len(candidate) == 4: +if dwave.graphs.is_maximal_matching(G, candidate) and len(candidate) == 4: print (candidate, " is a minimum maximal matching") else: print (candidate, " is not a minimum maximal matching") diff --git a/dwave_networkx/examples/min_vertex_color.py b/dwave/graphs/examples/min_vertex_color.py similarity index 87% rename from dwave_networkx/examples/min_vertex_color.py rename to dwave/graphs/examples/min_vertex_color.py index 15a7fd6d..ddc3e929 100644 --- a/dwave_networkx/examples/min_vertex_color.py +++ b/dwave/graphs/examples/min_vertex_color.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import dwave_networkx as dnx +import dwave.graphs import networkx as nx import dimod @@ -25,8 +25,8 @@ # Get the minimum vertex coloring, which is known in this case to be of # length 6 -candidate = dnx.min_vertex_coloring(G, sampler) -if dnx.is_vertex_coloring(G, candidate) and len(candidate) == 6: +candidate = dwave.graphs.min_vertex_coloring(G, sampler) +if dwave.graphs.is_vertex_coloring(G, candidate) and len(candidate) == 6: print(candidate, " is a minimum vertex coloring") else: print(candidate, " is not a minimum vertex coloring") diff --git a/dwave_networkx/examples/min_vertex_cover.py b/dwave/graphs/examples/min_vertex_cover.py similarity index 89% rename from dwave_networkx/examples/min_vertex_cover.py rename to dwave/graphs/examples/min_vertex_cover.py index fe86feba..9462bb7b 100644 --- a/dwave_networkx/examples/min_vertex_cover.py +++ b/dwave/graphs/examples/min_vertex_cover.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import dwave_networkx as dnx +import dwave.graphs import networkx as nx import dimod @@ -29,8 +29,8 @@ # Get the minimum vertex cover, which is known in this case to be of # length 5 -candidate = dnx.min_vertex_cover(G, sampler) -if dnx.is_vertex_cover(G, candidate) and len(candidate) == 5: +candidate = dwave.graphs.min_vertex_cover(G, sampler) +if dwave.graphs.is_vertex_cover(G, candidate) and len(candidate) == 5: print (candidate, " is a minimum vertex cover") else: print (candidate, " is not a minimum vertex cover") diff --git a/dwave_networkx/exceptions.py b/dwave/graphs/exceptions.py similarity index 100% rename from dwave_networkx/exceptions.py rename to dwave/graphs/exceptions.py diff --git a/dwave_networkx/generators/__init__.py b/dwave/graphs/generators/__init__.py similarity index 75% rename from dwave_networkx/generators/__init__.py rename to dwave/graphs/generators/__init__.py index 6992e508..cf8b8025 100644 --- a/dwave_networkx/generators/__init__.py +++ b/dwave/graphs/generators/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from dwave_networkx.generators.chimera import * -from dwave_networkx.generators.markov import markov_network -from dwave_networkx.generators.pegasus import * -from dwave_networkx.generators.zephyr import * +from dwave.graphs.generators.chimera import * +from dwave.graphs.generators.markov import markov_network +from dwave.graphs.generators.pegasus import * +from dwave.graphs.generators.zephyr import * diff --git a/dwave_networkx/generators/chimera.py b/dwave/graphs/generators/chimera.py similarity index 96% rename from dwave_networkx/generators/chimera.py rename to dwave/graphs/generators/chimera.py index f31ee105..43273633 100644 --- a/dwave_networkx/generators/chimera.py +++ b/dwave/graphs/generators/chimera.py @@ -22,7 +22,7 @@ from networkx.algorithms.bipartite import color from networkx import diameter -from dwave_networkx.exceptions import DWaveNetworkXException +from dwave.graphs.exceptions import DWaveNetworkXException from itertools import product @@ -126,7 +126,7 @@ def chimera_graph(m, n=None, t=None, create_using=None, node_list=None, edge_lis Examples ======== - >>> G = dnx.chimera_graph(1, 1, 2) # a single Chimera tile + >>> G = dwave.graphs.chimera_graph(1, 1, 2) # a single Chimera tile >>> len(G) 4 >>> list(G.nodes()) # doctest: +SKIP @@ -271,12 +271,12 @@ def find_chimera_indices(G): Examples -------- - >>> G = dnx.chimera_graph(1, 1, 4) - >>> chimera_indices = dnx.find_chimera_indices(G) + >>> G = dwave.graphs.chimera_graph(1, 1, 4) + >>> chimera_indices = dwave.graphs.find_chimera_indices(G) >>> G = nx.Graph() >>> G.add_edges_from([(0, 2), (1, 2), (1, 3), (0, 3)]) - >>> chimera_indices = dnx.find_chimera_indices(G) + >>> chimera_indices = dwave.graphs.find_chimera_indices(G) >>> nx.set_node_attributes(G, chimera_indices, 'chimera_index') """ @@ -348,7 +348,7 @@ class chimera_coordinates(object): Convert between Chimera coordinates and linear indices directly - >>> coords = dnx.chimera_coordinates(16, 16, 4) + >>> coords = dwave.graphs.chimera_coordinates(16, 16, 4) >>> coords.chimera_to_linear((0, 2, 0, 1)) 17 >>> coords.linear_to_chimera(17) @@ -356,8 +356,8 @@ class chimera_coordinates(object): Construct a new graph with the coordinate labels - >>> C16 = dnx.chimera_graph(16) - >>> coords = dnx.chimera_coordinates(16) + >>> C16 = dwave.graphs.chimera_graph(16) + >>> coords = dwave.graphs.chimera_coordinates(16) >>> G = nx.Graph() >>> G.add_nodes_from(coords.iter_linear_to_chimera(C16.nodes)) >>> G.add_edges_from(coords.iter_linear_to_chimera_pairs(C16.edges)) @@ -393,7 +393,7 @@ def chimera_to_linear(self, q): Examples -------- - >>> dnx.chimera_coordinates(16).chimera_to_linear((2, 2, 0, 0)) + >>> dwave.graphs.chimera_coordinates(16).chimera_to_linear((2, 2, 0, 0)) 272 """ @@ -420,11 +420,11 @@ def linear_to_chimera(self, r): Returns ------- c : 4-tuple - Chimera coordinates as defined in :func:`~dwave_networkx.chimera_graph`. + Chimera coordinates as defined in :func:`~dwave.graphs.chimera_graph`. Examples -------- - >>> dnx.chimera_coordinates(16).linear_to_chimera(272) + >>> dwave.graphs.chimera_coordinates(16).linear_to_chimera(272) (2, 2, 0, 0) """ m, n, t = self.args @@ -529,7 +529,7 @@ def graph_to_linear(self, g): ) else: raise ValueError( - f"Node labeling {labels} not recognized. Input must be generated by dwave_networkx.chimera_graph." + f"Node labeling {labels} not recognized. Input must be generated by dwave.graphs.chimera_graph." ) def graph_to_chimera(self, g): @@ -561,7 +561,7 @@ def graph_to_chimera(self, g): return g.copy() else: raise ValueError( - f"Node labeling {labels} not recognized. Input must be generated by dwave_networkx.chimera_graph." + f"Node labeling {labels} not recognized. Input must be generated by dwave.graphs.chimera_graph." ) class __chimera_coordinates_cache_dict(dict): @@ -604,7 +604,7 @@ def linear_to_chimera(r, m, n=None, t=None): Examples -------- - >>> G = dnx.linear_to_chimera(212, 8, 8, 4) + >>> G = dwave.graphs.linear_to_chimera(212, 8, 8, 4) (3, 2, 1, 0) """ @@ -641,7 +641,7 @@ def chimera_to_linear(i, j, u, k, m, n=None, t=None): Examples -------- - >>> G = dnx.chimera_to_linear(3, 2, 1, 0, 8, 8, 4) + >>> G = dwave.graphs.chimera_to_linear(3, 2, 1, 0, 8, 8, 4) 212 """ @@ -738,7 +738,7 @@ def chimera_sublattice_mappings(source, target, offset_list=None): """ if not (source.graph.get('family') == target.graph.get('family') == 'chimera'): - raise ValueError("source and target graphs must be Chimera graphs constructed by dwave_networkx.chimera_graph") + raise ValueError("source and target graphs must be Chimera graphs constructed by dwave.graphs.chimera_graph") t = source.graph['tile'] if t != target.graph['tile']: @@ -828,7 +828,7 @@ def chimera_torus(m, n=None, t=None, node_list=None, edge_list=None): Examples ======== - >>> G = dnx.chimera_torus(3, 3, 4) # a 3x3 tile chimera graph (connectivity 6) + >>> G = dwave.graphs.chimera_torus(3, 3, 4) # a 3x3 tile chimera graph (connectivity 6) >>> len(G) 72 >>> any([len(list(G.neighbors(n))) != 6 for n in G.nodes]) @@ -886,8 +886,8 @@ def chimera_two_color(q): A mapping of every qubit (default integer labels) in the Chimera[m, t] graph to one of 2 colors >>> m = 2 - >>> G = dnx.chimera_graph(m, coordinates=True) - >>> colors = {q: dnx.chimera_two_color(q) for q in G.nodes()} + >>> G = dwave.graphs.chimera_graph(m, coordinates=True) + >>> colors = {q: dwave.graphs.chimera_two_color(q) for q in G.nodes()} """ i, j, u, _ = q return (i ^ j ^ u) & 1 diff --git a/dwave_networkx/generators/common.py b/dwave/graphs/generators/common.py similarity index 100% rename from dwave_networkx/generators/common.py rename to dwave/graphs/generators/common.py diff --git a/dwave_networkx/generators/markov.py b/dwave/graphs/generators/markov.py similarity index 98% rename from dwave_networkx/generators/markov.py rename to dwave/graphs/generators/markov.py index ce1cdfd8..0110f8f8 100644 --- a/dwave_networkx/generators/markov.py +++ b/dwave/graphs/generators/markov.py @@ -15,8 +15,6 @@ import itertools import collections.abc as abc -from collections import namedtuple - import networkx as nx @@ -79,7 +77,7 @@ def markov_network(potentials): ... (0, 1): .5, ... (1, 0): .5, ... (1, 1): 2}} - >>> MN = dnx.markov_network(potentials) + >>> MN = dwave.graphs.markov_network(potentials) >>> MN['a']['b']['potential'][(0, 0)] -1 diff --git a/dwave_networkx/generators/pegasus.py b/dwave/graphs/generators/pegasus.py similarity index 97% rename from dwave_networkx/generators/pegasus.py rename to dwave/graphs/generators/pegasus.py index 23ebc68f..f751e859 100644 --- a/dwave_networkx/generators/pegasus.py +++ b/dwave/graphs/generators/pegasus.py @@ -15,11 +15,9 @@ """ Generators for some graphs derived from the D-Wave System. """ -import re - import networkx as nx -from dwave_networkx.exceptions import DWaveNetworkXException +from dwave.graphs.exceptions import DWaveNetworkXException import warnings from itertools import product @@ -182,7 +180,7 @@ def pegasus_graph(m, create_using=None, node_list=None, edge_list=None, data=Tru Examples ======== - >>> G = dnx.pegasus_graph(2, nice_coordinates=True) + >>> G = dwave.graphs.pegasus_graph(2, nice_coordinates=True) >>> G.nodes(data=True)[(0, 0, 0, 0, 0)] # doctest: +SKIP {'linear_index': 4, 'pegasus_index': (0, 0, 4, 0)} @@ -570,7 +568,7 @@ def pegasus_to_linear(self, q): Examples -------- - >>> dnx.pegasus_coordinates(2).pegasus_to_linear((0, 0, 4, 0)) + >>> dwave.graphs.pegasus_coordinates(2).pegasus_to_linear((0, 0, 4, 0)) 4 """ u, w, k, z = q @@ -587,7 +585,7 @@ def linear_to_pegasus(self, r): Examples -------- - >>> dnx.pegasus_coordinates(2).linear_to_pegasus(4) + >>> dwave.graphs.pegasus_coordinates(2).linear_to_pegasus(4) (0, 0, 4, 0) """ @@ -608,7 +606,7 @@ def nice_to_pegasus(n): Examples -------- - >>> dnx.pegasus_coordinates.nice_to_pegasus((0, 0, 0, 0, 0)) + >>> dwave.graphs.pegasus_coordinates.nice_to_pegasus((0, 0, 0, 0, 0)) (0, 0, 4, 0) Note that this method does not depend on the size of the Pegasus @@ -637,7 +635,7 @@ def pegasus_to_nice(p): Examples -------- - >>> dnx.pegasus_coordinates.pegasus_to_nice((0, 0, 4, 0)) + >>> dwave.graphs.pegasus_coordinates.pegasus_to_nice((0, 0, 4, 0)) (0, 0, 0, 0, 0) Note that this method does not depend on the size of the Pegasus @@ -667,7 +665,7 @@ def linear_to_nice(self, r): Examples -------- - >>> dnx.pegasus_coordinates(2).linear_to_nice(4) + >>> dwave.graphs.pegasus_coordinates(2).linear_to_nice(4) (0, 0, 0, 0, 0) """ return self.pegasus_to_nice(self.linear_to_pegasus(r)) @@ -682,7 +680,7 @@ def nice_to_linear(self, n): Examples -------- - >>> dnx.pegasus_coordinates(2).nice_to_linear((0, 0, 0, 0, 0)) + >>> dwave.graphs.pegasus_coordinates(2).nice_to_linear((0, 0, 0, 0, 0)) 4 """ return self.pegasus_to_linear(self.nice_to_pegasus(n)) @@ -808,7 +806,8 @@ def graph_to_linear(self, g): edges = self.iter_nice_to_linear_pairs(g.edges) else: raise ValueError( - f"Node labeling {labels} not recognized. Input must be generated by dwave_networkx.pegasus_graph." + f"Node labeling {labels} not recognized. " + "Input must be generated by dwave.graphs.pegasus_graph." ) return pegasus_graph( @@ -846,7 +845,8 @@ def graph_to_pegasus(self, g): edges = self.iter_nice_to_pegasus_pairs(g.edges) else: raise ValueError( - f"Node labeling {labels} not recognized. Input must be generated by dwave_networkx.pegasus_graph." + f"Node labeling {labels} not recognized. " + "Input must be generated by dwave.graphs.pegasus_graph." ) return pegasus_graph( @@ -885,7 +885,8 @@ def graph_to_nice(self, g): return g.copy() else: raise ValueError( - f"Node labeling {labels} not recognized. Input must be generated by dwave_networkx.pegasus_graph." + f"Node labeling {labels} not recognized. " + "Input must be generated by dwave.graphs.pegasus_graph." ) return pegasus_graph( @@ -1155,7 +1156,8 @@ def pegasus_sublattice_mappings(source, target, offset_list=None): that complex task. """ if target.graph.get('family') != 'pegasus': - raise ValueError("Source graph must be a Pegasus graph constructed by dwave_networkx.pegasus_graph") + raise ValueError("Source graph must be a Pegasus graph constructed by " + "dwave.graphs.pegasus_graph") m_t = target.graph['rows'] labels_t = target.graph['labels'] @@ -1172,7 +1174,8 @@ def nice_to_target(q): labels_s = source.graph['labels'] if source.graph.get('family') == 'chimera': if source.graph['tile'] != 4: - raise ValueError("Cannot construct sublattice mappings from Chimera to Pegasus unless the Chimera tile parameter is 4") + raise ValueError("Cannot construct sublattice mappings from Chimera " + "to Pegasus unless the Chimera tile parameter is 4") m_s = source.graph['rows'] n_s = source.graph['columns'] @@ -1208,7 +1211,9 @@ def source_to_inner(q): make_mapping = _pegasus_pegasus_sublattice_mapping else: - raise ValueError("source graph must be a Chimera graph or Pegasus graph constructed by dwave_networkx.chimera_graph or dwave_networkx.pegasus_graph respectively") + raise ValueError("source graph must be a Chimera graph or Pegasus graph " + "constructed by dwave.graphs.chimera_graph or " + "dwave.graphs.pegasus_graph respectively") for offset in offset_list: yield make_mapping(source_to_inner, nice_to_target, offset) @@ -1217,7 +1222,8 @@ def source_to_inner(q): def pegasus_torus(m, node_list=None, edge_list=None, offset_lists=None, offsets_index=None): """ - Creates a Pegasus graph modified to allow for periodic boundary conditions and translational invariance. + Creates a Pegasus graph modified to allow for periodic boundary conditions + and translational invariance. Parameters ---------- @@ -1263,7 +1269,7 @@ def pegasus_torus(m, node_list=None, edge_list=None, Examples ======== - >>> G = dnx.pegasus_torus(4) # a 3x3 tile pegasus torus (connectivity 15) + >>> G = dwave.graphs.pegasus_torus(4) # a 3x3 tile pegasus torus (connectivity 15) >>> len(G) # 3*3*24 216 >>> any([len(list(G.neighbors(n))) != 15 for n in G.nodes]) @@ -1321,8 +1327,8 @@ def pegasus_four_color(q): A mapping of every qubit (default integer labels) in the Pegasus[m] graph to one of 4 colors >>> m = 2 - >>> G = dnx.pegasus_graph(m, coordinates=True) - >>> colors = {q: dnx.pegasus_four_color(q) for q in G.nodes()} + >>> G = dwave.graphs.pegasus_graph(m, coordinates=True) + >>> colors = {q: dwave.graphs.pegasus_four_color(q) for q in G.nodes()} """ u, w, k, z = q return 2 * u + ((k ^ z) & 1) diff --git a/dwave_networkx/generators/zephyr.py b/dwave/graphs/generators/zephyr.py similarity index 96% rename from dwave_networkx/generators/zephyr.py rename to dwave/graphs/generators/zephyr.py index bfd5a78d..43708844 100644 --- a/dwave_networkx/generators/zephyr.py +++ b/dwave/graphs/generators/zephyr.py @@ -15,14 +15,10 @@ """ Generators for some graphs derived from the D-Wave System. """ -import re -import warnings from itertools import product import networkx as nx -from dwave_networkx.exceptions import DWaveNetworkXException - from .chimera import _chimera_coordinates_cache from .common import _add_compatible_edges, _add_compatible_nodes, _add_compatible_terms @@ -152,7 +148,7 @@ def zephyr_graph(m, t=4, create_using=None, node_list=None, edge_list=None, Examples -------- - >>> G = dnx.zephyr_graph(2) + >>> G = dwave.graphs.zephyr_graph(2) >>> G.nodes(data=True)[(0, 0, 0, 0, 0)] # doctest: +SKIP {'linear_index': 0} @@ -285,7 +281,7 @@ def zephyr_to_linear(self, q): Examples -------- - >>> dnx.zephyr_coordinates(2).zephyr_to_linear((0, 1, 2, 1, 0)) + >>> dwave.graphs.zephyr_coordinates(2).zephyr_to_linear((0, 1, 2, 1, 0)) 26 """ u, w, k, j, z = q @@ -302,7 +298,7 @@ def linear_to_zephyr(self, r): Examples -------- - >>> dnx.zephyr_coordinates(2).linear_to_zephyr(137) + >>> dwave.graphs.zephyr_coordinates(2).linear_to_zephyr(137) (1, 3, 2, 0, 1) """ @@ -372,7 +368,8 @@ def graph_to_linear(self, g): edges = self.iter_zephyr_to_linear_pairs(g.edges) else: raise ValueError( - f"Node labeling {labels} not recognized. Input must be generated by dwave_networkx.zephyr_graph." + f"Node labeling {labels} not recognized. " + "Input must be generated by dwave.graphs.zephyr_graph." ) return zephyr_graph( @@ -404,7 +401,8 @@ def graph_to_zephyr(self, g): return g.copy() else: raise ValueError( - f"Node labeling {labels} not recognized. Input must be generated by dwave_networkx.zephyr_graph." + f"Node labeling {labels} not recognized. " + "Input must be generated by dwave.graphs.zephyr_graph." ) return zephyr_graph( @@ -646,7 +644,7 @@ def zephyr_sublattice_mappings(source, target, offset_list=None): this function does not handle that complex task. """ if target.graph.get('family') != 'zephyr': - raise ValueError("Source graph must be a Zephyr graph constructed by dwave_networkx.zephyr_graph") + raise ValueError("Source graph must be a Zephyr graph constructed by dwave.graphs.zephyr_graph") m_t = target.graph['rows'] t = target.graph['tile'] @@ -680,7 +678,9 @@ def zephyr_to_target(q): nrange = range(m_t - n_s + 1) offset_list = product([t], mrange, nrange, jrange, jrange) else: - raise ValueError(f"Cannot construct sublattice mappings from Chimera to this Zephyr graph unless the tile parameter of the chimera graph is {t} or {2*t}.") + raise ValueError("Cannot construct sublattice mappings from Chimera " + "to this Zephyr graph unless the tile parameter of " + f"the chimera graph is {t} or {2*t}.") if labels_s == 'coordinate': def source_to_inner(q): @@ -708,7 +708,9 @@ def source_to_inner(q): make_mapping = _zephyr_zephyr_sublattice_mapping else: - raise ValueError("source graph must be a Chimera graph or Zephyr graph constructed by dwave_networkx.chimera_graph or dwave_networkx.zephyr_graph respectively") + raise ValueError("source graph must be a Chimera graph or Zephyr graph " + "constructed by dwave.graphs.chimera_graph or " + "dwave.graphs.zephyr_graph respectively") for offset in offset_list: yield make_mapping(source_to_inner, zephyr_to_target, offset) @@ -759,7 +761,7 @@ def zephyr_torus(m, t=4, node_list=None, edge_list=None): Examples -------- - >>> G = dnx.zephyr_torus(3) # a 3x3 tile pegasus torus (connectivity 15) + >>> G = dwave.graphs.zephyr_torus(3) # a 3x3 tile pegasus torus (connectivity 15) >>> len(G) # 3*3*24 288 >>> any([len(list(G.neighbors(n))) != 20 for n in G.nodes]) @@ -817,8 +819,8 @@ def zephyr_four_color(q, scheme=0): A mapping of every qubit (default integer labels) in the Zephyr[m, t] graph to one of 4 colors >>> m = 2 - >>> G = dnx.zephyr_graph(m, coordinates=True) - >>> colors = {q: dnx.zephyr_four_color(q) for q in G.nodes()} + >>> G = dwave.graphs.zephyr_graph(m, coordinates=True) + >>> colors = {q: dwave.graphs.zephyr_four_color(q) for q in G.nodes()} """ u, w, _, j, z = q diff --git a/dwave_networkx/package_info.py b/dwave/graphs/package_info.py similarity index 78% rename from dwave_networkx/package_info.py rename to dwave/graphs/package_info.py index 6941b8c3..c908476a 100644 --- a/dwave_networkx/package_info.py +++ b/dwave/graphs/package_info.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.8.18' -__author__ = 'D-Wave Systems Inc.' +__version__ = '1.0.0.dev' +__author__ = 'D-Wave Inc.' __authoremail__ = 'tools@dwavesys.com' -__description__ = 'A NetworkX extension providing graphs and algorithms relevant to working with the D-Wave System' +__description__ = 'A package providing graphs and algorithms relevant to working with the D-Wave System' diff --git a/dwave_networkx/utils/__init__.py b/dwave/graphs/utils/__init__.py similarity index 80% rename from dwave_networkx/utils/__init__.py rename to dwave/graphs/utils/__init__.py index 4679f8c7..bc392bad 100644 --- a/dwave_networkx/utils/__init__.py +++ b/dwave/graphs/utils/__init__.py @@ -11,6 +11,5 @@ # 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 dwave_networkx.utils.decorators import * + +from dwave.graphs.utils.decorators import * diff --git a/dwave_networkx/utils/decorators.py b/dwave/graphs/utils/decorators.py similarity index 93% rename from dwave_networkx/utils/decorators.py rename to dwave/graphs/utils/decorators.py index 48e65450..f973d110 100644 --- a/dwave_networkx/utils/decorators.py +++ b/dwave/graphs/utils/decorators.py @@ -20,7 +20,7 @@ import functools import inspect -import dwave_networkx as dnx +import dwave.graphs __all__ = ['binary_quadratic_model_sampler'] @@ -59,9 +59,9 @@ def func(*args, **kwargs): # been set if sampler is None: # this sampler has already been vetted - default_sampler = dnx.get_default_sampler() + default_sampler = dwave.graphs.get_default_sampler() if default_sampler is None: - raise dnx.DWaveNetworkXMissingSampler('no default sampler set') + raise dwave.graphs.DWaveNetworkXMissingSampler('no default sampler set') new_args[idx] = default_sampler continue diff --git a/dwave_networkx/algorithms/__init__.py b/dwave_networkx/algorithms/__init__.py deleted file mode 100644 index d588b247..00000000 --- a/dwave_networkx/algorithms/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2018 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 dwave_networkx.algorithms.independent_set import * -from dwave_networkx.algorithms.canonicalization import * -from dwave_networkx.algorithms.clique import * -from dwave_networkx.algorithms.cover import * -from dwave_networkx.algorithms.matching import * -from dwave_networkx.algorithms.social import * -from dwave_networkx.algorithms.elimination_ordering import * -from dwave_networkx.algorithms.coloring import * -from dwave_networkx.algorithms.max_cut import * -from dwave_networkx.algorithms.markov import * -from dwave_networkx.algorithms.tsp import * -from dwave_networkx.algorithms.partition import * diff --git a/setup.py b/setup.py index c7f00e77..60f471e6 100644 --- a/setup.py +++ b/setup.py @@ -20,18 +20,19 @@ my_loc = os.path.dirname(os.path.abspath(__file__)) os.chdir(my_loc) -exec(open(os.path.join(".", "dwave_networkx", "package_info.py")).read()) +exec(open(os.path.join(".", "dwave", "graphs", "package_info.py")).read()) -packages = ['dwave_networkx', - 'dwave_networkx.algorithms', - 'dwave_networkx.utils', - 'dwave_networkx.drawing', - 'dwave_networkx.generators', +packages = ['dwave.graphs', + 'dwave.graphs.algorithms', + 'dwave.graphs.drawing', + 'dwave.graphs.generators', + 'dwave.graphs.utils', ] install_requires = ['networkx>=2.4', 'dimod>=0.12.5', - 'numpy>=1.17.3', + # TODO: remove !=2.4.0 after we implement `dwave-samplers#82` + 'numpy>=1.21.3,!=2.4.0', # oldest that supports python 3.10 ] python_requires = ">=3.10" @@ -48,14 +49,14 @@ ] setup( - name='dwave_networkx', + name='dwave-graphs', version=__version__, author=__author__, author_email=__authoremail__, description=__description__, long_description=open('README.rst').read(), - url='https://github.com/dwavesystems/dwave_networkx', - download_url='https://github.com/dwavesystems/dwave_networkx/releases', + url='https://github.com/dwavesystems/dwave-graphs', + download_url='https://github.com/dwavesystems/dwave-graphs/releases', packages=packages, license='Apache 2.0', install_requires=install_requires, diff --git a/tests/requirements.txt b/tests/requirements.txt index 28ad9b35..c74701d3 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,2 +1,6 @@ coverage parameterized==0.7.4 + +# optional dependencies required for some tests +matplotlib==3.7.5; python_version=='3.10' # allow for numpy<1.23 (oldest-supported-numpy) +matplotlib==3.10.8; python_version>='3.11' diff --git a/tests/test_canonicalization.py b/tests/test_canonicalization.py index 699cf1dc..b50754c4 100644 --- a/tests/test_canonicalization.py +++ b/tests/test_canonicalization.py @@ -13,10 +13,9 @@ # limitations under the License. import unittest -import collections import dimod -import dwave_networkx as dnx +import dwave.graphs as dnx import networkx as nx diff --git a/tests/test_chimera_layout.py b/tests/test_chimera_layout.py index ef5544cd..0289edbc 100644 --- a/tests/test_chimera_layout.py +++ b/tests/test_chimera_layout.py @@ -16,7 +16,7 @@ import unittest import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx try: import matplotlib.pyplot as plt diff --git a/tests/test_clique.py b/tests/test_clique.py index 70e84189..3de553e8 100644 --- a/tests/test_clique.py +++ b/tests/test_clique.py @@ -15,7 +15,7 @@ import unittest import networkx as nx import dimod -import dwave_networkx as dnx +import dwave.graphs as dnx class TestIsClique(unittest.TestCase): diff --git a/tests/test_coloring.py b/tests/test_coloring.py index 74d353eb..ec64d1f6 100644 --- a/tests/test_coloring.py +++ b/tests/test_coloring.py @@ -13,13 +13,12 @@ # limitations under the License. import unittest -import itertools import networkx as nx import dimod -import dwave_networkx as dnx +import dwave.graphs as dnx class TestMinVertexColor(unittest.TestCase): diff --git a/tests/test_cover.py b/tests/test_cover.py index 26484476..9986ddda 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -16,7 +16,7 @@ import random import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx from dimod import ExactSolver, SimulatedAnnealingSampler diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 81e771a2..e12a812e 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -14,8 +14,8 @@ import unittest -import dwave_networkx as dnx -from dwave_networkx.utils import binary_quadratic_model_sampler +import dwave.graphs as dnx +from dwave.graphs.utils import binary_quadratic_model_sampler class MockSampler: diff --git a/tests/test_elimination_ordering.py b/tests/test_elimination_ordering.py index dd243574..8760f4c4 100644 --- a/tests/test_elimination_ordering.py +++ b/tests/test_elimination_ordering.py @@ -15,7 +15,7 @@ import unittest import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx class HeuristicCases: diff --git a/tests/test_generator_chimera.py b/tests/test_generator_chimera.py index 4317ba7c..dcddd1c5 100644 --- a/tests/test_generator_chimera.py +++ b/tests/test_generator_chimera.py @@ -15,7 +15,7 @@ import unittest import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx import numpy as np alpha_map = dict(enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')) @@ -132,7 +132,7 @@ def _check_matching_chimera_indices(self, G, chimera_indices): self.assertEqual(dat['chimera_index'], chimera_indices[v]) def test_coordinate_basics(self): - from dwave_networkx.generators.chimera import chimera_coordinates + from dwave.graphs.generators.chimera import chimera_coordinates G = dnx.chimera_graph(4) H = dnx.chimera_graph(4, coordinates=True) coords = chimera_coordinates(4) @@ -152,7 +152,7 @@ def test_coordinate_basics(self): self.assertEqual(q, coords.linear_to_chimera(v)) def test_coordinate_subgraphs(self): - from dwave_networkx.generators.chimera import chimera_coordinates + from dwave.graphs.generators.chimera import chimera_coordinates from random import sample G = dnx.chimera_graph(4) H = dnx.chimera_graph(4, coordinates=True) diff --git a/tests/test_generator_markov.py b/tests/test_generator_markov.py index de618175..970d515b 100644 --- a/tests/test_generator_markov.py +++ b/tests/test_generator_markov.py @@ -14,7 +14,7 @@ import unittest -import dwave_networkx as dnx +import dwave.graphs as dnx class Test_markov_network(unittest.TestCase): diff --git a/tests/test_generator_pegasus.py b/tests/test_generator_pegasus.py index 698d2df5..9cad33bb 100644 --- a/tests/test_generator_pegasus.py +++ b/tests/test_generator_pegasus.py @@ -18,10 +18,10 @@ from random import sample import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx import numpy as np -from dwave_networkx.generators.pegasus import ( +from dwave.graphs.generators.pegasus import ( fragmented_edges, get_tuple_defragmentation_fn, get_tuple_fragmentation_fn, diff --git a/tests/test_generator_zephyr.py b/tests/test_generator_zephyr.py index 246f453f..9078cd5a 100644 --- a/tests/test_generator_zephyr.py +++ b/tests/test_generator_zephyr.py @@ -15,7 +15,7 @@ import unittest import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx import numpy as np class TestZephyrGraph(unittest.TestCase): @@ -65,7 +65,7 @@ def test_float_robustness(self): self.assertIn(u, G[v]) def test_coordinate_basics(self): - from dwave_networkx.generators.zephyr import zephyr_coordinates + from dwave.graphs.generators.zephyr import zephyr_coordinates G = dnx.zephyr_graph(4) H = dnx.zephyr_graph(4, coordinates=True) coords = zephyr_coordinates(4) @@ -85,7 +85,7 @@ def test_coordinate_basics(self): self.assertEqual(q, coords.linear_to_zephyr(v)) def test_coordinate_subgraphs(self): - from dwave_networkx.generators.zephyr import zephyr_coordinates + from dwave.graphs.generators.zephyr import zephyr_coordinates from random import sample G = dnx.zephyr_graph(4) H = dnx.zephyr_graph(4, coordinates=True) diff --git a/tests/test_independent_set.py b/tests/test_independent_set.py index 9c64674b..1d05bcfc 100644 --- a/tests/test_independent_set.py +++ b/tests/test_independent_set.py @@ -16,7 +16,7 @@ import networkx as nx import dimod -import dwave_networkx as dnx +import dwave.graphs as dnx class TestIsIndependentSet(unittest.TestCase): diff --git a/tests/test_markov.py b/tests/test_markov.py index b27c9de2..fbfd87b0 100644 --- a/tests/test_markov.py +++ b/tests/test_markov.py @@ -15,7 +15,7 @@ import unittest import dimod -import dwave_networkx as dnx +import dwave.graphs as dnx class Test_sample_markov_network_bqm(unittest.TestCase): diff --git a/tests/test_matching.py b/tests/test_matching.py index b34fb068..d9cb5af7 100644 --- a/tests/test_matching.py +++ b/tests/test_matching.py @@ -18,7 +18,7 @@ import networkx as nx import parameterized -import dwave_networkx as dnx +import dwave.graphs as dnx @parameterized.parameterized_class( diff --git a/tests/test_max_cut.py b/tests/test_max_cut.py index f400af15..5cff3a32 100644 --- a/tests/test_max_cut.py +++ b/tests/test_max_cut.py @@ -15,7 +15,7 @@ import unittest import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx from dimod import ExactSolver, SimulatedAnnealingSampler, qubo_energy diff --git a/tests/test_parallel_embeddings.py b/tests/test_parallel_embeddings.py index 4874ebaa..19fef6ec 100644 --- a/tests/test_parallel_embeddings.py +++ b/tests/test_parallel_embeddings.py @@ -17,12 +17,12 @@ import networkx as nx -from dwave_networkx.drawing.parallel_embeddings import ( +from dwave.graphs.drawing.parallel_embeddings import ( _generate_edge_color_dict, _generate_node_color_dict, draw_parallel_embeddings, ) -from dwave_networkx import chimera_graph +from dwave.graphs import chimera_graph try: import matplotlib diff --git a/tests/test_partitioning.py b/tests/test_partitioning.py index ea03c144..b2636bb2 100644 --- a/tests/test_partitioning.py +++ b/tests/test_partitioning.py @@ -15,7 +15,7 @@ import unittest import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx from dimod import ExactCQMSolver diff --git a/tests/test_pegasus_layout.py b/tests/test_pegasus_layout.py index e536bf7c..c5b27a27 100644 --- a/tests/test_pegasus_layout.py +++ b/tests/test_pegasus_layout.py @@ -16,7 +16,7 @@ import unittest import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx try: import matplotlib.pyplot as plt diff --git a/tests/test_qubit_layout.py b/tests/test_qubit_layout.py index 25be0bcd..09934a95 100644 --- a/tests/test_qubit_layout.py +++ b/tests/test_qubit_layout.py @@ -15,7 +15,7 @@ import os import unittest -import dwave_networkx as dnx +import dwave.graphs as dnx try: import matplotlib.pyplot as plt diff --git a/tests/test_regular_coloring.py b/tests/test_regular_coloring.py index fbac4962..a8076d01 100644 --- a/tests/test_regular_coloring.py +++ b/tests/test_regular_coloring.py @@ -16,7 +16,7 @@ import numpy as np -import dwave_networkx as dnx +import dwave.graphs as dnx class TestRegularColoring(unittest.TestCase): diff --git a/tests/test_social.py b/tests/test_social.py index a092851d..fbe5b176 100644 --- a/tests/test_social.py +++ b/tests/test_social.py @@ -16,7 +16,7 @@ import itertools import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx from dimod import ExactSolver, SimulatedAnnealingSampler diff --git a/tests/test_tsp.py b/tests/test_tsp.py index 117dc7dc..dc4edcba 100644 --- a/tests/test_tsp.py +++ b/tests/test_tsp.py @@ -19,7 +19,7 @@ import dimod -import dwave_networkx as dnx +import dwave.graphs as dnx # adapted from future networkx version (nx.path_weight(...)) diff --git a/tests/test_zephyr_layout.py b/tests/test_zephyr_layout.py index f5e8f4c9..3a74df5b 100644 --- a/tests/test_zephyr_layout.py +++ b/tests/test_zephyr_layout.py @@ -16,7 +16,7 @@ import unittest import networkx as nx -import dwave_networkx as dnx +import dwave.graphs as dnx try: import matplotlib.pyplot as plt