-
Notifications
You must be signed in to change notification settings - Fork 16
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
Move in more preprocessing composites #7
Conversation
hhtong
commented
May 11, 2021
- rename fix_variables() to roof_duality() and move to new lower_bounds module
- move in more preprocessing composites (ClipComposite, ConnectedComponentsComposite, FixVariablesComposite, ScaleComposite, and SpinReversalTransformComposite)
- remove RoofDualityComposite and move functionality into an option in FixVariablesComposite
|
||
from dwave.preprocessing.cyfix_variables import fix_variables_wrapper | ||
|
||
def fix_variables(bqm, *, strict=True): | ||
def roof_duality(bqm, *, strict=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have spoken with @amahmudwave , who will expose the lower bound after this PR gets merged
|
||
""" | ||
|
||
def __init__(self, child_sampler, *, fixed_variables=None, algorithm=None, strict=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is too specialized, and we'll have to break it the very next time we add an algorithm.
I propose:
def __init__(self, child_sampler, *, fixed_variables=None, algorithm=None, strict=True): | |
def __init__(self, child_sampler: dimod.Sampler, *, algorithm: str = 'explicit', params: Optional[dict] = None): | |
self._algorithm = algorithm | |
self._params = params | |
self._algorithms = <map of callables> |
and then for sampling:
def sample(self, bqm, **parameters):
algo = self._algorithm[self._algorithm](**self._params)
return algo(bqm, **parameters)
So params can be specified per algorithm. For algorithm == 'explicit'
, param could be assignments
, and for algorithm == 'roof_duality'
, we'd use strict
.
The above is just a sketch, and we might want to use Enum instead of string for algorithm, and name variables differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, we can specify algorithm
in __init__
and then algorithm parameters as parameters of the sample
method.
In that case, we would have to (dynamically) set composite's parameters on init, depending on the chosen algorithm.
Makes sense, but I'm not sure how well it fits in dimod's composite framework. @arcondello, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me. The main assumption is that we treat it as immutable once it's instantiated. Though of course there are exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in latest commit to specifying algorithm
in __init__
and the rest of the parameters in **parameters
of .sample()
. I'm not entirely certain that the way I'm handling the parameters property is correct though. I also kept algorithm
as a string for now (I imagine this will become a callable later on, once we've finalized how roof_duality()
works)
I can return a lower bound but it will be subject to numerical errors, since floats are getting converted to llint and then back to float again. So it will be off by a small amount. Are there tests to validate the numbers that I will return with a tolerance for such discrepancy ? Oh I realize, the question may not be relevant to this PR :), nevermind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!