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

Fix/reduce order #76

Merged
merged 5 commits into from
Oct 14, 2020
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ To run all tests with unittest, execute

.. code-block:: shell

python -m unittest discover test
python -m unittest discover tests

To generate coverage reports, execute

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
author = u'Author'

# The short X.Y version
version = u'0.1'
version = u'1.0'
# The full version, including alpha/beta/rc tags
release = u'0.0.1'
release = u'1.0.5'


# -- General configuration ---------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion pyqubo/integer/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import abc
import six
from cpp_pyqubo import UserDefinedExpress, WithPenalty


Expand Down
2 changes: 1 addition & 1 deletion pyqubo/package_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# (major, minor, patch, prerelease)

VERSION = (1, 0, 4, "")
VERSION = (1, 0, 5, "")
__shortversion__ = '.'.join(map(str, VERSION[:3]))
__version__ = '.'.join(map(str, VERSION[:3])) + "".join(VERSION[3:])

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def run(self):
'numpy>=1.16.0,<2.0.0',
'dimod>=0.9.2',
'dwave-neal>=0.5.4',
'Deprecated>=1.2.10'
'Deprecated>=1.2.10',
'six>=1.11.0'
]

python_requires = '>=3.5'
Expand Down
7 changes: 1 addition & 6 deletions src/reduce_order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ namespace reduce_order{
void add_term(Terms* terms, Prod prod, CoeffPtr coeff){
auto result = terms->find(prod);
if(result == terms->end()){
//terms->at(prod) = coeff;
terms->insert(TermsPair{prod, coeff});
}else{
//terms->at(prod) = coeff->add(result->second);
//terms->insert(TermsPair{prod, coeff->add(result->second)});
result->second = coeff->add(result->second);
}
}
Expand Down Expand Up @@ -71,9 +68,7 @@ namespace reduce_order{
}

void replace_variable(Poly* mp, QuboIndex index_pair, int new_variable){
int loop_cnt = 0;
for(auto it = mp->terms->begin(); it != mp->terms->end(); it++){
loop_cnt++;
Prod prod = it->first;
CoeffPtr coeff = it->second;
bool first_in, second_in = false;
Expand All @@ -82,7 +77,7 @@ namespace reduce_order{
if(prod.get_var(i) == index_pair.second) second_in = true;
}
if(first_in && second_in){
uint32_t indices[4] = {0};
uint32_t* indices = new uint32_t[it->first.length+1];
int index = 0;
for(int i=0; i < it->first.length; i++){
if(prod.get_var(i) != index_pair.first && prod.get_var(i) != index_pair.second){
Expand Down
89 changes: 0 additions & 89 deletions tests/_test_main.py

This file was deleted.

3 changes: 1 addition & 2 deletions tests/test_express.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def test_compile_subh(self):
self.compile_check(exp, expected_qubo, expected_offset, feed_dict)

def test_compile_constraint(self):
import dimod
a, b, c = Binary("a"), Binary("b"), Binary("c")
exp = Constraint(a*b*c, label="constraint")
expected_qubo = {('a', '0*1'): -10.0, ('b', '0*1'): -10.0, ('0*1', '0*1'): 15.0, ('a', 'a'): 0.0, ('a', 'b'): 5.0, ('c', '0*1'): 1.0, ('b', 'b'): 0.0, ('c', 'c'): 0.0}
Expand All @@ -126,6 +125,6 @@ def __init__(self, hamiltonian, penalty, label):
expected_offset = 0.0
feed_dict={"p": 2}
self.compile_check(custom_penalty, expected_qubo, expected_offset, feed_dict)

if __name__ == '__main__':
unittest.main()
16 changes: 16 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ def test_constraint(self):
if sol.energy==1.0:
self.assertEqual(sol.subh['C1'], 1.0)

def test_higher_order(self):
x = Array.create('x', 5, 'BINARY')
exp = x[0]*x[1]*x[2]*x[3]
model = exp.compile(strength=10)

sample = {'x[0]': 1, 'x[1]': 1, 'x[2]': 1, 'x[3]': 1, '0*1': 1, '2*3': 1}
e = model.energy(sample, vartype='BINARY')
self.assertEqual(e, 1.0)

sample = {'x[0]': 0, 'x[1]': 1, 'x[2]': 1, 'x[3]': 1, '0*1': 0, '2*3': 1}
e = model.energy(sample, vartype='BINARY')
self.assertEqual(e, 0.0)

sample = {'x[0]': 1, 'x[1]': 1, 'x[2]': 1, 'x[3]': 1, '0*1': 0, '2*3': 1}
e = model.energy(sample, vartype='BINARY')
self.assertEqual(e, 10.0)

if __name__ == '__main__':
unittest.main()