dimod.AdjDictBQM.add_variable¶
-
AdjDictBQM.
add_variable
(v=None, bias=0.0)[source]¶ Add a variable to the binary quadratic model.
- Parameters
v (hashable, optional) – A label for the variable. Defaults to the length of the binary quadratic model, if that label is available. Otherwise defaults to the lowest available positive integer label.
bias (numeric, optional, default=0) – The initial bias value for the added variable. If v is already a variable, then bias (if any) is adding to its existing linear bias.
- Returns
The label of the added variable.
- Return type
hashable
- Raises
TypeError – If the label is not hashable.
Examples
>>> bqm = dimod.AdjDictBQM('SPIN') >>> bqm.add_variable() 0 >>> bqm.add_variable('a') 'a' >>> bqm.add_variable() 2
>>> bqm = dimod.AdjDictBQM('SPIN') >>> bqm.add_variable(1) 1 >>> bqm.add_variable() # 1 is taken 0 >>> bqm.add_variable() 2