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

embed_bqm silently assumes that chain_strength is a positive number #527

Open
pau557 opened this issue Jul 30, 2024 · 3 comments
Open

embed_bqm silently assumes that chain_strength is a positive number #527

pau557 opened this issue Jul 30, 2024 · 3 comments

Comments

@pau557
Copy link
Contributor

pau557 commented Jul 30, 2024

target_bqm.add_quadratic_from((p, q, -strength) for p, q in self.chain_edges(v))
offset += strength * len(self._chain_edges[v])
else: # if smear_vartype is dimod.BINARY
target_bqm.add_variables_from((p, 2 * strength) for p in itertools.chain(*self.chain_edges(v)))
target_bqm.add_quadratic_from((p, q, -4 * strength) for p, q in self.chain_edges(v))

embed_bqm assumes a positive sign for chain_strength:

import networkx as nx
from dwave.embedding import embed_bqm
import dimod

g = nx.Graph()
g.add_edge(100, 101)
bqm = dimod.BQM.from_ising({1: 0}, {})
emb = {1: [100, 101]}

for chain_strength in [-2, 2]:
    print(
        embed_bqm(bqm, embedding=emb, target_adjacency=g, chain_strength=chain_strength).quadratic
    )

Output:

{(101, 100): 2.0}
{(101, 100): -2.0}

The parameter is described as "coupling strength". I would expect that it either

  1. Applies the sign passed (your sampler could be a maximizer)
  2. Assumes minimization: It accepts any number and enforces the sign by taking abs of the input.

The current scheme where the sign is flipped is unexpected

@pau557 pau557 changed the title embed_bqm silently assumes chain strength to be a positive number embed_bqm silently assumes that chain_strength is a positive number Jul 30, 2024
@arcondello
Copy link
Member

I think silently correcting it would be the more unexpected behavior. So IMO the current behavior, while slightly strange, is consistent and easy to explain. So if we were to make a change, it would be to raise an error.

@pau557
Copy link
Contributor Author

pau557 commented Jul 30, 2024

In that case, the docstring should explain that the embedded chain coupler will be -1 * chain_strength

@arcondello
Copy link
Member

Agreed. Want to make the PR?

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

2 participants