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

More Elegant Fail for Cases with No Quadratic Biases #97

Open
m3ller opened this issue Jul 23, 2019 · 0 comments
Open

More Elegant Fail for Cases with No Quadratic Biases #97

m3ller opened this issue Jul 23, 2019 · 0 comments

Comments

@m3ller
Copy link
Contributor

m3ller commented Jul 23, 2019

Current Problem
When no quadratic biases are present in a penaltymodel, return an error that is more comprehensible to the end user. (Note: end user is likely to be calling the penaltymodel from stitch(..) and may not be able to understand the error from so deep in the penaltymodel stack)

import dwavebinarycsp as dbc
csp = dbc.ConstraintSatisfactionProblem(dbc.BINARY)                                     
csp.add_constraint(lambda x: x>0, ['a'])                                                
bqm = dbc.stitch(new_csp, min_classical_gap=3)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-35-25eb8a1c9af4> in <module>
----> 1 new_bqm = dbc.stitch(new_csp, min_classical_gap=3)

~/envs/ocean3/lib/python3.7/site-packages/dwavebinarycsp/compilers/stitcher.py in stitch(csp, min_classical_gap, max_graph_size)
    177             # try to use the penaltymodel ecosystem
    178             try:
--> 179                 pmodel = pm.get_penalty_model(spec)
    180             except pm.ImpossiblePenaltyModel:
    181                 # hopefully adding more variables will make it possible

~/envs/ocean3/lib/python3.7/site-packages/penaltymodel/core/interface.py in get_penalty_model(specification)
     68         # asynchronously
     69         for cache in iter_caches():
---> 70             cache(pm)
     71 
     72         return pm

~/envs/ocean3/lib/python3.7/site-packages/penaltymodel/cache/interface.py in cache_penalty_model(penalty_model, database)
     94     # load into the database
     95     with conn as cur:
---> 96         insert_penalty_model(cur, penalty_model)
     97 
     98     # close the connection

~/envs/ocean3/lib/python3.7/site-packages/penaltymodel/cache/database_manager.py in insert_penalty_model(cur, penalty_model)
    478     insert_graph(cur, nodelist, edgelist, encoded_data)
    479     insert_feasible_configurations(cur, penalty_model.feasible_configurations, encoded_data)
--> 480     insert_ising_model(cur, nodelist, edgelist, linear, quadratic, offset, encoded_data)
    481 
    482     encoded_data['decision_variables'] = json.dumps(penalty_model.decision_variables, separators=(',', ':'))

~/envs/ocean3/lib/python3.7/site-packages/penaltymodel/cache/database_manager.py in insert_ising_model(cur, nodelist, edgelist, linear, quadratic, offset, encoded_data)
    277         encoded_data['offset'] = offset
    278     if 'max_quadratic_bias' not in encoded_data:
--> 279         encoded_data['max_quadratic_bias'] = max(itervalues(quadratic))
    280     if 'min_quadratic_bias' not in encoded_data:
    281         encoded_data['min_quadratic_bias'] = min(itervalues(quadratic))

ValueError: max() arg is an empty sequence

Proposed Solution
Catch the case when no quadratics are provided.

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

1 participant