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

Add labels keyword argument to CQM.iter_constraint_data() #1382

Conversation

arcondello
Copy link
Member

See #1381. This addresses one of the options laid out.

Copy link

codecov bot commented Aug 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.69%. Comparing base (8356883) to head (4f88900).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1382      +/-   ##
==========================================
- Coverage   94.83%   93.69%   -1.14%     
==========================================
  Files          98       84      -14     
  Lines       10427     7359    -3068     
==========================================
- Hits         9888     6895    -2993     
+ Misses        539      464      -75     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@thisac thisac 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 minor comments; other than that LGTM.

def iter_constraint_data(self,
sample_like: SamplesLike,
*,
labels: typing.Optional[typing.Iterable[typing.Hashable]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

The types seem to already be imported.

Suggested change
labels: typing.Optional[typing.Iterable[typing.Hashable]] = None,
labels: Optional[Iterable[Hashable]] = None,

Copy link
Member Author

Choose a reason for hiding this comment

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

I am deliberately using the fully qualified typing. At some point I'll go through this and remove all of those names imported into the namespace and replace them with typing. but for now I wanted to minimize changes. I suppose there is an argument for local consistency, but 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. I guess both is fine, although I generally find using typing. everywhere makes the types less legible, although there are benefits to it as well. Python's typing system could definitely be better.

Copy link
Member Author

@arcondello arcondello Aug 2, 2024

Choose a reason for hiding this comment

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

I agree it's more cluttered visually. But I (personally) prefer cluttered signatures to a cluttered namespace. Determining what's a local symbol vs an imported one is much nicer with the qualified names. With typing most folks probably know which is which, but I prefer to be explicit when possible.

@@ -1219,6 +1233,7 @@ def iter_constraint_data(self, sample_like: SamplesLike) -> Iterator[ConstraintD
def iter_violations(self, sample_like: SamplesLike, *,
skip_satisfied: bool = False,
clip: bool = False,
labels: typing.Optional[typing.Iterable[typing.Hashable]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
labels: typing.Optional[typing.Iterable[typing.Hashable]] = None,
labels: Optional[Iterable[Hashable]] = None,

@@ -1153,6 +1157,7 @@ def iter_constraint_data(self, sample_like: SamplesLike) -> Iterator[ConstraintD
Args:
sample_like: A sample. `sample-like` is an extension of
NumPy's array_like structure. See :func:`.as_samples`.
labels: A subset of the constraint labels over which to iterate.
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth mentioning that the constraints will be yielded in the same ordering as the labels passed, instead of in order of addition which I presume is the case without a labels subset request.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am being deliberately ambiguous in case we want to change the behavior later.

@arcondello arcondello merged commit 4d3e6f8 into dwavesystems:main Aug 2, 2024
37 checks passed
@arcondello arcondello deleted the feature/iter_constraint_data-filtering branch August 2, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants