Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Constrained minimizer #258
base: main
Are you sure you want to change the base?
Constrained minimizer #258
Changes from 1 commit
ac84aa5
8bb6216
b575738
90d10db
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
What is the difference between the constraint to the cost? Should we minimize both of them? Maybe the constraint should be a Boolean function meaning that it returns true or false?
Should add more comments about what type of constraints can be implemented.
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.
The
cstr
cost function will almost always be a unitary distance/fidelity based cost, while thecost
cost function quantifies some desirable quality of the output circuit to optimize (i.e. it will not be distance based).The choice to minimize them both comes from the general form of constrained optimization problems. It still makes sense to use a scalar valued cost for the constraint because it's likely we would want to know how far off from being constrained a solution is (or if we want to shift some success threshold).
I've added some details in the docstring about what the constraint should look like. The cost function is left more open ended.
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.
I'm sorry, I'm still confused.
This abstract function tries to minimize the cost, the constraint, or both?
I assume both, but then why would one want two different cost functions to minimize? do they have different weights? why not combine them into a single cost function?
When you say "satisfying some 'constraint' CostFunction" it means that it is a boolean function (you can have a distance with a threshold, that will create a boolean value...)
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.
I'd like to preface by saying that these design choices are based on how off the shelf constrained optimizers work. The wikipedia page on the KKT conditions and the documentation for scipy are good reads for this.
The cost is minimized given that some constraint inequality is satisfied (i.e.
(cstr(x) - epsilon) <= 0
). The cost and constraint functions are likely to check for very different things, so from an interpretability standpoint it does not make sense to combine them at this level. Also, they are combined into one cost function under the hood but this is the responsibility of the actual optimizer used, not theConstrainedMinimizer
class. Combining them here means that off the shelf constrained optimizers cannot be used.While satisfying constraints does mean passing some boolean condition, treating them as discrete tests means we can't apply optimization tools that expect continuous and differentiable functions (which is an expectation of most constrained optimizers).
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.
I see, so how does the user specifies the constraint inequality ? in the scipy documentation there is an upper and a lower bound. Do you think there should one here as well?
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's a good point. It's not passed here because it fits better with how the
Minimizer.minimize
function call looks. In the current implementation, actual instances of theConstrainedMinimizer
have the success threshold as a parameter in__init__
. There are different ways to pass the success threshold given the optimizer, so I think handling this internally still makes sense.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.
If it makes a difference, I think keeping the instantiation API open for now is valuable. So if you think there is a modification to Minimizer API that makes better sense, we should discuss it.