Generates a random circuit.
cirq.testing.random_circuit(
qubits: Union[Sequence[ops.Qid], int],
n_moments: int,
op_density: float,
gate_domain: Optional[Dict[ops.Gate, int]] = None,
random_state: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None
) -> cirq.Circuit
Used in the notebooks
Args |
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, and the qubits will be
cirq.NamedQubits with names given by the integers in
range(qubits) .
|
n_moments
|
The number of moments in the generated circuit.
|
op_density
|
The probability that a gate is selected to operate on
randomly selected qubits. Note that this is not the expected number
of qubits that are acted on, since there are cases where the
number of qubits that a gate acts on does not evenly divide the
total number of qubits.
|
gate_domain
|
The set of gates to choose from, specified as a dictionary
where each key is a gate and the value of the key is the number of
qubits the gate acts on. If not provided, the default gate domain is
{X, Y, Z, H, S, T, CNOT, CZ, SWAP, ISWAP, CZPowGate()}. Only gates
which act on a number of qubits less than len(qubits) (or qubits if
provided as an int) are selected from the gate domain.
|
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.
|