dwavebinarycsp
dwavebinarycsp copied to clipboard
Use class vartype for default constraint vartype, not binary
Application & Proposed Solution
When adding a constraint to a CSP class, it would be nice to default to the class's vartype rather than always use binary:
import dwavebinarycsp
In [2]: import dwavebinarycsp.factories.constraint.gates as gates
In [3]: csp = dwavebinarycsp.ConstraintSatisfactionProblem("SPIN")
In [4]: csp.add_constraint(gates.and_gate(['a', 'b', 'c'], name='AND'))
In [5]: csp.variables
Out[5]:
defaultdict(list,
{'a': [Constraint.from_configurations(frozenset({(1, 0, 0), (1, 1, 1), (0, 1, 0), (0, 0, 0)}), ('a', 'b', 'c'), Vartype.BINARY, name='AND')],
'b': [Constraint.from_configurations(frozenset({(1, 0, 0), (1, 1, 1), (0, 1, 0), (0, 0, 0)}), ('a', 'b', 'c'), Vartype.BINARY, name='AND')],
'c': [Constraint.from_configurations(frozenset({(1, 0, 0), (1, 1, 1), (0, 1, 0), (0, 0, 0)}), ('a', 'b', 'c'), Vartype.BINARY, name='AND')]})
In [6]: bqm = dwavebinarycsp.stitch(csp)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-190cd5489319> in <module>
----> 1 bqm = dwavebinarycsp.stitch(csp)
ValueError: feasible_configurations type must match vartype. feasible_configurations have values {0, 1}, values permitted by vartype are frozenset({1, -1}).
Additional Context
dimod==0.9.13
dwave-cloud-client==0.8.4
dwave-greedy==0.1.2
dwave-hybrid==0.6.1
dwave-inspector==0.2.5
dwave-neal==0.5.7
dwave-networkx==0.8.8
dwave-ocean-sdk==3.3.0
dwave-qbsolv==0.3.2
dwave-system==1.4.0
dwave-tabu==0.3.1
dwavebinarycsp==0.1.2
penaltymodel==0.16.4
penaltymodel-cache==0.4.3
penaltymodel-lp==0.1.4
penaltymodel-mip==0.2.4