braket.annealing.problem module

class braket.annealing.problem.ProblemType(value)[source]

Bases: str, Enum

The type of annealing problem.

QUBO: Quadratic Unconstrained Binary Optimization, with values 1 and 0

ISING: Ising model, with values +/-1

QUBO = 'QUBO'
ISING = 'ISING'
class braket.annealing.problem.Problem(problem_type: ProblemType, linear: dict[int, float] | None = None, quadratic: dict[tuple[int, int], float] | None = None)[source]

Bases: object

Represents an annealing problem.

Initializes a Problem.

Parameters:
  • problem_type (ProblemType) – The type of annealing problem

  • linear (dict[int, float] | None) – The linear terms of this problem, as a map of variable to coefficient

  • quadratic (dict[tuple[int, int], float] | None) – The quadratic terms of this problem, as a map of variables to coefficient

Examples

>>> problem = Problem(
>>>     ProblemType.ISING,
>>>     linear={1: 3.14},
>>>     quadratic={(1, 2): 10.08},
>>> )
>>> problem.add_linear_term(2, 1.618).add_quadratic_term((3, 4), 1337)
property problem_type: ProblemType

The type of annealing problem.

Returns:

ProblemType – The type of annealing problem

property linear: dict[int, float]

The linear terms of this problem.

Returns:

dict[int, float] – The linear terms of this problem, as a map of variable to coefficient

property quadratic: dict[tuple[int, int], float]

The quadratic terms of this problem.

Returns:

dict[tuple[int, int], float] – The quadratic terms of this problem, as a map of variables to coefficient

add_linear_term(term: int, coefficient: float) Problem[source]

Adds a linear term to the problem.

Parameters:
  • term (int) – The variable of the linear term

  • coefficient (float) – The coefficient of the linear term

Returns:

Problem – This problem object

add_linear_terms(coefficients: dict[int, float]) Problem[source]

Adds linear terms to the problem.

Parameters:

coefficients (dict[int, float]) – A map of variable to coefficient

Returns:

Problem – This problem object

add_quadratic_term(term: tuple[int, int], coefficient: float) Problem[source]

Adds a quadratic term to the problem.

Parameters:
  • term (tuple[int, int]) – The variables of the quadratic term

  • coefficient (float) – The coefficient of the quadratic term

Returns:

Problem – This problem object

add_quadratic_terms(coefficients: dict[tuple[int, int], float]) Problem[source]

Adds quadratic terms to the problem.

Parameters:

coefficients (dict[tuple[int, int], float]) – A map of variables to coefficient

Returns:

Problem – This problem object

to_ir() Problem[source]

Converts this problem into IR representation.

Returns:

Problem – IR representation of this problem object