qiskit_addon_opt_mapper.applications.NumberPartition

class NumberPartition(number_set)[source]

Bases: OptimizationApplication

Optimization application for the “number partition” [1] problem.

References

[1]: “Partition problem”, https://en.wikipedia.org/wiki/Partition_problem

Init method.

Parameters:

number_set (list[int]) – A list of integers

__init__(number_set)[source]

Init method.

Parameters:

number_set (list[int]) – A list of integers

Return type:

None

Methods

__init__(number_set)

Init method.

interpret(result)

Interpret a result as a list of subsets.

sample_most_likely(state_vector)

Compute the most likely binary string from state vector.

to_optimization_problem()

Represent as an optimization problem.

interpret(result)[source]

Interpret a result as a list of subsets.

Parameters:

result (ndarray) – The calculated result of the problem

Returns:

A list of subsets whose sum is the half of the total.

Return type:

list[list[int]]

static sample_most_likely(state_vector)[source]

Compute the most likely binary string from state vector.

Parameters:

state_vector (QuasiDistribution | Statevector | ndarray | dict) – state vector or counts or quasi-probabilities.

Returns:

binary string as numpy.ndarray of ints.

Raises:

ValueError – if state_vector is not QuasiDistribution, Statevector, np.ndarray, or dict.

Return type:

ndarray

to_optimization_problem()[source]

Represent as an optimization problem.

Convert a number partitioning problem instance into a OptimizationProblem

Returns:

The OptimizationProblem created from the number partitioning problem instance.

Return type:

OptimizationProblem