Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dimod 0.10 #248

Merged
merged 4 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 162 additions & 109 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,160 +1,213 @@
version: 2
version: 2.1

jobs:
test-linux:
parameters:
python-version:
type: string
dimod-version:
type: string

#
# linux
#

test-3.9: &test-linux-template
docker:
- image: circleci/python:3.9.0
- image: circleci/python:<< parameters.python-version >>

steps:
- checkout
- restore_cache:
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
- run: python -m virtualenv env
- run: env/bin/pip install -r requirements.txt -r tests/requirements.txt -r docs/requirements.txt
- save_cache:
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
paths:
- env
- run: env/bin/pip install .
- run: env/bin/coverage run -m unittest discover
- run:
name: codecov

- restore_cache: &restore-cache-env
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}

- run: &create-virtualenv
name: Create virtual environment
command: |
. env/bin/activate
codecov # calls `coverage xml`, so we must activate venv
- run:
name: doctest
python -m venv env

- run: &install-requirements
name: Install requirements
command: |
. env/bin/activate
make -C docs/ doctest
pip install -U pip
pip install -r requirements.txt -r tests/requirements.txt
pip install wheel twine

- run:
name: linkcheck
name: Install appropriate dimod version
command: |
. env/bin/activate
make -C docs/ linkcheck
if [[ "<< parameters.dimod-version >>" ]]; then
pip install 'dimod<< parameters.dimod-version >>'
else
pip uninstall dimod -y
fi

- save_cache: &save-cache-env
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
paths:
- env

test-3.8:
<<: *test-linux-template
docker:
- image: circleci/python:3.8.6
- run: &build-package
name: Build package
command: env/bin/python setup.py sdist bdist_wheel

test-3.7:
<<: *test-linux-template
docker:
- image: circleci/python:3.7.9
- run: &install-package
name: Install package
command: env/bin/pip install .

test-3.6:
<<: *test-linux-template
docker:
- image: circleci/python:3.6.12
- run: &run-python-tests
name: Run Python tests
command: env/bin/coverage run -m unittest discover

- run: &upload-python-code-coverage
name: Upload code coverage
command: |
. env/bin/activate
codecov # calls `coverage xml`, so we must activate venv

#
# macos
#
test-macos:
parameters:
python-version:
type: string
xcode:
type: string

test-osx-3.9: &test-osx-template
macos:
xcode: "12.3.0"
environment:
PYTHON: 3.9.0
xcode: << parameters.xcode >>

steps:
- checkout
- run: HOMEBREW_NO_AUTO_UPDATE=1 brew install pyenv
- restore_cache:

# install `python-version` and cache it
- run: &brew-install-pyenv
name: Install pyenv
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install pyenv

- restore_cache: &restore-cache-pyenv
keys:
- pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-12.3.0
- run: pyenv install $PYTHON -s
- save_cache:
key: pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-12.3.0
- v1-pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-<< parameters.xcode >>

- run: &pyenv-install-python
name: Install python
command: pyenv install << parameters.python-version >> -s

- run: &pyenv-set-system-python
name: Set system python
command: |
pyenv global << parameters.python-version >>
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

- save_cache: &save-cache-pyenv
key: v1-pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-<< parameters.xcode >>
paths:
- ~/.pyenv
- run:
name: create virtualenv
command: |
eval "$(pyenv init -)"
pyenv local $PYTHON
python -m pip install virtualenv
python -m virtualenv env

# install dependencies and cache them
- restore_cache: *restore-cache-env

- run: *create-virtualenv

- run: *install-requirements

- save_cache: *save-cache-env

- run: *install-package

- run: *run-python-tests

test-docs:
docker:
- image: circleci/python:3.7

steps:
- checkout

- restore_cache:
keys:
- v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
- run: &install-dependencies-template
name: install dependencies
command: |
. env/bin/activate
python --version
pip install -r requirements.txt -r tests/requirements.txt
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}

- run: *create-virtualenv

- run: *install-requirements

- run:
name: Install docs requirements
command: env/bin/pip install -r docs/requirements.txt

- save_cache:
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
paths:
- env
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
- run: env/bin/pip install .
- run: env/bin/coverage run -m unittest discover

test-osx-3.8:
<<: *test-osx-template
environment:
PYTHON: 3.8.6
- run: *install-package

test-osx-3.7:
<<: *test-osx-template
environment:
PYTHON: 3.7.9
- run:
name: Build docs
command: |
. env/bin/activate
make -C docs/ html

test-osx-3.6:
<<: *test-osx-template
environment:
PYTHON: 3.6.12
- store_artifacts:
path: ./docs/build/html

#
# deploy
#
- run:
name: Test docs
command: |
. env/bin/activate
make -C docs/ doctest

- run:
name: Test links
command: |
. env/bin/activate
make -C docs/ linkcheck

pypi-deploy:
<<: *test-linux-template
docker:
- image: circleci/python:3.7

steps:
- checkout
- restore_cache:
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-test-3.9
- run: env/bin/pip install wheel twine
- run: env/bin/python setup.py sdist bdist_wheel

- restore_cache: *restore-cache-env

- run: *create-virtualenv

- run: *install-requirements

- save_cache: *save-cache-env

- run: *build-package

- store_artifacts:
path: dist
- run: env/bin/twine upload -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD" --skip-existing ./dist/*
path: ./dist

- run:
name: Upload package to PyPI
command: env/bin/twine upload -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD" --skip-existing ./dist/*


workflows:
version: 2
test:
jobs:
- test-3.9
- test-3.8
- test-3.7
- test-3.6
- test-osx-3.9
- test-osx-3.8
- test-osx-3.7
- test-osx-3.6
- test-linux:
name: test-linux-py<< matrix.python-version >><<# matrix.dimod-version >>-dimod<< matrix.dimod-version >><</ matrix.dimod-version >>
matrix:
parameters:
python-version: &python-versions ["3.6.12", "3.7.9", "3.8.6", "3.9.0"]
dimod-version: ["~=0.8.0,>=0.8.11", "~=0.9.0", "~=0.10.0,>0.10.4"]

- test-macos:
name: test-macos-py<< matrix.python-version >>
matrix:
parameters:
python-version: *python-versions
xcode: ["12.3.0"]

- test-docs

deploy:
jobs:
- test-3.8:
filters:
tags:
only: /^[0-9]+(\.[0-9]+)*(\.dev([0-9]+)?)?$/
branches:
ignore: /.*/
- pypi-deploy:
requires:
- test-3.8
filters:
tags:
only: /^[0-9]+(\.[0-9]+)*(\.dev([0-9]+)?)?$/
only: /^[0-9]+(\.[0-9]+)*((\.dev|rc)([0-9]+)?)?$/
branches:
ignore: /.*/
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sphinx
sphinx>=4.0.0,<5.0.0
sphinx_rtd_theme
recommonmark
9 changes: 5 additions & 4 deletions hybrid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def bqm_induced_by(bqm, variables, sample):
subbqm.add_variable(u, bias)

# no point in having offset since we're fixing only variables on boundary
subbqm.remove_offset()
subbqm.offset = 0

return subbqm

Expand All @@ -178,8 +178,9 @@ def bqm_edges_between_variables(bqm, variables):

>>> import dimod
>>> bqm = dimod.BQM({}, {(0, 1): 1, (1, 2): 1, (2, 3): 1}, 0, 'BINARY')
>>> bqm_edges_between_variables(bqm, {0, 1, 3})
[(0, 1), (0, 0), (1, 1), (3, 3)]
>>> edges = bqm_edges_between_variables(bqm, {0, 1, 3})
>>> edges # doctest: +SKIP
[(0, 1), (0, 0), (1, 1), (3, 3)] # note: order not defined

"""
variables = set(variables)
Expand Down Expand Up @@ -598,7 +599,7 @@ def hstack_samplesets(base, *others, **kwargs):
# copy over samplesets, one by one, from left to right
for ss in samplesets:
ss.change_vartype(vartype)
mask = [variables.index[v] for v in ss.variables]
mask = [variables.index(v) for v in ss.variables]
samples[:, mask] = ss.record.sample[:num_samples]

if bqm is None:
Expand Down
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
dimod>=0.9.11
dimod==0.10.6
numpy>=1.19.4
minorminer>=0.2.0
dwave-system>=1.0.0
dwave-neal>=0.5.1
dwave-tabu>=0.4.0
dwave-greedy>=0.2.0
minorminer==0.2.6
dwave-system==1.8.0
dwave-neal==0.5.8
dwave-tabu==0.4.2
dwave-greedy==0.2.1
networkx
dwave-networkx>=0.8.6
dwave-networkx==0.8.9
click
plucky>=0.4.3
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

# Package requirements, minimal pinning
install_requires = ['numpy>=1.15.0', 'networkx', 'click>5', 'plucky>=0.4.3',
'dimod>=0.8.11', 'minorminer>=0.1.7', 'dwave-networkx>=0.6.6',
'dwave-system>=0.7.6', 'dwave-neal>=0.5.1', 'dwave-tabu>=0.2.0',
'dwave-greedy>=0.1.0']
'dimod>=0.8.11,<0.11,!=0.10.0,!=0.10.1,!=0.10.2,!=0.10.3,!=0.10.4',
'minorminer>=0.1.7', 'dwave-networkx>=0.6.6', 'dwave-system>=0.7.6',
'dwave-neal>=0.5.1', 'dwave-tabu>=0.2.0', 'dwave-greedy>=0.1.0']

# Package extras requirements
extras_require = {
Expand Down