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

Adding the unbalanced penalization method #1347

Merged

Conversation

alejomonbar
Copy link
Contributor

@alejomonbar alejomonbar commented Jun 29, 2023

Following a recent thread about the unbalanced penalization method to encode inequality constraints. #1339.

lagrange_multiplier = [1,1]
bqm = BinaryQuadraticModel("BINARY")
for i in range(qubits):
    bqm.add_linear(f"x_{i}", 1)
terms = [(f"x_{i}", 4) for i in range(qubits)]
bqm.add_linear_inequality_constraint(terms, lagrange_multiplier,
                                     label, ub=5, penalization_method="unbalanced")
bqm.to_ising()

Still is left to implement the test, but I want to know if the structure is ok @arcondello?

Following recent thread about the unbalanced penalization equation to encode inequality constraints. dwavesystems#1339
@arcondello
Copy link
Member

Structure looks good! As you say, needs some tests and a release note, but I like the direction.

@arcondello arcondello self-requested a review June 30, 2023 15:19
@arcondello arcondello added the feature-request/enhancement New feature or request label Jun 30, 2023
@codecov
Copy link

codecov bot commented Jul 26, 2023

Codecov Report

Merging #1347 (a2668cb) into main (e5a8e3b) will decrease coverage by 0.02%.
Report is 2 commits behind head on main.
The diff coverage is 93.54%.

@@            Coverage Diff             @@
##             main    #1347      +/-   ##
==========================================
- Coverage   95.08%   95.06%   -0.02%     
==========================================
  Files          95       95              
  Lines        9902     9912      +10     
==========================================
+ Hits         9415     9423       +8     
- Misses        487      489       +2     
Files Changed Coverage Δ
dimod/binary/binary_quadratic_model.py 92.96% <93.54%> (-0.15%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@alejomonbar alejomonbar marked this pull request as ready for review July 26, 2023 09:43
@alejomonbar
Copy link
Contributor Author

Structure looks good! As you say, needs some tests and a release note, but I like the direction.

@arcondello please let me know what you think of how it is now.

Copy link
Member

@arcondello arcondello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few aesthetic comments

cross_zero: bool = False,
penalization_method: str = "slack",
) -> Iterable[Tuple[Variable, int]]:
"""Add a linear inequality constraint as a quadratic objective.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like everything got indented by an additional tab?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it! @arcondello

lb: int = np.iinfo(np.int64).min,
ub: int = 0,
cross_zero: bool = False,
penalization_method: str = "slack",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
penalization_method: str = "slack",
penalization_method: typing.Literal["slack", "unbalanced"] = "slack",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @arcondello

Copy link
Member

@arcondello arcondello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I took the liberty of making some minor edits to the release note to fit some esoteric formatting rules. I'll merge once the CI tests pass

@arcondello arcondello merged commit 06f6ab6 into dwavesystems:main Aug 17, 2023
31 checks passed
@alejomonbar
Copy link
Contributor Author

@arcondello I'm thinking I can also add a tutorial for this new feature. Do you know where can I put that tutorial?

@arcondello
Copy link
Member

How big of a tutorial did you have in mind? If it's something short and simple, then the docstring of modified method is definitely the easiest.

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

Successfully merging this pull request may close these issues.

None yet

2 participants