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

Consider adding a method that measures the "frustration" of a BQM #1369

Open
arcondello opened this issue Mar 21, 2024 · 0 comments
Open

Consider adding a method that measures the "frustration" of a BQM #1369

arcondello opened this issue Mar 21, 2024 · 0 comments
Labels
feature-request/enhancement New feature or request

Comments

@arcondello
Copy link
Member

"Frustration" is in some sense a measure of problem hardness. That is, what is the energy contribution of the linear and quadratic biases that are violated by a given solution.

Something like

import dimod

def frustration(bqm, sample):
    frustration = 0

    for v, bias in bqm.linear.items():
        frustration += max(0, sample[v] * bias)

    for (u, v), bias in bqm.quadratic.items():
        frustration += max(0, sample[u] * sample[v] * bias)
    
    return frustration

if __name__ == "__main__":
    bqm = dimod.generators.gnp_random_bqm(10, .5, "SPIN")
    sampleset = dimod.ExactSolver().sample(bqm)
    sample = sampleset.first.sample
    print("energy:", sampleset.first.energy)
    print("frustration:", frustration(bqm, sample))
@arcondello arcondello added the feature-request/enhancement New feature or request label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant