-
Notifications
You must be signed in to change notification settings - Fork 83
Open
Labels
Description
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