Skip to content

Commit

Permalink
1.1.7 release (#26)
Browse files Browse the repository at this point in the history
* Recreate dev and increment version

* Update README.rst

* Removed need for Cython (#24)

* removed need for cython

* fixed codestyle error

* fixed import codestyle error

* Fixed typo in docstring

* fixed bug

* converted np.exp and np.log2 to math.exp and math.log2

* small updates

* Renamed ambiguous variable

* Update _anneal_results.py

* Added le and ge tests

Co-authored-by: Joseph T. Iosue <[email protected]>
  • Loading branch information
jtiosue and Joseph T. Iosue authored Jun 12, 2020
1 parent c530d38 commit 8149cfa
Show file tree
Hide file tree
Showing 42 changed files with 382 additions and 4,703 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
make cython_install
make dev_install
- name: Test
run: |
make test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_manylinus_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: 3.8
- name: Install dependencies
run: |
make cython_install
make dev_install
- name: Build manylinux Python wheels
uses: RalfG/[email protected]_x86_64
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: 3.8
- name: Install dependencies
run: |
make cython_install
make dev_install
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_windows_macos_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
make cython_install
make dev_install
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
include README.rst LICENSE requirements.txt
recursive-include qubovert/sim/src *.h *.c
recursive-include qubovert *.pyx *.c
recursive-include qubovert *.h *.c
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ dev_install:
$(pip_cmd) install -e .
$(pip_cmd) install -r requirements-dev.txt

cython_install:
$(pip_cmd) install --upgrade pip
$(pip_cmd) install -r requirements-dev.txt
$(pip_cmd) install -e .

test:
$(python_cmd) -m pydocstyle convention=numpy qubovert
$(python_cmd) -m pytest --codestyle --cov=./ --cov-report=xml
Expand Down
38 changes: 19 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ The one-stop package for formulating, simulating, and solving problems in boolea

*master branch*

.. image:: https://github.com/jiosue/qubovert/workflows/build/badge.svg?branch=master
:target: https://github.com/jiosue/qubovert/actions/
.. image:: https://github.com/jtiosue/qubovert/workflows/build/badge.svg?branch=master
:target: https://github.com/jtiosue/qubovert/actions?query=workflow%3Abuild+branch%3Amaster
:alt: GitHub Actions CI
.. image:: https://readthedocs.org/projects/qubovert/badge/?version=latest
:target: https://qubovert.readthedocs.io/en/latest/?badge=latest
:target: https://qubovert.readthedocs.io/en/latest/
:alt: Documentation Status
.. image:: https://codecov.io/gh/jiosue/qubovert/branch/master/graph/badge.svg
:target: https://codecov.io/gh/jiosue/qubovert
.. image:: https://codecov.io/gh/jtiosue/qubovert/branch/master/graph/badge.svg
:target: https://codecov.io/gh/jtiosue/qubovert
:alt: Code Coverage
.. image:: https://img.shields.io/lgtm/grade/python/g/jiosue/qubovert.svg?logo=lgtm&logoWidth=18
:target: https://lgtm.com/projects/g/jiosue/qubovert/context:python
.. image:: https://img.shields.io/lgtm/grade/python/g/jtiosue/qubovert.svg?logo=lgtm&logoWidth=18
:target: https://lgtm.com/projects/g/jtiosue/qubovert/context:python
:alt: Code Quality

*dev branch*

.. image:: https://github.com/jiosue/qubovert/workflows/build/badge.svg?branch=dev
:target: https://github.com/jiosue/qubovert/actions/
.. image:: https://github.com/jtiosue/qubovert/workflows/build/badge.svg?branch=dev
:target: https://github.com/jtiosue/qubovert/actions?query=workflow%3Abuild+branch%3Adev
:alt: GitHub Actions CI
.. image:: https://readthedocs.org/projects/qubovert/badge/?version=dev
:target: https://qubovert.readthedocs.io/en/latest/?badge=dev
:target: https://qubovert.readthedocs.io/en/dev/
:alt: Documentation Status
.. image:: https://codecov.io/gh/jiosue/qubovert/branch/dev/graph/badge.svg
:target: https://codecov.io/gh/jiosue/qubovert
.. image:: https://codecov.io/gh/jtiosue/qubovert/branch/dev/graph/badge.svg
:target: https://codecov.io/gh/jtiosue/qubovert
:alt: Code Coverage

*pypi distribution*
Expand All @@ -41,7 +41,7 @@ The one-stop package for formulating, simulating, and solving problems in boolea
:alt: pypi dist downloads


Please see the `Repository <https://github.com/jiosue/qubovert>`_ and `Docs <https://qubovert.readthedocs.io>`_. For examples/tutorials, see the `notebooks <https://github.com/jiosue/qubovert/tree/master/notebook_examples>`_.
Please see the `Repository <https://github.com/jtiosue/qubovert>`_ and `Docs <https://qubovert.readthedocs.io>`_. For examples/tutorials, see the `notebooks <https://github.com/jtiosue/qubovert/tree/master/notebook_examples>`_.


.. contents::
Expand All @@ -63,7 +63,7 @@ Or to install from source:

.. code:: shell
git clone https://github.com/jiosue/qubovert.git
git clone https://github.com/jtiosue/qubovert.git
cd qubovert
pip install -e .
Expand All @@ -81,7 +81,7 @@ Note that to install from source on Windows you will need `Microsoft Visual C++
Example of the typical workflow
-------------------------------

Here we show an example of formulating a pseudo-boolean objective function. We can also make spin objective functions (Hamiltonians) in a very similar manner. See the `notebooks <https://github.com/jiosue/qubovert/tree/master/notebook_examples>`_ for examples.
Here we show an example of formulating a pseudo-boolean objective function. We can also make spin objective functions (Hamiltonians) in a very similar manner. See the `notebooks <https://github.com/jtiosue/qubovert/tree/master/notebook_examples>`_ for examples.


Create the boolean objective function to minimize
Expand Down Expand Up @@ -184,7 +184,7 @@ Managing QUBO, QUSO, PUBO, PUSO, PCBO, and PCSO formulations
- PCBO: Polynomial Constrained Boolean Optimization (``qubovert.PCBO``)
- PCSO: Polynomial Constrained Spin Optimization (``qubovert.PCSO``)

Each of the objects has many methods and arbitary arithmetic defined; see the docstrings of each object and the `notebooks <https://github.com/jiosue/qubovert/tree/master/notebook_examples>`_ for more info. A boolean optimization model is one whose variables can be assigned to be either 0 or 1, while a spin optimization model is one whose variables can be assigned to be either 1 or -1. The ``qubovert.boolean_var(name)`` function will create a PCBO representing the boolean variable with name ``name``. Similarly, the ``qubovert.spin_var(name)`` function will create a PCSO representing the spin variable with name ``name``.
Each of the objects has many methods and arbitary arithmetic defined; see the docstrings of each object and the `notebooks <https://github.com/jtiosue/qubovert/tree/master/notebook_examples>`_ for more info. A boolean optimization model is one whose variables can be assigned to be either 0 or 1, while a spin optimization model is one whose variables can be assigned to be either 1 or -1. The ``qubovert.boolean_var(name)`` function will create a PCBO representing the boolean variable with name ``name``. Similarly, the ``qubovert.spin_var(name)`` function will create a PCSO representing the spin variable with name ``name``.


There are many utilities in the *utils* library that can be helpful. Some examples of utility functions are listed here.
Expand All @@ -204,7 +204,7 @@ There are many utilities in the *utils* library that can be helpful. Some exampl
See ``qubovert.utils.__all__`` for more. Please note that all conversions between boolean and spin map {0, 1} to/from {1, -1} in that order! This is the convention that *qubovert* uses everywhere.


The PCBO and PCSO objects have constraint methods; for example, the ``.add_constraint_le_zero`` method will enforce that an expression is less than or equal to zero by adding a penalty to the model whenever it does not. The PCBO object also has constraint methods for satisfiability expressions; for example, the ``.add_constraint_OR`` will enforce that the OR of the given boolean expression evaluates to True by adding a penalty to the model whenever it does not. See the docstrings and `notebooks <https://github.com/jiosue/qubovert/tree/master/notebook_examples>`_ for more info.
The PCBO and PCSO objects have constraint methods; for example, the ``.add_constraint_le_zero`` method will enforce that an expression is less than or equal to zero by adding a penalty to the model whenever it does not. The PCBO object also has constraint methods for satisfiability expressions; for example, the ``.add_constraint_OR`` will enforce that the OR of the given boolean expression evaluates to True by adding a penalty to the model whenever it does not. See the docstrings and `notebooks <https://github.com/jtiosue/qubovert/tree/master/notebook_examples>`_ for more info.


For more utilities on satisfiability expressions, *qubovert* also has a *sat* library; see ``qubovert.sat.__all__``. Consider the following 3-SAT example. We have variables ``x0, x1, x2, x3``, labeled by ``0, 1, 2, 3``. We can create an expression ``C`` that evaluates to 1 whenever the 3-SAT conditions are satisfied.
Expand All @@ -225,7 +225,7 @@ For more utilities on satisfiability expressions, *qubovert* also has a *sat* li
Basic examples of common functionality
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

See the `notebooks <https://github.com/jiosue/qubovert/tree/master/notebook_examples>`_ for many fully worked out examples. Here we will just show some basic and brief examples.
See the `notebooks <https://github.com/jtiosue/qubovert/tree/master/notebook_examples>`_ for many fully worked out examples. Here we will just show some basic and brief examples.


The basic building block of a binary optimization model is a Python dictionary. The keys of the dictionary are tuples of variable names, and the values are their corresponding coefficients. For example, in the below code block, ``model1``, ``model2``, and ``model3`` are equivalent.
Expand Down Expand Up @@ -357,7 +357,7 @@ We use a Metropolis algorithm to simulate spin and boolean system. Below we show
Convert common problems to quadratic form (the *problems* library)
------------------------------------------------------------------

One of the goals of *qubovert* is to become a large collection of problems mapped to QUBO and QUSO forms in order to aid the recent increase in study of these problems due to quantum optimization algorithms. Use Python's ``help`` function! I have very descriptive doc strings on all the functions and classes. Please see the `notebooks <https://github.com/jiosue/qubovert/tree/master/notebook_examples>`_ for a few more examples as well.
One of the goals of *qubovert* is to become a large collection of problems mapped to QUBO and QUSO forms in order to aid the recent increase in study of these problems due to quantum optimization algorithms. Use Python's ``help`` function! I have very descriptive doc strings on all the functions and classes. Please see the `notebooks <https://github.com/jtiosue/qubovert/tree/master/notebook_examples>`_ for a few more examples as well.


See the following Set Cover example.
Expand Down
6 changes: 3 additions & 3 deletions notebook_examples/Annealing_and_simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@
}
],
"source": [
"res.sort_by_value()\n",
"res.sort()\n",
"print(res)"
]
},
Expand Down Expand Up @@ -709,7 +709,7 @@
" >>> print(anneal_res.best.state)\n",
" {0: 1, 1: -1, 2: 1, 3: -1, 4: 1}\n",
" >>> # now sort the results\n",
" >>> anneal_res.sort_by_value()\n",
" >>> anneal_res.sort()\n",
" >>>\n",
" >>> # now iterate through all of the results in the sorted order\n",
" >>> for res in anneal_res:\n",
Expand Down Expand Up @@ -948,7 +948,7 @@
"\n",
"I'd like to remark that D-Wave's QUBO and QUSO simulated annealing implementations in their Python package `neal` are faster than `qubovert`'s implementations. If your goal is to use simulated annealing to find the ground state of a QUBO or QUSO, then you should probably use `neal`. In fact, the main purpose of `qubovert` is to aid in the formulation of binary optimization models so that they can easily be sent to D-Wave (either their simulated or quantum annealer). See all the other notebooks where I use `neal` to solve the models that I create.\n",
"\n",
"However, `neal` does not provide the functionality for simulated annealing of PUBOs and PUSOs, nor does it allow the ability to provide an arbitrary temperature schedule. If your goal is to research different schedules (like we did with the reverse annealing example) or to solve higher order models that are expensive to reduce to QUBOs and QUSOs, then the `qubovert.sim` library may be useful. Similarly, if you are interested in how physical systems behave with time and temperature, then `qubovert`'s simulation functionaliy may be useful; for example, see a <a href=\"https://github.com/jiosue/ising_sim\">graphical simulation implementation</a> that I wrote for the 1D ferromagnetic Ising chain."
"However, `neal` does not provide the functionality for simulated annealing of PUBOs and PUSOs, nor does it allow the ability to provide an arbitrary temperature schedule. If your goal is to research different schedules (like we did with the reverse annealing example) or to solve higher order models that are expensive to reduce to QUBOs and QUSOs, then the `qubovert.sim` library may be useful. Similarly, if you are interested in how physical systems behave with time and temperature, then `qubovert`'s simulation functionaliy may be useful; for example, see a <a href=\"https://github.com/jtiosue/ising_sim\">graphical simulation implementation</a> that I wrote for the 1D ferromagnetic Ising chain."
]
},
{
Expand Down
5 changes: 5 additions & 0 deletions qubovert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
from . import sim
from . import problems


del __all_qubo__, __all_quso__
del __all_pubo__, __all_puso__
del __all_pcbo__, __all_pcso__

BOOLEAN_MODELS = QUBO, PUBO, PCBO, utils.QUBOMatrix, utils.PUBOMatrix
SPIN_MODELS = QUSO, PUSO, PCSO, utils.QUSOMatrix, utils.PUSOMatrix

Expand Down
4 changes: 2 additions & 2 deletions qubovert/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
)


__version__ = "1.1.6"
__version__ = "1.1.7"
__author__ = "Joseph T. Iosue"
__authoremail__ = "[email protected]"
__license__ = "Apache Software License 2.0"
__sourceurl__ = "https://github.com/jiosue/qubovert"
__sourceurl__ = "https://github.com/jtiosue/qubovert"
__docsurl__ = "https://qubovert.readthedocs.io"
__description__ = (
"A package for formulating, simulating, and solving "
Expand Down
2 changes: 2 additions & 0 deletions qubovert/problems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
__all_np__ + __all_benchmarking__
)

del __all_np__, __all_benchmarking__

name = "problems"
2 changes: 2 additions & 0 deletions qubovert/problems/benchmarking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
__all_asc__
)

del __all_asc__

name = "benchmarking"
3 changes: 3 additions & 0 deletions qubovert/problems/np/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@
__all_packing__ + __all_partitioning__ + __all_tree__
)

del __all_bilp__, __all_coloring__, __all_covering__, __all_cycles__
del __all_packing__, __all_partitioning__, __all_tree__

name = "np"
2 changes: 2 additions & 0 deletions qubovert/problems/np/bilp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
__all_bilp__
)

del __all_bilp__

name = "bilp"
2 changes: 2 additions & 0 deletions qubovert/problems/np/coloring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
__all_js__
)

del __all_js__

name = "coloring"
2 changes: 1 addition & 1 deletion qubovert/problems/np/coloring/_job_sequencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

from numpy import log2
from math import log2
from qubovert.utils import (
QUBOMatrix, decimal_to_boolean, solution_type, spin_to_boolean
)
Expand Down
2 changes: 2 additions & 0 deletions qubovert/problems/np/covering/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
__all_vc__
)

del __all_sc__, __all_vc__

name = "covering"
3 changes: 2 additions & 1 deletion qubovert/problems/np/covering/_set_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"""

from numpy import log2, allclose
from numpy import allclose
from math import log2
from qubovert.utils import (
QUBOMatrix, solve_qubo_bruteforce, solution_type, spin_to_boolean
)
Expand Down
2 changes: 2 additions & 0 deletions qubovert/problems/np/partitioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
__all_gp__
)

del __all_np__, __all_gp__

name = "partitioning"
2 changes: 2 additions & 0 deletions qubovert/sat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
__all_sat__
)

del __all_sat__

name = "sat"
11 changes: 5 additions & 6 deletions qubovert/sim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@


__all__ = (
__all_pusosim__ +
__all_pubosim__ +
__all_qusosim__ +
__all_qubosim__ +
__all_results__ +
__all_anneal__
__all_pusosim__ + __all_pubosim__ + __all_qusosim__ + __all_qubosim__ +
__all_results__ + __all_anneal__
)

del __all_pusosim__, __all_pubosim__, __all_qusosim__, __all_qubosim__
del __all_results__, __all_anneal__


name = "sim"
27 changes: 14 additions & 13 deletions qubovert/sim/_anneal.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from . import PUSOSimulation, QUSOSimulation, AnnealResults
import random
import numpy as np
from math import log

__all__ = (
'anneal_qubo', 'anneal_quso', 'anneal_pubo', 'anneal_puso',
Expand Down Expand Up @@ -114,8 +115,8 @@ def anneal_temperature_range(model, start_flip_prob=0.5,

# now ensure that the bolzmann weight satisfy the desired probabilities.
# ie exp(-del_energy / T) = prob
T0 = -max_del_energy / np.log(start_flip_prob) if start_flip_prob else 0
Tf = -min_del_energy / np.log(end_flip_prob) if end_flip_prob else 0
T0 = -max_del_energy / log(start_flip_prob) if start_flip_prob else 0
Tf = -min_del_energy / log(end_flip_prob) if end_flip_prob else 0
return float(T0), float(Tf)


Expand Down Expand Up @@ -361,7 +362,7 @@ def anneal_puso(H, num_anneals=1, anneal_duration=1000, initial_state=None,
>>> print(anneal_res.best.state)
{0: 1, 1: -1, 2: 1, 3: -1, 4: 1}
>>> # now sort the results
>>> anneal_res.sort_by_value()
>>> anneal_res.sort()
>>>
>>> # now iterate through all of the results in the sorted order
>>> for res in anneal_res:
Expand All @@ -383,9 +384,9 @@ def anneal_pubo(P, num_anneals=1, anneal_duration=1000, initial_state=None,
"""anneal_pubo.
Run a simulated annealing algorithm to try to find the minimum of the PUBO
given by ``P``. ``anneal_pubo`` uses a cooling schedule with the
``qubovert.sim.PUBOSimulation`` object. Please see all of the parameters
for details.
given by ``P``. ``anneal_pubo`` converts ``P`` to a PUSO and then uses a
cooling schedule with the ``qubovert.sim.PUSOSimulation`` object. Please
see all of the parameters for details.
**Please note** that the ``qv.sim.anneal_qubo`` function performs much
faster than the ``qv.sim.anneal_pubo`` function since the former is written
Expand Down Expand Up @@ -476,7 +477,7 @@ def anneal_pubo(P, num_anneals=1, anneal_duration=1000, initial_state=None,
>>> print(anneal_res.best.state)
{0: 0, 1: 1, 2: 0, 3: 1, 4: 0}
>>> # now sort the results
>>> anneal_res.sort_by_value()
>>> anneal_res.sort()
>>>
>>> # now iterate through all of the results in the sorted order
>>> for res in anneal_res:
Expand All @@ -500,7 +501,7 @@ def anneal_quso(L, num_anneals=1, anneal_duration=1000, initial_state=None,
Run a simulated annealing algorithm to try to find the minimum of the QUSO
given by ``L``. ``anneal_quso`` uses a cooling schedule with the
``qubovert.sim.PUSOSimulation`` object. Please see all of the parameters
``qubovert.sim.QUSOSimulation`` object. Please see all of the parameters
for details.
Parameters
Expand Down Expand Up @@ -586,7 +587,7 @@ def anneal_quso(L, num_anneals=1, anneal_duration=1000, initial_state=None,
>>> print(anneal_res.best.state)
{0: 1, 1: -1, 2: 1, 3: -1, 4: 1}
>>> # now sort the results
>>> anneal_res.sort_by_value()
>>> anneal_res.sort()
>>>
>>> # now iterate through all of the results in the sorted order
>>> for res in anneal_res:
Expand All @@ -608,9 +609,9 @@ def anneal_qubo(Q, num_anneals=1, anneal_duration=1000, initial_state=None,
"""anneal_qubo.
Run a simulated annealing algorithm to try to find the minimum of the QUBO
given by ``Q``. ``anneal_qubo`` uses a cooling schedule with the
``qubovert.sim.PUBOSimulation`` object. Please see all of the parameters
for details.
given by ``Q``. ``anneal_qubo`` converts ``Q`` to a QUSO and then uses a
cooling schedule with the ``qubovert.sim.QUSOSimulation`` object. Please
see all of the parameters for details.
Parameters
----------
Expand Down Expand Up @@ -696,7 +697,7 @@ def anneal_qubo(Q, num_anneals=1, anneal_duration=1000, initial_state=None,
>>> print(anneal_res.best.state)
{0: 0, 1: 1, 2: 0, 3: 1, 4: 0}
>>> # now sort the results
>>> anneal_res.sort_by_value()
>>> anneal_res.sort()
>>>
>>> # now iterate through all of the results in the sorted order
>>> for res in anneal_res:
Expand Down
Loading

0 comments on commit 8149cfa

Please sign in to comment.