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

Relabeling creates inconsistent BQMs #1110

Closed
JoelPasvolsky opened this issue Feb 11, 2022 · 1 comment · Fixed by #1111
Closed

Relabeling creates inconsistent BQMs #1110

JoelPasvolsky opened this issue Feb 11, 2022 · 1 comment · Fixed by #1111
Labels

Comments

@JoelPasvolsky
Copy link
Contributor

Description
Relabeling can create BQMs that are inconsistent with generated BQMs:

>>>  bqm = dimod.BinaryQuadraticModel({'a': 1, 'b': 2}, {('a', 'b'): 1.5}, 'BINARY')
>>> bqm.relabel_variables({'a': 'c', 'b': 'c'})
>>> print(bqm.linear, bqm.quadratic)
{'c': 2.0, 'c': 2.0} {('c', 'c'): 1.5}

In comparison:

>>> bqm = dimod.BinaryQuadraticModel({'c': 1, 'c': 2}, {('c', 'c'): 1.5}, 'BINARY')
>>> print(bqm.linear, bqm.quadratic)
{'c': 3.5} {}

Expected Behavior
Consistent treatment of a variable set in multiple places. For the given example, it's noticeable, but in relabeling large numbers of variables in a big BQM, this might not end well

Environment
dimod version here is 0.10.10

@arcondello
Copy link
Member

arcondello commented Feb 11, 2022

Also {'c': 1, 'c': 2} in your second example is just {'c': 2}. You can get something similar to what you're looking for with bqm.contract_variables('a', 'b').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants