cirq.testing.random_circuit
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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-06-27 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-27 UTC."],[],[]]