Problem
- class braket.annealing.problem.ProblemType(*values)[source]
Bases:
StrEnumThe 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, linear=None, quadratic=None)[source]
Bases:
objectRepresents an annealing problem.
- Parameters:
problem_type (
ProblemType)linear (
dict[int,float] |None)quadratic (
dict[tuple[int,int],float] |None)
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, coefficient)[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
- Return type:
- Returns:
Problem – This problem object
- add_linear_terms(coefficients)[source]
Adds linear terms to the problem.
- Parameters:
coefficients (dict[int, float]) – A map of variable to coefficient
- Return type:
- Returns:
Problem – This problem object
- add_quadratic_term(term, coefficient)[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
- Return type:
- Returns:
Problem – This problem object