gnm_random_bqm(variables: Union[int, Sequence[Hashable]], num_interactions: int, vartype: Union[dimod.vartypes.Vartype, str, frozenset], *, cls: type = <class 'dimod.binary.binary_quadratic_model.BinaryQuadraticModel'>, random_state: Optional[Union[numpy.random.mtrand.RandomState, int]] = None, bias_generator: Optional[Callable[[int], Sequence[Union[int, float, numpy.number]]]] = None) dimod.binary.binary_quadratic_model.BinaryQuadraticModel[source]

Generate a random binary quadratic model with a fixed number of variables and interactions.

  • variables – The variables. If variables is an int, the variables are labelled as [0, variables).

  • num_interactions – The number of interactions.

  • vartype

    Variable type for the BQM. Accepted input values:

    • Vartype.SPIN, 'SPIN', {-1, 1}

    • Vartype.BINARY, 'BINARY', {0, 1}

  • cls (type, optional) – Binary quadratic model class to build from. Default is BinaryQuadraticModel.

  • random_state – A random seed or a random state generator. Used for generating the structure of the BQM and, if bias_generator is not given, for the bias generation.

  • bias_generator – Bias generating function. Should accept a single argument n and return an ndarray of biases of length n. May be called multiple times. If not provided, :meth:numpy.random.RandomState.uniform is used by default.


A binary quadratic model of type cls.