cirq.testing.random_circuit

cirq.testing.random_circuit(qubits: Union[Sequence[cirq.ops.raw_types.Qid], int], n_moments: int, op_density: float, gate_domain: Optional[Dict[cirq.ops.raw_types.Gate, int]] = None, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None) → cirq.circuits.circuit.Circuit[source]

Generates a random circuit.

Parameters
  • qubits – If a sequence of qubits, then these are the qubits that the circuit should act on. Because the qubits on which an operation acts are chosen randomly, not all given qubits may be acted upon. If an int, then this number of qubits will be automatically generated.

  • n_moments – the number of moments in the generated circuit.

  • op_density – the expected proportion of qubits that are acted on in any moment.

  • gate_domain – The set of gates to choose from, with a specified arity.

  • random_state – Random state or random state seed.

Raises

ValueError

  • op_density is not in (0, 1). * gate_domain is empty. * qubits is an int less than 1 or an empty sequence.

Returns

The randomly generated Circuit.