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

LinearEqualityToPenalty converter: accept list of penalty terms as input #14

Open
HassanNaseri opened this issue Sep 30, 2020 · 8 comments
Assignees

Comments

@HassanNaseri
Copy link

Requested Feature

LinearEqualityToPenalty converter only accepts a single scalar input as penalty factor. Better results can be usually obtained by applying higher penalty factors to broken constraints. This requires LinearEqualityToPenalty to accept a list of penalty terms as input, including separate penalty factor for each constraint. If user provides none or a single value for penalty, the already existing process can be followed.

Why?

Once a solution is obtained, it is easy to evaluate the constraints and find the broken ones. Then the penalty terms for those broken constraints can be increased and the problem can be solved again. In the future, Qiskit may implement checking for broken constraints, but for time being this can be done by the user. Anyhow, having a list of penalties as input is mandatory for any iterative tuning.

@TDHTTTT
Copy link

TDHTTTT commented Oct 8, 2020

Can I work on this?

@TDHTTTT
Copy link

TDHTTTT commented Oct 8, 2020

Just to clarify, when the user provides a single value for penalty, should they use float or a a list with one float or it doesn't matter?

@a-matsuo
Copy link
Contributor

a-matsuo commented Oct 8, 2020

Sure. If you can help us, that would be great. It doesn't matter that much, but just a single float seems more reasonable.

@HassanNaseri
Copy link
Author

HassanNaseri commented Oct 8, 2020

I agree that single float is better. It will be then backwards compatible. I added the following code to convert function (not committed) to create the list when it does not exist. It supports both a single float and a list with single value. You may use a similar approach or something better.

    # Create penalties list if a single penalty value is given
    num_constraint = len(self._src.linear_constraints)
    if not hasattr(penalty, "__len__"):
        penalty = [penalty] * num_constraint
    elif len(penalty) == 1:
        penalty = [penalty[0]] * num_constraint
    # Check the length of penalties list
    if len(penalty) != num_constraint:
        raise QiskitOptimizationError('Penlaty vector length does not match the number of constraints.')

TDHTTTT referenced this issue in TDHTTTT/qiskit-aqua Oct 8, 2020
…of penalty terms (#1294)

* now penalty can either be a single float (backward compatible) or a list of float that applies to linear constraints correspondingly
* updated docstring for the change
@TDHTTTT
Copy link

TDHTTTT commented Oct 8, 2020

Hey @a-matsuo @HassanNaseri could you guys take a look at qiskit-community/qiskit-aqua#1322? Thanks!

@woodsp-ibm woodsp-ibm transferred this issue from qiskit-community/qiskit-aqua Jan 26, 2021
@a-matsuo
Copy link
Contributor

@TDHTTTT @HassanNaseri
I forgot about this issue and the PR, qiskit-community/qiskit-aqua#1322. Is the PR ready? If so, can you make a PR in this qiskit-optimization as well?

@a-matsuo
Copy link
Contributor

@TDHTTTT @HassanNaseri
Are you guys still interested in this issue?

@HassanNaseri
Copy link
Author

@a-matsuo I am interested. I am already using the feature on my local copy of qiskit. This is a minor change that got complicated. @TDHTTTT can you make a new PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants