modified type hint in docathon
@@ -61,6 +61,7 @@ The following is an example of use.
import logging
from math import fsum
+from typing import Tuple
import numpy as np
from docplex.mp.constants import ComparisonType
@@ -73,20 +74,20 @@ from qiskit.aqua.operators import WeightedPauliOperator
logger = logging.getLogger(__name__)
-def get_operator(mdl, auto_penalty=True, default_penalty=1e5):
+def get_operator(mdl: Model, auto_penalty: bool = True,
+ default_penalty: float = 1e5) -> Tuple[WeightedPauliOperator, float]:
"""
Generate Ising Hamiltonian from a model of DOcplex.
Args:
- mdl (docplex.mp.model.Model): A model of DOcplex for a optimization problem.
- auto_penalty (bool): If true, the penalty coefficient is automatically defined
+ mdl : A model of DOcplex for a optimization problem.
+ auto_penalty : If true, the penalty coefficient is automatically defined
by "_auto_define_penalty()".
- default_penalty (float): The default value of the penalty coefficient for the constraints.
+ default_penalty : The default value of the penalty coefficient for the constraints.
This value is used if "auto_penalty" is False.
Returns:
- tuple(operators.WeightedPauliOperator, float): operator for the Hamiltonian and a
- constant shift for the obj function.
+ A WeightedPauliOperator for the Hamiltonian and a constant shift for the obj function.
"""
_validate_input_model(mdl)
@@ -207,12 +208,12 @@ def get_operator(mdl, auto_penalty=True, default_penalty=1e5):
return qubit_op, shift
-def _validate_input_model(mdl):
+def _validate_input_model(mdl: Model):
"""
Check whether an input model is valid. If not, raise an AquaError
Args:
- mdl (docplex.mp.model.Model): A model of DOcplex for a optimization problem.
+ mdl : A model of DOcplex for a optimization problem.
Raises:
AquaError: Unsupported input model
@@ -240,18 +241,18 @@ def _validate_input_model(mdl):
raise AquaError('The input model has unsupported elements.')
-def _auto_define_penalty(mdl, default_penalty=1e5):
+def _auto_define_penalty(mdl: Model, default_penalty: float = 1e5) -> float:
"""
Automatically define the penalty coefficient.
This returns object function's (upper bound - lower bound + 1).
Args:
- mdl (docplex.mp.model.Model): A model of DOcplex for a optimization problem.
- default_penalty (float): The default value of the penalty coefficient for the constraints.
+ mdl : A model of DOcplex for a optimization problem.
+ default_penalty : The default value of the penalty coefficient for the constraints.
Returns:
- float: The penalty coefficient for the Hamiltonian.
+ The penalty coefficient for the Hamiltonian.
"""
# if a constraint has float coefficient, return 1e5 for the penalty coefficient.
