gnp_random_bqm(n: Union[int, Sequence[Hashable]], p: float, 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 BQM structured as an Erdős-Rényi graph.

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

  • p – The probability for interaction creation.

  • vartype

    Variable type for the BQM. Accepted input values:

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

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

  • cls – 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.


This algorithm runs in O(n^2) time and space.