Skip to content

Add maximize to minimize converter#114

Merged
adekusar-drl merged 26 commits intoqiskit-community:mainfrom
tomtuamnuq:maxmin-conv
May 21, 2021
Merged

Add maximize to minimize converter#114
adekusar-drl merged 26 commits intoqiskit-community:mainfrom
tomtuamnuq:maxmin-conv

Conversation

@tomtuamnuq
Copy link
Copy Markdown
Contributor

@tomtuamnuq tomtuamnuq commented Apr 29, 2021

Summary

Adds Maximize To Minimize converter

Fixes #41

Details and comments

Introduces a new converter class MaximizeToMinimize for QuadraticProgram as described in #41 .
It converts a problem to a minimization problem. The converter is in the default converters list of OptimizationAlgorithm. Algorithms and QuadraticProgramToQubo are now using MaximizeToMinimize.

tomtuamnuq added 3 commits April 29, 2021 07:22
Many algorithms converted problems internally to minimization.
To avoid duplicate code MaximizeToMinimize converter is used now.
Since the internal problem is now minimization,
there are changes to the following results:

- intermediate_fval in GroverOptimizationResult is that of
the minimization QUBO.

- raw_results in OptimizationResult are those of the
the minimization QUBO.

- ADMM optimizer logs out the minimization objective values

samples in OptimizationResult are still that of the
original problem.

This solves issue qiskit-community#41
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 29, 2021

CLA assistant check
All committers have signed the CLA.

@tomtuamnuq
Copy link
Copy Markdown
Contributor Author

The installation of cvxpy by just using pip install qiskit-optimization[cvxpy] was not enough to set up the complete test on my local machine and I missed to check whether the tests were still skipped. Sorry for that.

I have checked the failed Unit Test: TestWarmStartQAOAOptimizer.test_max_cut
The problem is, that the presolver GoemansWilliamsonOptimizer is now getting a minimization qubo. Therefore, opt_result in https://github.com/Qiskit/qiskit-optimization/blob/3e21815034c72030eab17f2865895dc0d12076a4/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py#L294 is now

optimal function value: 0.0
optimal value: [0 0 0 0]
status: SUCCESS

Instead of
optimal function value: 4.0
optimal value: [0 1 1 0]
status: SUCCESS

This leads to a wrong result.

Maybe we should not add MaximizeToMinimize always to the default converters list in https://github.com/Qiskit/qiskit-optimization/blob/3e21815034c72030eab17f2865895dc0d12076a4/qiskit_optimization/algorithms/optimization_algorithm.py#L354

Then, we can alter the UnitTest to use a fixed List of converters(without MaximizeToMinimize) instead of the default list.

Maybe GoemansWilliamsonOptimizer should give a hint if it is used with a minimization problem?

Copy link
Copy Markdown
Member

@woodsp-ibm woodsp-ibm left a comment

Choose a reason for hiding this comment

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

Nice job for a first contribution! You have even done a reno yaml file, nice!

Comment thread qiskit_optimization/algorithms/admm_optimizer.py Outdated
Comment thread qiskit_optimization/algorithms/cobyla_optimizer.py Outdated
Comment thread qiskit_optimization/converters/maximize_to_minimize.py Outdated
Comment thread qiskit_optimization/converters/maximize_to_minimize.py Outdated
@t-imamichi t-imamichi requested a review from adekusar-drl April 30, 2021 00:47
Comment thread qiskit_optimization/algorithms/multistart_optimizer.py
Comment thread qiskit_optimization/algorithms/optimization_algorithm.py Outdated
Comment thread qiskit_optimization/converters/quadratic_program_to_qubo.py Outdated
Comment thread test/converters/test_converters.py Outdated
Comment thread test/converters/test_converters.py Outdated
@t-imamichi
Copy link
Copy Markdown
Collaborator

t-imamichi commented May 6, 2021

Could you apply black code formatter by black qiskit_optimization test.
We recently apply black to the entire code base. See #117 for details.

tomtuamnuq added 2 commits May 7, 2021 11:05
Use black formatter
Solve conflicts:

qiskit_optimization/algorithms/admm_optimizer.py
qiskit_optimization/algorithms/grover_optimizer.py
qiskit_optimization/algorithms/minimum_eigen_optimizer.py
qiskit_optimization/algorithms/multistart_optimizer.py
qiskit_optimization/algorithms/optimization_algorithm.py
qiskit_optimization/algorithms/slsqp_optimizer.py
test/converters/test_converters.py
@t-imamichi
Copy link
Copy Markdown
Collaborator

Sorry. Could format again by black -l 100? We added a missing config #118.

@t-imamichi
Copy link
Copy Markdown
Collaborator

t-imamichi commented May 7, 2021

I think we need to simplify each algorithm to use both OptimizationAlgorithm._convert and OptimizationAlgorithm._interpret.

For example, ADMM case

converters = [IntegerToBinary(), MaximizeToMinimize()]
original_problem = problem
problem = self._convert(problem, converters)
...
return cast(
    ADMMOptimizationResult,
    self._interpret(
        x=solution,
        converters=converters,
        problem=original_problem,
        result_class=ADMMOptimizationResult,
        state=self._state,
    ),
)

@tomtuamnuq
Copy link
Copy Markdown
Contributor Author

Sorry. Could format again by black -l 100? We added a missing config #118.

Hello @t-imamichi ,
since I have merged the config file in, prior to commit with "apply make black", it should be okay.
Running black with line length spec does not change anything.

Comment thread qiskit_optimization/algorithms/optimization_algorithm.py Outdated
Comment thread qiskit_optimization/algorithms/multistart_optimizer.py Outdated
@t-imamichi t-imamichi changed the title Maxmin conv Add maximize to minimize converter May 13, 2021
tomtuamnuq added 3 commits May 16, 2021 08:49
Solve conflicts:

qiskit_optimization/algorithms/grover_optimizer.py
test/algorithms/test_min_eigen_optimizer.py
@t-imamichi
Copy link
Copy Markdown
Collaborator

t-imamichi commented May 17, 2021

Thanks. It's almost done. It may require #136 to pass unit tests. Please wait for a while for us to fix the unit test issues.
Details #138

Copy link
Copy Markdown
Contributor

@adekusar-drl adekusar-drl left a comment

Choose a reason for hiding this comment

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

One thing to check out is the warm start QAOA test. Other than that, looks good to me! Thanks a lot!

Comment thread qiskit_optimization/algorithms/cobyla_optimizer.py Outdated
Comment thread qiskit_optimization/algorithms/slsqp_optimizer.py Outdated
Comment thread test/algorithms/test_warm_start_qaoa.py Outdated
Comment thread test/algorithms/test_warm_start_qaoa.py Outdated
t-imamichi and others added 2 commits May 21, 2021 22:55
Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
Comment thread test/algorithms/test_warm_start_qaoa.py Outdated
Comment thread test/algorithms/test_warm_start_qaoa.py Outdated
@t-imamichi
Copy link
Copy Markdown
Collaborator

Let's see the CI result. I think this PR is ready if CI passes.

@t-imamichi t-imamichi self-requested a review May 21, 2021 16:26
Copy link
Copy Markdown
Collaborator

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

Thank you for your cooperation! LGTM.

@adekusar-drl adekusar-drl merged commit 04adb49 into qiskit-community:main May 21, 2021
@tomtuamnuq tomtuamnuq deleted the maxmin-conv branch May 22, 2021 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maximize to minimize converter

5 participants