qplex.model package

Submodules

qplex.model.constants module

constants.py

This module defines various constants used throughout QPLEX.

class qplex.model.constants.ConstraintType(value)[source]

Bases: Enum

An enumeration.

CARDINALITY = 'cardinality'
INEQUALITY = 'inequality'
MULTIPLE = 'multiple'
PARTITION = 'partition'
UNCONSTRAINED = 'unconstrained'

qplex.model.execution_config module

class qplex.model.execution_config.ExecutionConfig(method: str = 'classical', verbose: bool = False, provider: str | None = None, workflow: str = 'default', backend: str | None = None, provider_options: ~typing.Dict[str, ~typing.Any] = <factory>, algorithm: str = 'qaoa', ansatz: str | None = None, p: int = 2, mixer: ~typing.Any | None = None, layers: int = 2, optimizer: str = 'COBYLA', callback: ~typing.Callable[[~numpy.ndarray], None] | None = None, tolerance: float = 1e-10, max_iter: int = 1000, penalty: float | None = None, shots: int = 1024, seed: int = 1)[source]

Bases: object

Configuration for quantum optimization execution.

algorithm: str = 'qaoa'
ansatz: str | None = None
backend: str | None = None
callback: Callable[[ndarray], None] | None = None
layers: int = 2
max_iter: int = 1000
method: str = 'classical'
mixer: Any | None = None
optimizer: str = 'COBYLA'
p: int = 2
penalty: float | None = None
provider: str | None = None
provider_options: Dict[str, Any]
seed: int = 1
shots: int = 1024
to_dict() Dict[str, Any][source]

Convert configuration to dictionary.

tolerance: float = 1e-10
verbose: bool = False
workflow: str = 'default'

qplex.model.qmodel module

class qplex.model.qmodel.ModelSolution(solution: Dict[str, Any], objective: float, execution_time: float, method: str, provider: str | None = None, backend: str | None = None, algorithm: str = 'N/A')[source]

Bases: object

algorithm: str = 'N/A'
backend: str | None = None
execution_time: float
method: str
objective: float
provider: str | None = None
solution: Dict[str, Any]
class qplex.model.qmodel.QModel(name)[source]

Bases: Model

Creates an instance of a QModel.

Parameters:

name (str) – The name of the model.

Return type:

An instance of a QModel.

get_qubo(penalty: float | None = None) QuadraticProgram[source]

Returns the QUBO encoding of this problem.

Parameters:

penalty (float, optional) – The penalty factor for the QUBO conversion.

Returns:

The QUBO encoding of this problem.

Return type:

QuadraticProgram

print_solution(print_zeros: bool = False, solution_header_fmt: str | None = None, var_value_fmt: str | None = None, **kwargs)[source]

Prints the solution of the model. Must be called after solve().

Parameters:
  • print_zeros (bool, optional) – Whether to print variables with zero values.

  • solution_header_fmt (str, optional) – Format string for the solution header.

  • var_value_fmt (str, optional) – Format string for variable values.

  • kwargs (dict) – Additional keyword arguments.

solve(method: str = 'classical', config=ExecutionConfig(method='classical', verbose=False, provider=None, workflow='default', backend=None, provider_options={}, algorithm='qaoa', ansatz=None, p=2, mixer=None, layers=2, optimizer='COBYLA', callback=<qplex.commons.optimization_callback.OptimizationCallback object>, tolerance=1e-10, max_iter=1000, penalty=None, shots=1024, seed=1))[source]

Solves the model using the specified method and Options.

Parameters:
  • method (str, optional) – The method to solve the model, either ‘classical’ or ‘quantum’.

  • config (Options, optional) – The options for solving the model.

Raises:

ValueError – If the method argument is not ‘classical’ or ‘quantum’.

Module contents

This module provides the qmodel for the definition of an optimization problem model.