qiskit_addon_opt_mapper.converters.OptimizationProblemToQubo¶
- class OptimizationProblemToQubo(penalty=None)[source]¶
Bases:
OptimizationProblemConverterConvert a given optimization problem in quadratic form into a QUBO problem.
Done by converting variables to binary and eliminating constraints. An optimization problem in quadratic form is a problem with quadratic objective function and linear constraints. A QUBO is a problem with quadratic objective function and no constraints. This combines several converters: IntegerToBinary, InequalityToPenalty, InequalityToEquality, EqualityToPenalty, and MaximizeToMinimize. The resulting HUBO problem can be directly mapped to an Ising Hamiltonian using the to_ising() function.
Examples
>>> from qiskit_addon_opt_mapper.problems import OptimizationProblem >>> from qiskit_addon_opt_mapper.converters import OptimizationProblemToQubo >>> problem = OptimizationProblem() >>> # define a problem >>> conv = OptimizationProblemToQubo() >>> problem2 = conv.convert(problem)
Init method.
- Parameters:
penalty (float | None) – Penalty factor to scale equality constraints that are added to objective. If None is passed, a penalty factor will be automatically calculated on every conversion.
- __init__(penalty=None)[source]¶
Init method.
- Parameters:
penalty (float | None) – Penalty factor to scale equality constraints that are added to objective. If None is passed, a penalty factor will be automatically calculated on every conversion.
- Return type:
None
Methods
__init__([penalty])Init method.
convert(problem)Convert a optimization problem into a QUBO form.
get_compatibility_msg(problem)Checks whether a given problem can be converted to a QUBO form.
interpret(x)Convert the result of the converted problem back to that of the original problem.
is_compatible(problem)Checks whether a given problem can be solved with the optimizer implementing this method.
Attributes
Returns the penalty factor used in conversion.
- convert(problem)[source]¶
Convert a optimization problem into a QUBO form.
The new problem has no constraints and the objective function is quadratic.
- Parameters:
problem (OptimizationProblem) – The problem with linear constraints to be solved.
- Returns:
The problem converted in QUBO format as minimization problem.
- Raises:
OptimizationError – In case of an incompatible problem.
- Return type:
OptimizationProblem
- static get_compatibility_msg(problem)[source]¶
Checks whether a given problem can be converted to a QUBO form.
If the problem is not compatible, this function returns a message explaining the incompatibility.
The following problems are not compatible: - Continuous variables are not supported. - Higher-order objective functions are not supported. - Quadratic constraints are not supported. - Higher-order constraints are not supported. - Constraints with float coefficients are not supported, because inequality constraints cannot be converted to equality constraints using integer slack variables.
- Parameters:
problem (OptimizationProblem) – The optimization problem to check compatibility.
- Returns:
A message describing the incompatibility.
- Return type:
- interpret(x)[source]¶
Convert the result of the converted problem back to that of the original problem.
Done by applying the interpret method of each converter in reverse order.