Skip to content

Commit 432f9e6

Browse files
authored
Merge pull request #103 from arcondello/PresolveImpl-refactor-part2
Refactor presolve methods
2 parents 96463cb + 0bf2edf commit 432f9e6

13 files changed

Lines changed: 1136 additions & 400 deletions

File tree

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,24 +333,24 @@ workflows:
333333
matrix:
334334
parameters:
335335
# test the lowest and highest of each minor for the dependencies
336-
dimod-version: [==0.12.5, ~=0.12.0]
336+
dimod-version: [==0.12.6, ~=0.12.0]
337337
numpy-version: [==1.20.0, ~=1.23.0]
338338
python-version: *python-versions
339339
exclude:
340340
- numpy-version: ==1.20.0 # NumPy 1.20 does not support 3.10
341-
dimod-version: ==0.12.5
341+
dimod-version: ==0.12.6
342342
python-version: 3.10.0
343343
- numpy-version: ==1.20.0 # NumPy 1.20 does not support 3.10
344344
dimod-version: ~=0.12.0
345345
python-version: 3.10.0
346346
- numpy-version: ==1.20.0 # NumPy 1.20 does not support 3.11
347-
dimod-version: ==0.12.5
347+
dimod-version: ==0.12.6
348348
python-version: 3.11.0
349349
- numpy-version: ==1.20.0 # NumPy 1.20 does not support 3.11
350350
dimod-version: ~=0.12.0
351351
python-version: 3.11.0
352352
- numpy-version: ~=1.23.0 # NumPy 1.23 does not support 3.7
353-
dimod-version: ==0.12.5
353+
dimod-version: ==0.12.6
354354
python-version: 3.7.9
355355
- numpy-version: ~=1.23.0 # NumPy 1.23 does not support 3.7
356356
dimod-version: ~=0.12.0

dwave/preprocessing/include/dwave/flags.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@ enum Feasibility {
2727
enum TechniqueFlags : std::uint64_t {
2828
None = 0,
2929

30-
// todo: individual technique flags
30+
/// Remove redundant constraints.
31+
/// See Achterberg et al., section 3.1.
32+
RemoveRedundantConstraints = 1 << 0,
33+
34+
/// Remove small biases from the objective and constraints.
35+
/// See Achterberg et al., section 3.1.
36+
RemoveSmallBiases = 1 << 1,
37+
38+
/// Use constraints to tighten the bounds on variables.
39+
/// See Achterberg et al., section 3.2.
40+
DomainPropagation = 1 << 2,
3141

3242
All = 0xffffffffffffffffu,
3343

dwave/preprocessing/include/dwave/presolve.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class Presolver {
5252
/// This clears the model from the presolver.
5353
model_type detach_model();
5454

55+
const Feasibility& feasibility() const;
56+
5557
/// Load the default presolve techniques.
5658
void load_default_presolvers();
5759

dwave/preprocessing/libcpp.pxd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ cdef extern from "dwave/exceptions.hpp" namespace "dwave::presolve" nogil:
2222
pass
2323

2424
cdef extern from "dwave/flags.hpp" namespace "dwave::presolve" nogil:
25-
pass
25+
enum Feasibility:
26+
Unknown,
27+
Infeasible,
28+
Feasible
2629

2730
cdef extern from "dwave/presolve.hpp" namespace "dwave::presolve" nogil:
2831
cdef cppclass Presolver[bias_type, index_type, assignment_type]:
@@ -32,6 +35,7 @@ cdef extern from "dwave/presolve.hpp" namespace "dwave::presolve" nogil:
3235
Presolver(model_type)
3336
void apply() except+
3437
model_type detach_model()
38+
const Feasibility& feasibility() const
3539
void load_default_presolvers()
3640
model_type& model()
3741
vector[assignment_type] restore(vector[assignment_type])

dwave/preprocessing/presolve/cypresolve.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ from dimod.libcpp cimport ConstrainedQuadraticModel as cppConstrainedQuadraticMo
2727
from dimod.constrained.cyconstrained cimport cyConstrainedQuadraticModel, make_cqm
2828
from dimod.cyutilities cimport ConstNumeric
2929

30+
from dwave.preprocessing.libcpp cimport Feasibility as cppFeasibility
31+
3032
# We want to establish a relationship between presolveimpl.hpp and this file, so that
3133
# changes to presolveimpl.hpp will trigger a rebuild.
3234
cdef extern from "../src/presolveimpl.hpp" namespace "dwave::presolve" nogil:
@@ -61,6 +63,9 @@ cdef class cyPresolver:
6163
self.cpppresolver.apply()
6264
self._model_num_variables = self.cpppresolver.model().num_variables()
6365

66+
if self.cpppresolver.feasibility() == cppFeasibility.Infeasible:
67+
raise RuntimeError("infeasible")
68+
6469
def clear_model(self):
6570
"""Clear the held constrained quadratic model. This is useful to save memory."""
6671
self.cpppresolver.detach_model()

dwave/preprocessing/src/presolve.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ dimod::ConstrainedQuadraticModel<Bias, Index> Presolver<Bias, Index, Assignment>
4545
return impl_->detach_model();
4646
}
4747

48+
template <class Bias, class Index, class Assignment>
49+
const Feasibility& Presolver<Bias, Index, Assignment>::feasibility() const {
50+
return impl_->feasibility();
51+
}
52+
4853
template <class Bias, class Index, class Assignment>
4954
void Presolver<Bias, Index, Assignment>::load_default_presolvers() {
5055
impl_->techniques = TechniqueFlags::Default;

0 commit comments

Comments
 (0)