Skip to content

Commit

Permalink
Merge pull request #829 from arcondello/remove-boost
Browse files Browse the repository at this point in the history
Remove boost and roof duality
  • Loading branch information
arcondello authored May 26, 2021
2 parents ad96ab8 + b4fa721 commit 535604c
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 2,335 deletions.
30 changes: 0 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ jobs:
name: fix git checkout
command: git reset --hard

- run:
name: install boost
command: |
yum install -y boost-devel
- run:
name: build wheels
command: |
Expand Down Expand Up @@ -62,12 +57,6 @@ jobs:
steps:
- checkout

# in the future we'd like to not need boost here
- run: &linux-install-boost-template
name: install boost
command: |
sudo apt-get install libboost-dev
- run:
name: build sdist
command: |
Expand Down Expand Up @@ -174,11 +163,6 @@ jobs:
command: |
brew install pyenv
- run: &install-boost-osx-template
name: install boost
command: |
brew install boost
- restore_cache:
keys:
- pyenv-{{ .Environment.CIRCLE_JOB }}-xcode12.2.0
Expand Down Expand Up @@ -247,8 +231,6 @@ jobs:
command: |
brew install pyenv
- run: *install-boost-osx-template

- restore_cache:
keys:
- pyenv-{{ .Environment.CIRCLE_JOB }}-xcode12.2.0
Expand Down Expand Up @@ -310,16 +292,10 @@ jobs:
pip install -r requirements.txt
pip install -r tests\requirements.txt
- run: &win-install-boost-template
name: install boost
command: |
nuget install boost -ExcludeVersion -OutputDirectory .
- run:
name: build extension
command: |
env\Scripts\activate.ps1
$env:CL+=' -Iboost\lib\native\include\'
python setup.py build_ext --inplace
- run:
Expand Down Expand Up @@ -354,13 +330,10 @@ jobs:

- run: *win-install-dependencies-template

- run: *win-install-boost-template

- run:
name: create wheel
command: |
env\Scripts\activate.ps1
$env:CL+=' -Iboost\lib\native\include\'
python setup.py bdist_wheel
- store_artifacts:
Expand All @@ -383,8 +356,6 @@ jobs:
steps:
- checkout

- run: *linux-install-boost-template

- run:
name: install doxygen
command: sudo apt-get install doxygen
Expand Down Expand Up @@ -429,7 +400,6 @@ jobs:

steps:
- checkout
- run: *linux-install-boost-template
- run:
name: run cpp tests
command: |
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
include pyproject.toml
recursive-include dimod/roof_duality *.cpp *.hpp
recursive-include dimod/include *h
recursive-include dimod *.pyx *.pxd *.pyx.src
5 changes: 0 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ in place:
pip install -r requirements.txt
python setup.py build_ext --inplace
Note that installation from source requires that your system have the Boost_
C++ libraries installed.

.. _Boost: https://www.boost.org/

.. installation-end-marker
License
Expand Down
9 changes: 1 addition & 8 deletions dimod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@
from dimod.reference import *
import dimod.reference

try:
import dimod.roof_duality._fix_variables as _
except ImportError:
pass
else:
# we only import fix_variables function into the top level namespace if the c++ extension
# is built
from dimod.roof_duality import fix_variables
from dimod.roof_duality import fix_variables

from dimod.binary_quadratic_model import BinaryQuadraticModel, BQM
import dimod.binary_quadratic_model
Expand Down
57 changes: 0 additions & 57 deletions dimod/roof_duality/_fix_variables.pyx

This file was deleted.

56 changes: 2 additions & 54 deletions dimod/roof_duality/fix_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,64 +39,12 @@ def fix_variables(bqm, sampling_mode=True):
Returns:
dict: Variable assignments for some variables of the specified binary quadratic model.
Examples:
This example creates a binary quadratic model with a single ground state
and fixes the model's single variable to the minimizing assignment.
>>> bqm = dimod.BinaryQuadraticModel.from_ising({'a': 1.0}, {})
>>> dimod.fix_variables(bqm)
{'a': -1}
This example has two ground states, :math:`a=b=-1` and :math:`a=b=1`, with
no variable having a single value for all ground states, so neither variable
is fixed.
>>> bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN)
>>> bqm.add_interaction('a', 'b', -1.0)
>>> dimod.fix_variables(bqm) # doctest: +SKIP
{}
This example turns sampling model off, so variables are fixed to an assignment
that attains the ground state.
>>> bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN)
>>> bqm.add_interaction('a', 'b', -1.0)
>>> dimod.fix_variables(bqm, sampling_mode=False) # doctest: +SKIP
{'a': 1, 'b': 1}
.. [BHT] Boros, E., P.L. Hammer, G. Tavares. Preprocessing of Unconstraint Quadratic Binary
Optimization. Rutcor Research Report 10-2006, April, 2006.
.. [BH] Boros, E., P.L. Hammer. Pseudo-Boolean optimization. Discrete Applied Mathematics 123,
(2002), pp. 155-225
"""
try:
from dimod.roof_duality._fix_variables import fix_variables_wrapper
except ImportError:
raise ImportError("c++ extension roof_duality is not built")

if sampling_mode:
method = 2 # roof-duality only
else:
method = 1 # roof-duality and strongly connected components

linear = bqm.linear
if all(v in linear for v in range(len(bqm))):
# we can work with the binary form of the bqm directly
fixed = fix_variables_wrapper(bqm.binary, method)
else:
try:
inverse_mapping = dict(enumerate(sorted(linear)))
except TypeError:
# in python3 unlike types cannot be sorted
inverse_mapping = dict(enumerate(linear))
mapping = {v: i for i, v in inverse_mapping.items()}

fixed = fix_variables_wrapper(bqm.relabel_variables(mapping, inplace=False).binary, method)
fixed = {inverse_mapping[v]: val for v, val in fixed.items()}

if bqm.vartype is Vartype.SPIN:
return {v: 2*val - 1 for v, val in fixed.items()}
else:
return fixed
# todo: add temporary dependency on dwave-preprocessing
raise NotImplementedError
Loading

0 comments on commit 535604c

Please sign in to comment.