Expand dimod.make_quadratic documentation#1415
Expand dimod.make_quadratic documentation#1415iamashwin99 wants to merge 6 commits intodwavesystems:mainfrom
Conversation
Added notes on variable types in make_quadratic function.
There was a problem hiding this comment.
Pull request overview
This pull request expands the documentation for the dimod.make_quadratic function by adding explanatory notes about variable types and example output to help users better understand the function's behavior.
Changes:
- Added a Notes section explaining the three types of variables that appear in the reduced quadratic model (original, product, and auxiliary variables)
- Added example output showing the BinaryQuadraticModel representation returned by the function
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
JoelPasvolsky
left a comment
There was a problem hiding this comment.
Thank you for contributing to the Ocean SDK, @iamashwin99.
The comments below are to keep your additions aligned with Ocean formatting, remove trailing whitespaces, and return a shorter, more easily parsable result.
| >>> bqm | ||
| BinaryQuadraticModel({0: -3.5, 1: -1.5, '0*1': -2.5, 'aux0,1': -5.0, 2: 1.5}, {(1, 0): 1.5, ('0*1', 0): 2.5, ('0*1', 1): 2.5, ('aux0,1', 0): 5.0, ('aux0,1', 1): 5.0, ('aux0,1', '0*1'): 5.0, (2, '0*1'): -2.0}, 10.0, 'SPIN') |
There was a problem hiding this comment.
| >>> bqm | |
| BinaryQuadraticModel({0: -3.5, 1: -1.5, '0*1': -2.5, 'aux0,1': -5.0, 2: 1.5}, {(1, 0): 1.5, ('0*1', 0): 2.5, ('0*1', 1): 2.5, ('aux0,1', 0): 5.0, ('aux0,1', 1): 5.0, ('aux0,1', '0*1'): 5.0, (2, '0*1'): -2.0}, 10.0, 'SPIN') | |
| >>> list(bqm.variables) | |
| [0, 1, '0*1', 'aux0,1', 2] |
More readable and short.
There was a problem hiding this comment.
I think the full bqm would be a better description. It would also give hint about how the auxiliary qubits are generated. What do you think?
There was a problem hiding this comment.
Unless it provides high value to users (e.g., a list of parameters, typical timing), we try to avoid long outputs because they're not easy to parse, make the example look daunting, and can require maintenance (e.g., the recent backward-incompatible NumPy update that changes formats). My thinking is that such a short example lets users easily copy & paste so those who want to see the exact BQM structure can do so without difficulty. The list output highlights the generated variables you describe and additional, more robust ways to provide an output with more information could be
>>> len(bqm.linear) + len(bqm.quadratic)
12
or
>>> print(bqm.to_polystring())
10 - 3.5*v0 - 1.5*v1 - 2.5*0*1 - 5*aux0,1 + 1.5*v2 + 1.5*v0*v1 + 2.5*v0*0*1 + 2.5*v1*0*1 + 5*v0*aux0,1 + 5*v1*aux0,1 + 5*0*1*aux0,1 - 2*0*1*v2
and even for the latter, preferably shorten it with ellipses for readability, something perhaps like:
>>> print(bqm.to_polystring())
10 - ... 2.5*0*1 - 5*aux0,1 + ... 2.5*v1*0*1 + 5*v0*aux0,1 + 5*v1*aux0,1 + ...
Can one of these or another robust & short output do most of the work? If yes, that would be preferable. Thank you!
Co-authored-by: Joel Pasvolsky <34041130+JoelPasvolsky@users.noreply.github.com>
Co-authored-by: Joel Pasvolsky <34041130+JoelPasvolsky@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.