modules.applications.optimization.bp.mappings.ising.Ising

class Ising

Bases: Mapping

Ising formulation for the Bin Packing Problem.

__init__()

Constructor method

Methods

__init__()

Constructor method

get_available_submodule_options()

Gets the list of available options.

get_available_submodules(option)

If the module has submodules depending on certain options, this method should adjust the submodule_options accordingly.

get_default_submodule(option)

Returns the default submodule based on the provided option.

get_depending_parameters(option, config)

If the module has parameters depending on certain options, this method should return the parameters for the given option.

get_parameter_options()

Returns the configurable settings for this mapping.

get_requirements()

Return requirements of this module

get_submodule(option)

Submodule is instantiated according to the information given in self.sub_options.

map(problem, config)

Maps the bin packing problem input to an ISING formulation.

postprocess(input_data, config, **kwargs)

Reverse transformation/mapping from the submodule's format to the mathematical formulation suitable for the parent module.

preprocess(input_data, config, **kwargs)

Maps the data to the correct target format.

reverse_map(solution)

Maps the solution back to be able to validate and evaluate it.

transform_docplex_mip_to_ising(mip_docplex, ...)

Transform a docplex mix-integer-problem to an Ising formulation.

class Config

Bases: TypedDict

Attributes of a valid config.

penalty_factor: float
clear() None.  Remove all items from D.
copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
get_available_submodule_options() list

Gets the list of available options.

Returns:

List of module options

get_available_submodules(option: list) list

If the module has submodules depending on certain options, this method should adjust the submodule_options accordingly.

Parameters:

option -- List of chosen options

Returns:

List of available submodules

get_default_submodule(option: str) Core

Returns the default submodule based on the provided option.

Parameters:

option -- Option specifying the submodule

Returns:

Instance of the corresponding submodule

Raises:

NotImplementedError -- If the option is not recognized

get_depending_parameters(option: str, config: dict) dict

If the module has parameters depending on certain options, this method should return the parameters for the given option.

Parameters:
  • option -- The chosen option

  • config -- Current config dictionary

Returns:

The parameters for the given option

get_parameter_options() dict

Returns the configurable settings for this mapping.

Returns:

return {
"penalty_factor": {
                    "values": [2],
                    "description": "Choose your QUBO-penalty-factor(s).",
                    "custom_input": True,
                    "allow_ranges": True,
                    "postproc": float
        }
    }
static get_requirements() list[dict]

Return requirements of this module

Returns:

List of dict with requirements of this module

get_submodule(option: str) Core

Submodule is instantiated according to the information given in self.sub_options. If self.sub_options is None, get_default_submodule is called as a fallback.

Parameters:

option -- String with the options

Returns:

Instance of a module

map(problem: tuple[list, float, list], config: Config) tuple[dict, float]

Maps the bin packing problem input to an ISING formulation.

Parameters:
  • problem -- Bin packing problem instance defined by 1. object weights, 2. bin capacity, 3. incompatible objects

  • config -- Config with the parameters specified in Config class

Returns:

Dict with ISING-matrix, -vector and -offset as well as time it took to map it

postprocess(input_data: any, config: dict, **kwargs) tuple[any, float]

Reverse transformation/mapping from the submodule's format to the mathematical formulation suitable for the parent module.

Parameters:
  • input_data -- Data which should be reverse-mapped

  • config -- Config of the reverse mapping

  • kwargs -- Optional keyword arguments

Returns:

Tuple with reverse-mapped problem and the time it took to map it

preprocess(input_data: any, config: dict, **kwargs) tuple[any, float]

Maps the data to the correct target format.

Parameters:
  • input_data -- Data which should be mapped

  • config -- Config of the mapping

  • kwargs -- Optional keyword arguments

Returns:

Tuple with mapped problem and the time it took to map it

reverse_map(solution: ndarray) tuple[dict, float]

Maps the solution back to be able to validate and evaluate it.

Parameters:

solution -- The solution of the QAOA is a numpy-array

Returns:

Solution mapped accordingly, time it took to map it

transform_docplex_mip_to_ising(mip_docplex: Model, penalty_factor) tuple[ndarray, ndarray, float, QuadraticProgram]

Transform a docplex mix-integer-problem to an Ising formulation.

Parameters:
  • mip_docplex -- Docplex-Model

  • penalty_factor -- Penalty factor for transformation

Returns:

J-matrix, t-vector and c-offset of the Ising formulation, and the QUBO matrix