diff --git a/.coveragerc b/.coveragerc index a8fd2ff1..1de9d189 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,5 @@ [run] -# omit virtualenv and test files -omit = venv/*, */tests/* -source=dwave_networkx +source=dwave_networkx, dwave/plugins/networkx [report] exclude_lines: diff --git a/README.rst b/README.rst index b5b1c0bc..ee7ff622 100644 --- a/README.rst +++ b/README.rst @@ -28,7 +28,7 @@ bipartite architecture). .. code: python ->>> import dwave_networkx as dnx +>>> import dwave.plugins.networkx as dnx >>> graph = dnx.chimera_graph(1, 1, 4) See the documentation for more examples. @@ -44,7 +44,7 @@ Installation .. code-block:: bash - pip install dwave_networkx + pip install dwave-networkx **Installation from source:** diff --git a/docs/conf.py b/docs/conf.py index f54c30a3..1bcf38dd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -62,11 +62,11 @@ # |version| and |release|, also used in various other places throughout the # built documents. # -import dwave_networkx +import dwave.plugins.networkx # The short X.Y version. -version = dwave_networkx.__version__ +version = dwave.plugins.networkx.__version__ # The full version, including alpha/beta/rc tags. -release = dwave_networkx.__version__ +release = dwave.plugins.networkx.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/intro.rst b/docs/intro.rst index 691ad81a..560db36d 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -28,7 +28,7 @@ Below you can see how to create Chimera graphs implemented in the D-Wave 2X and .. code:: python - import dwave_networkx as dnx + import dwave.plugins.networkx as dnx # D-Wave 2X C = dnx.chimera_graph(12, 12, 4) diff --git a/docs/reference/algorithms/canonicalization.rst b/docs/reference/algorithms/canonicalization.rst index cb4d2815..146b84af 100644 --- a/docs/reference/algorithms/canonicalization.rst +++ b/docs/reference/algorithms/canonicalization.rst @@ -2,9 +2,9 @@ Canonicalization **************** -.. automodule:: dwave_networkx.algorithms.canonicalization +.. automodule:: dwave.plugins.networkx.algorithms.canonicalization -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.plugins.networkx .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/clique.rst b/docs/reference/algorithms/clique.rst index 54a357f7..da5183e6 100644 --- a/docs/reference/algorithms/clique.rst +++ b/docs/reference/algorithms/clique.rst @@ -11,9 +11,9 @@ such 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.plugins.networkx.algorithms.clique -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.plugins.networkx .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/coloring.rst b/docs/reference/algorithms/coloring.rst index 199ecb51..3b244fbb 100644 --- a/docs/reference/algorithms/coloring.rst +++ b/docs/reference/algorithms/coloring.rst @@ -20,7 +20,7 @@ border (represented by an edge of the graph) have different colors. Coloring a map of Canada with four colors. -.. automodule:: dwave_networkx.algorithms.coloring +.. automodule:: dwave.plugins.networkx.algorithms.coloring .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/cover.rst b/docs/reference/algorithms/cover.rst index bd19f889..e865a49b 100644 --- a/docs/reference/algorithms/cover.rst +++ b/docs/reference/algorithms/cover.rst @@ -16,7 +16,7 @@ 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.plugins.networkx.algorithms.cover .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/elimination_ordering.rst b/docs/reference/algorithms/elimination_ordering.rst index 89641977..2f4ab907 100644 --- a/docs/reference/algorithms/elimination_ordering.rst +++ b/docs/reference/algorithms/elimination_ordering.rst @@ -14,7 +14,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.plugins.networkx.algorithms.elimination_ordering .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/index.rst b/docs/reference/algorithms/index.rst index 4fd57ec9..d6409531 100644 --- a/docs/reference/algorithms/index.rst +++ b/docs/reference/algorithms/index.rst @@ -7,7 +7,7 @@ Algorithms Implementations of graph-theory algorithms on the D-Wave system and other binary quadratic model samplers. -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.plugins.networkx .. toctree:: :maxdepth: 2 diff --git a/docs/reference/algorithms/markov.rst b/docs/reference/algorithms/markov.rst index 8831e709..9a715eaa 100644 --- a/docs/reference/algorithms/markov.rst +++ b/docs/reference/algorithms/markov.rst @@ -2,7 +2,7 @@ Markov Networks *************** -.. automodule:: dwave_networkx.algorithms.markov +.. automodule:: dwave.plugins.networkx.algorithms.markov .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/matching.rst b/docs/reference/algorithms/matching.rst index a57b8483..05e6357c 100644 --- a/docs/reference/algorithms/matching.rst +++ b/docs/reference/algorithms/matching.rst @@ -13,7 +13,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.plugins.networkx.algorithms.matching .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/max_cut.rst b/docs/reference/algorithms/max_cut.rst index 50644a59..ed2d7aab 100644 --- a/docs/reference/algorithms/max_cut.rst +++ b/docs/reference/algorithms/max_cut.rst @@ -15,7 +15,7 @@ between this subset and the remaining vertices is as large as possible. {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.plugins.networkx.algorithms.max_cut .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/packing.rst b/docs/reference/algorithms/packing.rst index 3800e680..63f0eab0 100644 --- a/docs/reference/algorithms/packing.rst +++ b/docs/reference/algorithms/packing.rst @@ -16,9 +16,9 @@ of 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.plugins.networkx.algorithms.independent_set -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.plugins.networkx .. autosummary:: :toctree: generated/ @@ -30,7 +30,7 @@ of its member pairs. Helper Functions ---------------- -.. currentmodule:: dwave_networkx.algorithms.independent_set +.. currentmodule:: dwave.plugins.networkx.algorithms.independent_set .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/social.rst b/docs/reference/algorithms/social.rst index 89ba0318..548d36a4 100644 --- a/docs/reference/algorithms/social.rst +++ b/docs/reference/algorithms/social.rst @@ -16,7 +16,7 @@ friendly/hostile interactions between vertices. be 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.plugins.networkx.algorithms.social .. autosummary:: :toctree: generated/ diff --git a/docs/reference/algorithms/tsp.rst b/docs/reference/algorithms/tsp.rst index 72c73576..26928d91 100644 --- a/docs/reference/algorithms/tsp.rst +++ b/docs/reference/algorithms/tsp.rst @@ -13,7 +13,7 @@ graph. A traveling salesperson route of [2, 1, 0, 3]. -.. automodule:: dwave_networkx.algorithms.tsp +.. automodule:: dwave.plugins.networkx.algorithms.tsp .. autosummary:: :toctree: generated/ diff --git a/docs/reference/default_sampler.rst b/docs/reference/default_sampler.rst index e5868d52..381aec86 100644 --- a/docs/reference/default_sampler.rst +++ b/docs/reference/default_sampler.rst @@ -3,9 +3,9 @@ Default sampler *************** -.. currentmodule:: dwave_networkx.default_sampler +.. currentmodule:: dwave.plugins.networkx.default_sampler -.. automodule:: dwave_networkx.default_sampler +.. automodule:: dwave.plugins.networkx.default_sampler Functions --------- diff --git a/docs/reference/drawing.rst b/docs/reference/drawing.rst index 9556ed02..b221e9e9 100644 --- a/docs/reference/drawing.rst +++ b/docs/reference/drawing.rst @@ -5,7 +5,7 @@ Drawing Tools to visualize topologies of D-Wave QPUs and weighted graph problems on them. -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.plugins.networkx .. note:: Some functionality requires `NumPy `_ and/or `Matplotlib `_\ . @@ -13,7 +13,7 @@ Tools to visualize topologies of D-Wave QPUs and weighted graph problems on them Chimera Graph Functions ----------------------- -.. automodule:: dwave_networkx.drawing.chimera_layout +.. automodule:: dwave.plugins.networkx.drawing.chimera_layout .. autosummary:: :toctree: generated/ @@ -32,7 +32,7 @@ positions on a Chimera unit cell. .. code-block:: python >>> import networkx as nx - >>> import dwave_networkx as dnx + >>> import dwave.plugins.networkx as dnx >>> import matplotlib.pyplot as plt >>> H = nx.Graph() >>> H.add_nodes_from([0, 4, 5, 6, 7]) @@ -63,7 +63,7 @@ positions on a Chimera unit cell. Pegasus Graph Functions ----------------------- -.. automodule:: dwave_networkx.drawing.pegasus_layout +.. automodule:: dwave.plugins.networkx.drawing.pegasus_layout .. autosummary:: :toctree: generated/ @@ -81,7 +81,7 @@ of nodes of a simple 5-node graph on a small Pegasus lattice. .. code-block:: python - >>> import dwave_networkx as dnx + >>> import dwave.plugins.networkx as dnx >>> import matplotlib.pyplot as plt >>> G = dnx.pegasus_graph(2) >>> H = dnx.pegasus_graph(2, node_list=[4, 40, 41, 42, 43], diff --git a/docs/reference/generators.rst b/docs/reference/generators.rst index 95318c6f..8ebe6d81 100644 --- a/docs/reference/generators.rst +++ b/docs/reference/generators.rst @@ -5,7 +5,7 @@ Graph Generators Generators for graphs, such the graphs (topologies) of D-Wave System QPUs. -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.plugins.networkx D-Wave Systems -------------- @@ -26,7 +26,7 @@ the `find_chimera()` function to determine the Chimera indices. .. code-block:: python >>> import networkx as nx - >>> import dwave_networkx as dnx + >>> import dwave.plugins.networkx as dnx >>> G = dnx.chimera_graph(1, 1, 4) >>> chimera_indices = dnx.find_chimera_indices(G) >>> print chimera_indices diff --git a/docs/reference/utilities.rst b/docs/reference/utilities.rst index 1f177908..f5ca0ee9 100644 --- a/docs/reference/utilities.rst +++ b/docs/reference/utilities.rst @@ -2,18 +2,18 @@ Utilities ********* -.. automodule:: dwave_networkx.utils -.. currentmodule:: dwave_networkx.utils +.. automodule:: dwave.plugins.networkx.utils +.. currentmodule:: dwave.plugins.networkx.utils Decorators ---------- -.. automodule:: dwave_networkx.utils.decorators +.. automodule:: dwave.plugins.networkx.utils.decorators .. autosummary:: :toctree: generated/ binary_quadratic_model_sampler -.. currentmodule:: dwave_networkx +.. currentmodule:: dwave.plugins.networkx .. toctree:: :hidden: @@ -53,7 +53,7 @@ Pegasus Exceptions ---------- -.. automodule:: dwave_networkx.exceptions +.. automodule:: dwave.plugins.networkx.exceptions .. autosummary:: :toctree: generated/ diff --git a/docs/reference/utilities/index.rst b/docs/reference/utilities/index.rst index c635a31b..d4f44e42 100644 --- a/docs/reference/utilities/index.rst +++ b/docs/reference/utilities/index.rst @@ -3,7 +3,7 @@ Coordinates Conversion ********************** -.. automodule:: dwave_networkx +.. automodule:: dwave.plugins.networkx .. autoclass:: chimera_coordinates diff --git a/dwave/__init__.py b/dwave/__init__.py new file mode 100644 index 00000000..31141c58 --- /dev/null +++ b/dwave/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2020 D-Wave Systems Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pkgutil +__path__ = pkgutil.extend_path(__path__, __name__) diff --git a/dwave/plugins/__init__.py b/dwave/plugins/__init__.py new file mode 100644 index 00000000..31141c58 --- /dev/null +++ b/dwave/plugins/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2020 D-Wave Systems Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pkgutil +__path__ = pkgutil.extend_path(__path__, __name__) diff --git a/dwave/plugins/networkx/__init__.py b/dwave/plugins/networkx/__init__.py new file mode 100644 index 00000000..0d009fb3 --- /dev/null +++ b/dwave/plugins/networkx/__init__.py @@ -0,0 +1,37 @@ +# 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. + +import dwave.plugins.networkx.generators +from dwave.plugins.networkx.generators import * + +import dwave.plugins.networkx.algorithms +from dwave.plugins.networkx.algorithms import * + +import dwave.plugins.networkx.utils + +import dwave.plugins.networkx.exceptions +from dwave.plugins.networkx.exceptions import * + +import dwave.plugins.networkx.default_sampler +from dwave.plugins.networkx.default_sampler import * + +import dwave.plugins.networkx.drawing +from dwave.plugins.networkx.drawing import * + +from dwave.plugins.networkx.package_info import ( + __version__, + __author__, + __authoremail__, + __description__, + ) diff --git a/dwave/plugins/networkx/algorithms/__init__.py b/dwave/plugins/networkx/algorithms/__init__.py new file mode 100644 index 00000000..72b393c8 --- /dev/null +++ b/dwave/plugins/networkx/algorithms/__init__.py @@ -0,0 +1,25 @@ +# 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.plugins.networkx.algorithms.independent_set import * +from dwave.plugins.networkx.algorithms.canonicalization import * +from dwave.plugins.networkx.algorithms.clique import * +from dwave.plugins.networkx.algorithms.cover import * +from dwave.plugins.networkx.algorithms.matching import * +from dwave.plugins.networkx.algorithms.social import * +from dwave.plugins.networkx.algorithms.elimination_ordering import * +from dwave.plugins.networkx.algorithms.coloring import * +from dwave.plugins.networkx.algorithms.max_cut import * +from dwave.plugins.networkx.algorithms.markov import * +from dwave.plugins.networkx.algorithms.tsp import * diff --git a/dwave_networkx/algorithms/canonicalization.py b/dwave/plugins/networkx/algorithms/canonicalization.py similarity index 98% rename from dwave_networkx/algorithms/canonicalization.py rename to dwave/plugins/networkx/algorithms/canonicalization.py index af4f90c0..f4ace843 100644 --- a/dwave_networkx/algorithms/canonicalization.py +++ b/dwave/plugins/networkx/algorithms/canonicalization.py @@ -14,7 +14,7 @@ import math -from dwave_networkx.generators.chimera import chimera_coordinates +from dwave.plugins.networkx.generators.chimera import chimera_coordinates __all__ = ['canonical_chimera_labeling'] diff --git a/dwave_networkx/algorithms/clique.py b/dwave/plugins/networkx/algorithms/clique.py similarity index 95% rename from dwave_networkx/algorithms/clique.py rename to dwave/plugins/networkx/algorithms/clique.py index 89600fb6..bc5fb75f 100644 --- a/dwave_networkx/algorithms/clique.py +++ b/dwave/plugins/networkx/algorithms/clique.py @@ -13,12 +13,14 @@ # limitations under the License. import networkx as nx -import dwave_networkx as dnx -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.plugins.networkx.algorithms.independent_set import maximum_independent_set +from dwave.plugins.networkx.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): """ @@ -87,7 +89,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) @@ -145,6 +147,7 @@ def clique_number(G, sampler=None, lagrange=2.0, **sampler_args): """ return len(maximum_clique(G, sampler, lagrange, **sampler_args)) + def is_clique(G, clique_nodes): """Determines whether the given nodes form a clique. @@ -172,7 +175,7 @@ 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 + >>> import dwave.plugins.networkx as dnx >>> G = dnx.chimera_graph(1, 1, 4) >>> dnx.is_clique(G, [0, 1, 2, 3]) False diff --git a/dwave_networkx/algorithms/coloring.py b/dwave/plugins/networkx/algorithms/coloring.py similarity index 99% rename from dwave_networkx/algorithms/coloring.py rename to dwave/plugins/networkx/algorithms/coloring.py index 8ccf6713..e8dd4ed5 100644 --- a/dwave_networkx/algorithms/coloring.py +++ b/dwave/plugins/networkx/algorithms/coloring.py @@ -17,7 +17,7 @@ import networkx as nx -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.plugins.networkx.utils import binary_quadratic_model_sampler __all__ = ["is_vertex_coloring", "is_cycle", diff --git a/dwave_networkx/algorithms/cover.py b/dwave/plugins/networkx/algorithms/cover.py similarity index 96% rename from dwave_networkx/algorithms/cover.py rename to dwave/plugins/networkx/algorithms/cover.py index 28888fb3..8ea15498 100644 --- a/dwave_networkx/algorithms/cover.py +++ b/dwave/plugins/networkx/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.plugins.networkx.algorithms.independent_set import maximum_weighted_independent_set +from dwave.plugins.networkx.utils import binary_quadratic_model_sampler __all__ = ['min_weighted_vertex_cover', 'min_vertex_cover', 'is_vertex_cover'] @@ -125,7 +125,7 @@ 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.plugins.networkx as dnx >>> import dimod >>> sampler = dimod.ExactSolver() # small testing sampler >>> G = dnx.chimera_graph(1, 1, 4) @@ -177,7 +177,7 @@ 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 + >>> import dwave.plugins.networkx as dnx >>> G = dnx.chimera_graph(1, 1, 4) >>> cover = [0, 1, 2, 3] >>> dnx.is_vertex_cover(G,cover) diff --git a/dwave_networkx/algorithms/elimination_ordering.py b/dwave/plugins/networkx/algorithms/elimination_ordering.py similarity index 99% rename from dwave_networkx/algorithms/elimination_ordering.py rename to dwave/plugins/networkx/algorithms/elimination_ordering.py index eff3d14a..e3bdaed2 100644 --- a/dwave_networkx/algorithms/elimination_ordering.py +++ b/dwave/plugins/networkx/algorithms/elimination_ordering.py @@ -18,7 +18,7 @@ import networkx as nx -from dwave_networkx.generators.pegasus import pegasus_coordinates +from dwave.plugins.networkx.generators.pegasus import pegasus_coordinates __all__ = ['is_almost_simplicial', 'is_simplicial', diff --git a/dwave_networkx/algorithms/independent_set.py b/dwave/plugins/networkx/algorithms/independent_set.py similarity index 97% rename from dwave_networkx/algorithms/independent_set.py rename to dwave/plugins/networkx/algorithms/independent_set.py index 241a690b..0f2dbbb3 100644 --- a/dwave_networkx/algorithms/independent_set.py +++ b/dwave/plugins/networkx/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.plugins.networkx.utils import binary_quadratic_model_sampler __all__ = ["maximum_weighted_independent_set", "maximum_weighted_independent_set_qubo", @@ -195,7 +195,7 @@ 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 + >>> import dwave.plugins.networkx as dnx >>> G = dnx.chimera_graph(1, 1, 4) >>> dnx.is_independent_set(G, [0, 1, 2, 3]) True @@ -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.plugins.networkx.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/plugins/networkx/algorithms/markov.py similarity index 98% rename from dwave_networkx/algorithms/markov.py rename to dwave/plugins/networkx/algorithms/markov.py index 3144cff3..910f43ff 100644 --- a/dwave_networkx/algorithms/markov.py +++ b/dwave/plugins/networkx/algorithms/markov.py @@ -14,7 +14,7 @@ import dimod -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.plugins.networkx.utils import binary_quadratic_model_sampler __all__ = ['sample_markov_network', 'markov_network_bqm'] diff --git a/dwave_networkx/algorithms/matching.py b/dwave/plugins/networkx/algorithms/matching.py similarity index 99% rename from dwave_networkx/algorithms/matching.py rename to dwave/plugins/networkx/algorithms/matching.py index 14237626..c188f54e 100644 --- a/dwave_networkx/algorithms/matching.py +++ b/dwave/plugins/networkx/algorithms/matching.py @@ -19,7 +19,7 @@ import dimod import networkx as nx -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.plugins.networkx.utils import binary_quadratic_model_sampler __all__ = ['is_matching', 'is_maximal_matching', diff --git a/dwave_networkx/algorithms/max_cut.py b/dwave/plugins/networkx/algorithms/max_cut.py similarity index 97% rename from dwave_networkx/algorithms/max_cut.py rename to dwave/plugins/networkx/algorithms/max_cut.py index 39baa096..7f4173ac 100644 --- a/dwave_networkx/algorithms/max_cut.py +++ b/dwave/plugins/networkx/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.plugins.networkx.exceptions import DWaveNetworkXException +from dwave.plugins.networkx.utils import binary_quadratic_model_sampler __all__ = ["maximum_cut", "weighted_maximum_cut"] diff --git a/dwave_networkx/algorithms/social.py b/dwave/plugins/networkx/algorithms/social.py similarity index 97% rename from dwave_networkx/algorithms/social.py rename to dwave/plugins/networkx/algorithms/social.py index 91fd4834..7263b6f5 100644 --- a/dwave_networkx/algorithms/social.py +++ b/dwave/plugins/networkx/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.plugins.networkx.utils import binary_quadratic_model_sampler __all__ = ["structural_imbalance"] @@ -159,7 +159,7 @@ def structural_imbalance_ising(S): Examples -------- >>> import dimod - >>> from dwave_networkx.algorithms.social import structural_imbalance_ising + >>> from dwave.plugins.networkx.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/plugins/networkx/algorithms/tsp.py similarity index 99% rename from dwave_networkx/algorithms/tsp.py rename to dwave/plugins/networkx/algorithms/tsp.py index d4d086e6..7aefb1a6 100644 --- a/dwave_networkx/algorithms/tsp.py +++ b/dwave/plugins/networkx/algorithms/tsp.py @@ -16,7 +16,7 @@ from collections import defaultdict -from dwave_networkx.utils import binary_quadratic_model_sampler +from dwave.plugins.networkx.utils import binary_quadratic_model_sampler __all__ = ["traveling_salesperson", "traveling_salesperson_qubo", diff --git a/dwave_networkx/utils/decorators.py b/dwave/plugins/networkx/default_sampler.py similarity index 56% rename from dwave_networkx/utils/decorators.py rename to dwave/plugins/networkx/default_sampler.py index 4aba854c..14af6555 100644 --- a/dwave_networkx/utils/decorators.py +++ b/dwave/plugins/networkx/default_sampler.py @@ -12,16 +12,66 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -Decorators allow for input checking and default parameter setting for -algorithms. -""" +"""Sets a binary quadratic model sampler used by default +for functions that require a sample when none is specified. + +A sampler is a process that samples +from low-energy states in models defined by an Ising equation +or a Quadratic Unconstrained Binary Optimization Problem +(QUBO). + +Sampler API +----------- +* Required Methods: 'sample_qubo' and 'sample_ising' +* Return value: iterable of samples, in order of increasing energy + +See `dimod `_ for details. +Example +------- +This example creates and uses a placeholder for binary quadratic model +samplers that returns a correct response only in the case of finding an +independent set on a complete graph (where one node is always an +independent set). The placeholder sampler can be used to test the simple +examples of the functions for configuring a default sampler. + +>>> # Create a placeholder sampler +>>> class ExampleSampler: +... # an example sampler, only works for independent set on complete +... # graphs +... def __init__(self, name): +... self.name = name +... def sample_ising(self, h, J): +... sample = {v: -1 for v in h} +... sample[0] = 1 # set one node to true +... return [sample] +... def sample_qubo(self, Q): +... sample = {v: 0 for v in set().union(*Q)} +... sample[0] = 1 # set one node to true +... return [sample] +... def __str__(self): +... return self.name +... +>>> # Identify the new sampler as the default sampler +>>> sampler0 = ExampleSampler('sampler0') +>>> dnx.set_default_sampler(sampler0) +>>> # Find an independent set using the default sampler +>>> G = nx.complete_graph(5) +>>> dnx.maximum_independent_set(G) +[0] + +""" from decorator import decorator -import dwave_networkx as dnx +from dwave.plugins.networkx.exceptions import DWaveNetworkXMissingSampler + +__all__ = ['set_default_sampler', + 'get_default_sampler', + 'unset_default_sampler', + ] -__all__ = ['binary_quadratic_model_sampler'] + +_SAMPLER = None def binary_quadratic_model_sampler(which_args): @@ -57,8 +107,8 @@ def maximal_matching(G, sampler, **sampler_args): missing a method. >>> import networkx as nx - >>> import dwave_networkx as dnx - >>> from dwave_networkx.utils import decorators + >>> import dwave.plugins.networkx as dnx + >>> from dwave.plugins.networkx.utils import decorators >>> # Create two placeholder samplers >>> class WellDefinedSampler: ... # an example sampler, only works for independent set on complete @@ -108,7 +158,7 @@ def maximal_matching(G, sampler, **sampler_args): in () ----> 1 independent_set(G, IllDefinedSampler) in independent_set(G, sampler, **sampler_args) - /usr/local/lib/python2.7/dist-packages/dwave_networkx/utils/decorators.pyc in _binary_quadratic_model_sampler(f, *args, **kw) + /usr/local/lib/python2.7/dist-packages/dwave.plugins.networkx/utils/decorators.pyc in _binary_quadratic_model_sampler(f, *args, **kw) 61 62 if not hasattr(sampler, "sample_qubo") or not callable(sampler.sample_qubo): ---> 63 raise TypeError("expected sampler to have a 'sample_qubo' method") @@ -134,9 +184,9 @@ def _binary_quadratic_model_sampler(f, *args, **kw): # been set if sampler is None: # this sampler has already been vetted - default_sampler = dnx.get_default_sampler() + default_sampler = get_default_sampler() if default_sampler is None: - raise dnx.DWaveNetworkXMissingSampler('no default sampler set') + raise DWaveNetworkXMissingSampler('no default sampler set') new_args[idx] = default_sampler continue @@ -148,3 +198,69 @@ def _binary_quadratic_model_sampler(f, *args, **kw): # now run the function and return the results return f(*new_args, **kw) return _binary_quadratic_model_sampler + + +@binary_quadratic_model_sampler(0) +def set_default_sampler(sampler): + """Sets a default binary quadratic model sampler. + + Parameters + ---------- + sampler + A binary quadratic model sampler. A sampler is a process that + samples from low-energy states in models defined by an Ising + equation or a Quadratic Unconstrained Binary Optimization + Problem (QUBO). A sampler is expected to have a 'sample_qubo' + and 'sample_ising' method. A sampler is expected to return an + iterable of samples, in order of increasing energy. + + Examples + -------- + This example sets sampler0 as the default sampler and finds an independent + 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 + + """ + global _SAMPLER + _SAMPLER = sampler + + +def unset_default_sampler(): + """Resets the default sampler back to None. + + Examples + -------- + 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 + 'sampler0' + >>> dnx.unset_default_sampler() # doctest: +SKIP + >>> print(dnx.get_default_sampler()) # doctest: +SKIP + None + """ + global _SAMPLER + _SAMPLER = None + + +def get_default_sampler(): + """Queries the current default sampler. + + Examples + -------- + This example queries the default sampler before and after specifying + a default sampler. + + >>> print(dnx.get_default_sampler()) # doctest: +SKIP + None + >>> dnx.set_default_sampler(sampler) # doctest: +SKIP + >>> print(dnx.get_default_sampler()) # doctest: +SKIP + 'sampler' + + """ + return _SAMPLER diff --git a/dwave_networkx/utils/__init__.py b/dwave/plugins/networkx/drawing/__init__.py similarity index 80% rename from dwave_networkx/utils/__init__.py rename to dwave/plugins/networkx/drawing/__init__.py index 4679f8c7..e236bf07 100644 --- a/dwave_networkx/utils/__init__.py +++ b/dwave/plugins/networkx/drawing/__init__.py @@ -11,6 +11,6 @@ # 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.plugins.networkx.drawing.chimera_layout import * +from dwave.plugins.networkx.drawing.pegasus_layout import * diff --git a/dwave_networkx/drawing/chimera_layout.py b/dwave/plugins/networkx/drawing/chimera_layout.py similarity index 97% rename from dwave_networkx/drawing/chimera_layout.py rename to dwave/plugins/networkx/drawing/chimera_layout.py index 486a2033..0526033d 100644 --- a/dwave_networkx/drawing/chimera_layout.py +++ b/dwave/plugins/networkx/drawing/chimera_layout.py @@ -20,8 +20,8 @@ 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.plugins.networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield +from dwave.plugins.networkx.generators.chimera import chimera_graph, find_chimera_indices, chimera_coordinates __all__ = ['chimera_layout', 'draw_chimera', 'draw_chimera_embedding', 'draw_chimera_yield'] @@ -219,7 +219,7 @@ def draw_chimera(G, **kwargs): -------- >>> # Plot 2x2 Chimera unit cells >>> import networkx as nx - >>> import dwave_networkx as dnx + >>> import dwave.plugins.networkx as dnx >>> import matplotlib.pyplot as plt # doctest: +SKIP >>> G = dnx.chimera_graph(2, 2, 4) >>> dnx.draw_chimera(G) # doctest: +SKIP diff --git a/dwave_networkx/drawing/distinguishable_colors.py b/dwave/plugins/networkx/drawing/distinguishable_colors.py similarity index 100% rename from dwave_networkx/drawing/distinguishable_colors.py rename to dwave/plugins/networkx/drawing/distinguishable_colors.py diff --git a/dwave_networkx/drawing/pegasus_layout.py b/dwave/plugins/networkx/drawing/pegasus_layout.py similarity index 94% rename from dwave_networkx/drawing/pegasus_layout.py rename to dwave/plugins/networkx/drawing/pegasus_layout.py index 2e8425b1..6bdb08c7 100644 --- a/dwave_networkx/drawing/pegasus_layout.py +++ b/dwave/plugins/networkx/drawing/pegasus_layout.py @@ -19,9 +19,9 @@ 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.pegasus import pegasus_graph, pegasus_coordinates -from dwave_networkx.drawing.chimera_layout import chimera_node_placer_2d +from dwave.plugins.networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield +from dwave.plugins.networkx.generators.pegasus import pegasus_graph, pegasus_coordinates +from dwave.plugins.networkx.drawing.chimera_layout import chimera_node_placer_2d __all__ = ['pegasus_layout', @@ -40,7 +40,7 @@ def pegasus_layout(G, scale=1., center=None, dim=2, crosses=False): ---------- G : NetworkX graph A Pegasus graph or a subgraph of a Pegasus graph, as produced by - the :func:`dwave_networkx.pegasus_graph` function. + the :func:`dwave.plugins.networkx.pegasus_graph` function. scale : float (default 1.) Scale factor. A setting of ``scale = 1`` fits all positions within @@ -73,7 +73,7 @@ def pegasus_layout(G, scale=1., center=None, dim=2, crosses=False): """ 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.plugins.networkx.pegasus_graph") if G.graph.get('labels') == 'nice': m = 3*(G.graph['rows']-1) @@ -102,7 +102,7 @@ def pegasus_node_placer_2d(G, scale=1., center=None, dim=2, crosses=False): ---------- G : NetworkX graph A Pegasus graph or a subgraph of a Pegasus graph, as produced by - the :func:`dwave_networkx.pegasus_graph` function. + the :func:`dwave.plugins.networkx.pegasus_graph` function. scale : float (default 1.) Scale factor. A setting of ``scale = 1`` fits all positions within @@ -184,7 +184,7 @@ def draw_pegasus(G, crosses=False, **kwargs): ---------- G : NetworkX graph A Pegasus graph or a subgraph of a Pegasus graph, as produced by - the :func:`dwave_networkx.pegasus_graph` function. + the :func:`dwave.plugins.networkx.pegasus_graph` function. linear_biases : dict (optional, default {}) Biases as a dict, of form {node: bias, ...}, where keys are @@ -211,7 +211,7 @@ 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.plugins.networkx as dnx >>> import matplotlib.pyplot as plt # doctest: +SKIP >>> G = dnx.pegasus_graph(2) >>> dnx.draw_pegasus(G) # doctest: +SKIP @@ -229,7 +229,7 @@ def draw_pegasus_embedding(G, *args, **kwargs): ---------- G : NetworkX graph A Pegasus graph or a subgraph of a Pegasus graph, as produced by - the :func:`dwave_networkx.pegasus_graph` function. + the :func:`dwave.plugins.networkx.pegasus_graph` function. emb : dict Chains, as a dict of form {qubit: chain, ...}, where qubits are diff --git a/dwave_networkx/drawing/qubit_layout.py b/dwave/plugins/networkx/drawing/qubit_layout.py similarity index 99% rename from dwave_networkx/drawing/qubit_layout.py rename to dwave/plugins/networkx/drawing/qubit_layout.py index e8115e9a..cd77aac9 100644 --- a/dwave_networkx/drawing/qubit_layout.py +++ b/dwave/plugins/networkx/drawing/qubit_layout.py @@ -22,7 +22,7 @@ from networkx import draw -from dwave_networkx.drawing.distinguishable_colors import distinguishable_color_map +from dwave.plugins.networkx.drawing.distinguishable_colors import distinguishable_color_map __all__ = ['draw_qubit_graph'] diff --git a/dwave_networkx/exceptions.py b/dwave/plugins/networkx/exceptions.py similarity index 91% rename from dwave_networkx/exceptions.py rename to dwave/plugins/networkx/exceptions.py index 7678d3f4..bf57ec07 100644 --- a/dwave_networkx/exceptions.py +++ b/dwave/plugins/networkx/exceptions.py @@ -21,6 +21,10 @@ from networkx import NetworkXException +__all__ = ['DWaveNetworkXException', + 'DWaveNetworkXMissingSampler', + ] + class DWaveNetworkXException(NetworkXException): """Base class for exceptions in DWaveNetworkX.""" diff --git a/dwave_networkx/__init__.py b/dwave/plugins/networkx/generators/__init__.py similarity index 56% rename from dwave_networkx/__init__.py rename to dwave/plugins/networkx/generators/__init__.py index f948c483..9b4a3d98 100644 --- a/dwave_networkx/__init__.py +++ b/dwave/plugins/networkx/generators/__init__.py @@ -12,20 +12,6 @@ # 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_networkx.algorithms -from dwave_networkx.algorithms import * - -import dwave_networkx.utils -from dwave_networkx.exceptions import * - -import dwave_networkx.default_sampler -from dwave_networkx.default_sampler import * - -import dwave_networkx.drawing -from dwave_networkx.drawing import * - -from dwave_networkx.package_info import __version__, __author__, \ - __authoremail__, __description__ +from dwave.plugins.networkx.generators.chimera import * +from dwave.plugins.networkx.generators.markov import markov_network +from dwave.plugins.networkx.generators.pegasus import * diff --git a/dwave_networkx/generators/chimera.py b/dwave/plugins/networkx/generators/chimera.py similarity index 99% rename from dwave_networkx/generators/chimera.py rename to dwave/plugins/networkx/generators/chimera.py index c3a164ec..1901d1b5 100644 --- a/dwave_networkx/generators/chimera.py +++ b/dwave/plugins/networkx/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.plugins.networkx.exceptions import DWaveNetworkXException __all__ = ['chimera_graph', 'chimera_coordinates', diff --git a/dwave_networkx/generators/markov.py b/dwave/plugins/networkx/generators/markov.py similarity index 100% rename from dwave_networkx/generators/markov.py rename to dwave/plugins/networkx/generators/markov.py diff --git a/dwave_networkx/generators/pegasus.py b/dwave/plugins/networkx/generators/pegasus.py similarity index 99% rename from dwave_networkx/generators/pegasus.py rename to dwave/plugins/networkx/generators/pegasus.py index 5bbb87ae..b308bb35 100644 --- a/dwave_networkx/generators/pegasus.py +++ b/dwave/plugins/networkx/generators/pegasus.py @@ -19,7 +19,7 @@ import networkx as nx -from dwave_networkx.exceptions import DWaveNetworkXException +from dwave.plugins.networkx.exceptions import DWaveNetworkXException import warnings __all__ = ['pegasus_graph', diff --git a/dwave_networkx/package_info.py b/dwave/plugins/networkx/package_info.py similarity index 100% rename from dwave_networkx/package_info.py rename to dwave/plugins/networkx/package_info.py diff --git a/dwave_networkx/drawing/__init__.py b/dwave/plugins/networkx/utils/__init__.py similarity index 85% rename from dwave_networkx/drawing/__init__.py rename to dwave/plugins/networkx/utils/__init__.py index ffd58558..be4c0173 100644 --- a/dwave_networkx/drawing/__init__.py +++ b/dwave/plugins/networkx/utils/__init__.py @@ -12,5 +12,4 @@ # 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.plugins.networkx.utils.decorators import * diff --git a/dwave_networkx/generators/__init__.py b/dwave/plugins/networkx/utils/decorators.py similarity index 79% rename from dwave_networkx/generators/__init__.py rename to dwave/plugins/networkx/utils/decorators.py index fed0b571..74e185d8 100644 --- a/dwave_networkx/generators/__init__.py +++ b/dwave/plugins/networkx/utils/decorators.py @@ -12,6 +12,6 @@ # 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 * +# this submodule is kept for backwards compatibility + +from dwave.plugins.networkx.default_sampler import binary_quadratic_model_sampler diff --git a/dwave_networkx.py b/dwave_networkx.py new file mode 100644 index 00000000..c31d9929 --- /dev/null +++ b/dwave_networkx.py @@ -0,0 +1,62 @@ +# Copyright 2020 D-Wave Systems Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from dwave.plugins.networkx import * +from dwave.plugins.networkx import ( + __version__, + __author__, + __authoremail__, + __description__, + ) + + +# We want `dwave_networkx` to alias `dwave.plugins.networkx` so we mess around +# with the path. We use a function to make cleaning up this namespace easier. +def alias_subpackages(): + import importlib + import pkgutil + import sys + + if sys.version_info[1] <= 5: + # in python 3.5, we need a named tuple + from collections import namedtuple + + Module = namedtuple('Module', ['module_finder', 'name', 'ispkg']) + + def walk_packages(*args, **kwargs): + for module in pkgutil.walk_packages(*args, **kwargs): + yield Module(*module) + + else: + walk_packages = pkgutil.walk_packages + + import warnings + warnings.warn("the dwave_networkx namespace was deprecated in " + "dwave-networkx 0.9.0, please use " + "dwave.plugins.networkx instead.", + DeprecationWarning, stacklevel=3) + + for module in walk_packages(dwave.plugins.networkx.__path__, + dwave.plugins.networkx.__name__ + '.'): + # only want the subpackages + if not module.ispkg: + continue + + # pretend that each subpackage lives in the dwave_networkx namespace + package_name = 'dwave_networkx.' + module.name.split('.')[-1] + sys.modules[package_name] = importlib.import_module(module.name) + + +alias_subpackages() +del alias_subpackages diff --git a/dwave_networkx/algorithms/__init__.py b/dwave_networkx/algorithms/__init__.py deleted file mode 100644 index 3c4f4ad3..00000000 --- a/dwave_networkx/algorithms/__init__.py +++ /dev/null @@ -1,25 +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 * diff --git a/dwave_networkx/default_sampler.py b/dwave_networkx/default_sampler.py deleted file mode 100644 index 8763e663..00000000 --- a/dwave_networkx/default_sampler.py +++ /dev/null @@ -1,136 +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. - -"""Sets a binary quadratic model sampler used by default -for functions that require a sample when none is specified. - -A sampler is a process that samples -from low-energy states in models defined by an Ising equation -or a Quadratic Unconstrained Binary Optimization Problem -(QUBO). - -Sampler API ------------ -* Required Methods: 'sample_qubo' and 'sample_ising' -* Return value: iterable of samples, in order of increasing energy - -See `dimod `_ for details. - -Example -------- -This example creates and uses a placeholder for binary quadratic model -samplers that returns a correct response only in the case of finding an -independent set on a complete graph (where one node is always an -independent set). The placeholder sampler can be used to test the simple -examples of the functions for configuring a default sampler. - ->>> # Create a placeholder sampler ->>> class ExampleSampler: -... # an example sampler, only works for independent set on complete -... # graphs -... def __init__(self, name): -... self.name = name -... def sample_ising(self, h, J): -... sample = {v: -1 for v in h} -... sample[0] = 1 # set one node to true -... return [sample] -... def sample_qubo(self, Q): -... sample = {v: 0 for v in set().union(*Q)} -... sample[0] = 1 # set one node to true -... return [sample] -... def __str__(self): -... return self.name -... ->>> # Identify the new sampler as the default sampler ->>> sampler0 = ExampleSampler('sampler0') ->>> dnx.set_default_sampler(sampler0) ->>> # Find an independent set using the default sampler ->>> G = nx.complete_graph(5) ->>> dnx.maximum_independent_set(G) -[0] - -""" - -from dwave_networkx.utils.decorators import binary_quadratic_model_sampler - -__all__ = ['set_default_sampler', 'get_default_sampler', 'unset_default_sampler'] - - -_SAMPLER = None - - -@binary_quadratic_model_sampler(0) -def set_default_sampler(sampler): - """Sets a default binary quadratic model sampler. - - Parameters - ---------- - sampler - A binary quadratic model sampler. A sampler is a process that - samples from low-energy states in models defined by an Ising - equation or a Quadratic Unconstrained Binary Optimization - Problem (QUBO). A sampler is expected to have a 'sample_qubo' - and 'sample_ising' method. A sampler is expected to return an - iterable of samples, in order of increasing energy. - - Examples - -------- - This example sets sampler0 as the default sampler and finds an independent - 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 - - """ - global _SAMPLER - _SAMPLER = sampler - - -def unset_default_sampler(): - """Resets the default sampler back to None. - - Examples - -------- - 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 - 'sampler0' - >>> dnx.unset_default_sampler() # doctest: +SKIP - >>> print(dnx.get_default_sampler()) # doctest: +SKIP - None - """ - global _SAMPLER - _SAMPLER = None - - -def get_default_sampler(): - """Queries the current default sampler. - - Examples - -------- - This example queries the default sampler before and after specifying - a default sampler. - - >>> print(dnx.get_default_sampler()) # doctest: +SKIP - None - >>> dnx.set_default_sampler(sampler) # doctest: +SKIP - >>> print(dnx.get_default_sampler()) # doctest: +SKIP - 'sampler' - - """ - return _SAMPLER diff --git a/dwave_networkx/examples/chimera_graph.py b/examples/chimera_graph.py similarity index 95% rename from dwave_networkx/examples/chimera_graph.py rename to examples/chimera_graph.py index 073c61c3..e10aed03 100644 --- a/dwave_networkx/examples/chimera_graph.py +++ b/examples/chimera_graph.py @@ -14,7 +14,7 @@ # import matplotlib.pyplot as plt -import dwave_networkx as dnx +import dwave.plugins.networkx as dnx import networkx as nx G = dnx.chimera_graph(2, 2, 4) diff --git a/dwave_networkx/examples/max_cut.py b/examples/max_cut.py similarity index 96% rename from dwave_networkx/examples/max_cut.py rename to examples/max_cut.py index 98fd1ae0..20a049cb 100644 --- a/dwave_networkx/examples/max_cut.py +++ b/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.plugins.networkx as dnx import networkx as nx import dimod diff --git a/dwave_networkx/examples/max_independent_set.py b/examples/max_independent_set.py similarity index 96% rename from dwave_networkx/examples/max_independent_set.py rename to examples/max_independent_set.py index 194e0f46..dddd0385 100644 --- a/dwave_networkx/examples/max_independent_set.py +++ b/examples/max_independent_set.py @@ -13,7 +13,7 @@ # limitations under the License. import networkx as nx -import dwave_networkx as dnx +import dwave.plugins.networkx as dnx import dimod # Use basic simulated annealer diff --git a/dwave_networkx/examples/min_maximal_matching.py b/examples/min_maximal_matching.py similarity index 96% rename from dwave_networkx/examples/min_maximal_matching.py rename to examples/min_maximal_matching.py index 82697ee2..b71422d9 100644 --- a/dwave_networkx/examples/min_maximal_matching.py +++ b/examples/min_maximal_matching.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.plugins.networkx as dnx import dimod # Use basic simulated annealer diff --git a/dwave_networkx/examples/min_vertex_color.py b/examples/min_vertex_color.py similarity index 96% rename from dwave_networkx/examples/min_vertex_color.py rename to examples/min_vertex_color.py index 15a7fd6d..4eada9b7 100644 --- a/dwave_networkx/examples/min_vertex_color.py +++ b/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.plugins.networkx as dnx import networkx as nx import dimod diff --git a/dwave_networkx/examples/min_vertex_cover.py b/examples/min_vertex_cover.py similarity index 97% rename from dwave_networkx/examples/min_vertex_cover.py rename to examples/min_vertex_cover.py index fe86feba..69dd87db 100644 --- a/dwave_networkx/examples/min_vertex_cover.py +++ b/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.plugins.networkx as dnx import networkx as nx import dimod diff --git a/setup.py b/setup.py index 6bcfd124..3a7a2e04 100644 --- a/setup.py +++ b/setup.py @@ -20,13 +20,14 @@ 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", "plugins", "networkx", "package_info.py")).read()) packages = ['dwave_networkx', - 'dwave_networkx.algorithms', - 'dwave_networkx.utils', - 'dwave_networkx.drawing', - 'dwave_networkx.generators', + 'dwave.plugins.networkx', + 'dwave.plugins.networkx.algorithms', + 'dwave.plugins.networkx.utils', + 'dwave.plugins.networkx.drawing', + 'dwave.plugins.networkx.generators', ] install_requires = ['networkx>=2.0,<3.0', @@ -48,17 +49,18 @@ ] setup( - name='dwave_networkx', + name='dwave-networkx', 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-networkx', + download_url='https://github.com/dwavesystems/dwave-networkx/releases', packages=packages, license='Apache 2.0', install_requires=install_requires, python_requires=python_requires, classifiers=classifiers, + zip_safe=False, )