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

dqm.adj fails when interactions exist #1329

Open
JoelPasvolsky opened this issue May 17, 2023 · 0 comments
Open

dqm.adj fails when interactions exist #1329

JoelPasvolsky opened this issue May 17, 2023 · 0 comments
Labels

Comments

@JoelPasvolsky
Copy link
Contributor

Description
DQM's adj property only works when all interactions are zero.

Steps To Reproduce

  • Fails:
>>> dqm = dimod.DiscreteQuadraticModel()
>>> dqm.add_variable(2)
>>> dqm.add_variable(2)
>>> dqm.set_linear(0, [1, -1])         # optional
>>> dqm.set_linear(1, [0.5, -0.5])    # optional
>>> dqm.adj
{0: {}, 1: {}}
>>> dqm.set_quadratic(0, 1, [[2, 3], [0, 0]])
>>> dqm.adj
TypeError: cannot convert dictionary update sequence element #0 to a sequence
  • Produces garbage:
>>> provinces = ["AB", "BC", "ON", "MB", "NB", "NL", "NS", "NT", "NU",  "PE", "QC", "SK", "YT"]
>>> borders = [("BC", "AB"), ("BC", "NT"), ("BC", "YT"), ("AB", "SK"), ("AB", "NT"), ("SK", "MB"), ("SK", "NT"), ("MB", "ON"),          ("MB", "NU"), ("ON", "QC"), ("QC", "NB"), ("QC", "NL"), ("NB", "NS"), ("YT", "NT"), ("NT", "NU")]
>>> colors = [0, 1, 2, 3]
>>> dqm = dimod.DiscreteQuadraticModel()
>>>for p in provinces:
...        _ = dqm.add_variable(4, label=p)
>>> for p0, p1 in borders:
...       dqm.set_quadratic(p0, p1, {(c, c): 1 for c in colors})
>>> dqm.adj
{'AB': {'B': 'C', 'N': 'T', 'S': 'K'}, 'BC': {'A': 'B', 'N': 'T', 'Y': 'T'}, 'ON': {'M': 'B', 'Q': 'C'}, 'MB': {'O': 'N', 'N': 'U', 'S': 'K'}, 'NB': {'N': 'S', 'Q': 'C'}, 'NL': {'Q': 'C'}, 'NS': {'N': 'B'}, 'NT': {'A': 'B', 'B': 'C', 'N': 'U', 'S': 'K', 'Y': 'T'}, 'NU': {'M': 'B', 'N': 'T'}, 'PE': {}, 'QC': {'O': 'N', 'N': 'L'}, 'SK': {'A': 'B', 'M': 'B', 'N': 'T'}, 'YT': {'B': 'C', 'N': 'T'}}

Expected Behavior
If we don't support printing adj for DQM, remove the property

Environment

  • OS: Unix, WIN
  • Python version: 3.10.2

Additional Context
I don't remember if this worked in the past or not

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

No branches or pull requests

1 participant