This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1179 from manoelmarques/stable-0.7.5
[Stable] Qiskit Aqua Release 0.7.5
- Loading branch information
Showing
9 changed files
with
315 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.7.4 | ||
0.7.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
qiskit/optimization/converters/ising_to_quadratic_program.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2020. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
|
||
"""The converter from a ```Operator``` to ``QuadraticProgram``.""" | ||
|
||
from typing import Optional, Union | ||
import copy | ||
import warnings | ||
import numpy as np # pylint: disable=unused-import | ||
|
||
from qiskit.aqua.operators import OperatorBase, WeightedPauliOperator | ||
from ..problems.quadratic_program import QuadraticProgram | ||
|
||
|
||
class IsingToQuadraticProgram: | ||
"""Convert a qubit operator into a quadratic program""" | ||
|
||
def __init__(self, linear: bool = False) -> None: | ||
r""" | ||
Args: | ||
linear: If linear is True, :math:`x^2` is treated as a linear term | ||
since :math:`x^2 = x` for :math:`x \in \{0,1\}`. | ||
Else, :math:`x^2` is treat as a quadratic term. | ||
The default value is False. | ||
""" | ||
self._qubit_op = None | ||
self._offset = 0.0 | ||
self._num_qubits = 0 | ||
self._qubo_matrix = None # type: Optional[np.ndarray] | ||
self._qp = None # type: Optional[QuadraticProgram] | ||
self._linear = linear | ||
warnings.warn("The IsingToQuadraticProgram class is deprecated and " | ||
"will be removed in a future release. Use the " | ||
".from_ising() method on the QuadraticProgram class " | ||
"instead.", DeprecationWarning) | ||
|
||
def encode(self, qubit_op: Union[OperatorBase, WeightedPauliOperator], offset: float = 0.0 | ||
) -> QuadraticProgram: | ||
"""Convert a qubit operator and a shift value into a quadratic program | ||
Args: | ||
qubit_op: The qubit operator to be converted into a | ||
:class:`~qiskit.optimization.problems.quadratic_program.QuadraticProgram` | ||
offset: The shift value of the qubit operator | ||
Returns: | ||
QuadraticProgram converted from the input qubit operator and the shift value | ||
Raises: | ||
QiskitOptimizationError: If there are Pauli Xs in any Pauli term | ||
QiskitOptimizationError: If there are more than 2 Pauli Zs in any Pauli term | ||
NotImplementedError: If the input operator is a ListOp | ||
""" | ||
self._qubit_op = qubit_op | ||
self._offset = copy.deepcopy(offset) | ||
self._num_qubits = qubit_op.num_qubits | ||
self._qp = QuadraticProgram() | ||
self._qp.from_ising(qubit_op, offset, | ||
linear=self._linear) | ||
return self._qp |
49 changes: 49 additions & 0 deletions
49
qiskit/optimization/converters/quadratic_program_to_ising.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2020. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""The converter from an ```QuadraticProgram``` to ``Operator``.""" | ||
|
||
from typing import Tuple, Optional | ||
import warnings | ||
|
||
from qiskit.aqua.operators import OperatorBase | ||
from ..problems.quadratic_program import QuadraticProgram | ||
|
||
|
||
class QuadraticProgramToIsing: | ||
"""Convert an optimization problem into a qubit operator.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize the internal data structure.""" | ||
self._src = None # type: Optional[QuadraticProgram] | ||
warnings.warn("The QuadraticProgramToIsing class is deprecated and " | ||
"will be removed in a future release. Use the " | ||
".to_ising() method on a QuadraticProgram object " | ||
"instead.", DeprecationWarning) | ||
|
||
def encode(self, op: QuadraticProgram) -> Tuple[OperatorBase, float]: | ||
"""Convert a problem into a qubit operator | ||
Args: | ||
op: The optimization problem to be converted. Must be an unconstrained problem with | ||
binary variables only. | ||
Returns: | ||
The qubit operator of the problem and the shift value. | ||
Raises: | ||
QiskitOptimizationError: If a variable type is not binary. | ||
QiskitOptimizationError: If constraints exist in the problem. | ||
""" | ||
|
||
self._src = op | ||
return self._src.to_ising() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
releasenotes/notes/deprecate-ising-converter-classes-11749cdb6ac1bfaa.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
deprecations: | ||
- | | ||
The ising convert classes | ||
:class:`qiskit.optimization.converters.QuadraticProgramToIsing` and | ||
:class:`qiskit.optimization.converters.IsingToQuadraticProgram` have | ||
been deprecated and will be removed in a future release. Instead the | ||
:class:`qiskit.optimization.QuadraticProgram` methods | ||
:meth:`~qiskit.optimization.QuadraticProgram.to_ising` and | ||
:meth:`~qiskit.optimization.QuadraticPrgraom.from_ising` should be used | ||
instead. | ||
- | | ||
The ``pprint_as_string`` method for | ||
:class:`qiskit.optimization.QuadraticProgram` has been deprecated and will | ||
be removed in a future release. Instead you should just run | ||
``.pprint_as_string()`` on the output from | ||
:meth:`~qiskit.optimization.QuadraticProgram.to_docplex` | ||
- | | ||
The ``prettyprint`` method for | ||
:class:`qiskit.optimization.QuadraticProgram` has been deprecated and will | ||
be removed in a future release. Instead you should just run | ||
``.prettyprint()`` on the output from | ||
:meth:`~qiskit.optimization.QuadraticProgram.to_docplex` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters