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

Use class vartype for default constraint vartype, not binary #112

Open
JoelPasvolsky opened this issue May 27, 2021 · 0 comments
Open

Use class vartype for default constraint vartype, not binary #112

JoelPasvolsky opened this issue May 27, 2021 · 0 comments

Comments

@JoelPasvolsky
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant