# Does BQM manipulate constraints after they are entered?

**If I have a constraint such as x_1==0, then as I understand it there might be 2 ways to enter this constraint in a Binary Quadratic Model:**

**bqm = BinaryQuadraticModel({'x':1},**

** {},**

** 0, 'BINARY')**

OR

**bqm = BinaryQuadraticModel({},**

** {'xx':1},**

** 0, 'BINARY')**

**In most cases, the second formulation is preferred for solving a QUBO. But, when it comes time to solve this BQM, will these get solved differently? Or, will these have the same solution quality?**

## Comments

David J(Report)Hello,

I think you are referring to providing the values as linear or quadratic terms, correct?

Here's the constructor signature for reference:

BinaryQuadraticModel(linear, quadratic, offset, vartype)

The quadratic terms would need to be entered a little differently.

bqm = BinaryQuadraticModel({'x1':1}, {('x1','x2'):1}, 0, 'BINARY')

Inputting the linear and quadratic terms isn't a constraint but rather is used in the calculation of the Hamiltonian equation. The first equation in the QUBO section of the Solving Problems with Quantum Samplers docs page shows the linear and quadratic terms being added together. The idea is that the xi and xj terms will be selected as 1 or 0 by the QPU in order to make the total sum of all of these terms a low number. The Qi,i and Qi,j terms are the linear (i,i) and quadratic (i,j) terms that you, as the programmer, get to select to formulate the problem.

In the above code example, Qi,i represents all of the linear terms in the dictionary {'x1':1} and Qi,j represents all of the quadratic terms in the dictionary {('x1','x2'):1}. In the above code example there is only one linear term and one quadratic term.

Also, please take a look at the Getting Started Guide to see an explanation of how the problem is relates to the Hamiltonian formula. In the Formulation and Sampling section there is a Simple Objective Example that might be helpful.

On the other hand, to formulate

constraintsin a BQM, Penalty Models can be used.The CQM let's problems be input in terms of constraints, rather than in terms of QUBO/ising values.

I hope this helps to clarify things a little. Please feel free to ask more questions.

Please sign in to leave a comment.