Module: cirq.testing

Utilities for testing code.


asynchronous module

circuit_compare module

consistent_act_on module

consistent_controlled_gate_op module

consistent_decomposition module

consistent_pauli_expansion module

consistent_phase_by module

consistent_protocols module

consistent_qasm module

consistent_resolve_parameters module

consistent_specified_has_unitary module

deprecation module

devices module: Provides test devices that can validate circuits.

equals_tester module: A utility class for testing equality methods.

equivalent_basis_map module

equivalent_repr_eval module

gate_features module: Simple gates used for testing purposes.

json module

lin_alg_utils module: A testing class with utilities for checking linear algebra.

logs module: Helper for testing python logging statements.

no_identifier_qubit module

op_tree module

order_tester module: A utility class for testing ordering methods.

sample_circuits module


class EqualsTester: Tests equality against user-provided disjoint equivalence groups.

class NoIdentifierQubit: A singleton qubit type that does not have a qudit variant.

class OrderTester: Tests ordering against user-provided disjoint ordered groups or items.

class ThreeQubitGate: A gate that must be applied to exactly three qubits.

class TwoQubitGate: A gate that must be applied to exactly two qubits.

class ValidatingTestDevice: A fake device that was created to ensure certain Device validation features are


assert_all_implemented_act_on_effects_match_unitary(...): Uses val's effect on final_state_vector to check act_on(val)'s behavior.

assert_allclose_up_to_global_phase(...): Checks if a ~= b * exp(i t) for some t.

assert_circuits_with_terminal_measurements_are_equivalent(...): Determines if two circuits have equivalent effects.



assert_controlled_and_controlled_by_identical(...): Checks that gate.on().controlled_by() == gate.controlled().on()

assert_decompose_is_consistent_with_unitary(...): Uses val._unitary_ to check val._phase_by_'s behavior.

assert_deprecated(...): Allows deprecated functions, classes, decorators in tests.

assert_eigengate_implements_consistent_protocols(...): Checks that an EigenGate subclass is internally consistent and has a

assert_equivalent_computational_basis_map(...): Ensure equivalence of basis state mapping.

assert_equivalent_op_tree(...): Ensures that the two OP_TREEs are equivalent.

assert_equivalent_repr(...): Checks that eval(repr(v)) == v.

assert_has_consistent_apply_unitary(...): Tests whether a value's _applyunitary is correct.

assert_has_consistent_apply_unitary_for_various_exponents(...): Tests whether a value's _applyunitary is correct.

assert_has_consistent_qid_shape(...): Tests whether a value's _qid_shape_ and _num_qubits_ are correct and


assert_has_diagram(...): Determines if a given circuit has the desired text diagram.

assert_implements_consistent_protocols(...): Checks that a value is internally consistent and has a good repr.

assert_json_roundtrip_works(...): Tests that the given object can serialized and de-serialized

assert_logs(...): A context manager for testing logging and warning events.

assert_pauli_expansion_is_consistent_with_unitary(...): Checks Pauli expansion against unitary matrix.

assert_phase_by_is_consistent_with_unitary(...): Uses val._unitary_ to check val._phase_by_'s behavior.

assert_qasm_is_consistent_with_unitary(...): Uses val._unitary_ to check val._qasm_'s behavior.

assert_same_circuits(...): Asserts that two circuits are identical, with a descriptive error.

assert_specifies_has_unitary_if_unitary(...): Checks that unitary values can be cheaply identifies as unitary.

asyncio_pending(...): THIS FUNCTION IS DEPRECATED.



random_circuit(...): Generates a random circuit.

random_density_matrix(...): Returns a random density matrix distributed with Hilbert-Schmidt measure.

random_orthogonal(...): Returns a random orthogonal matrix distributed with Haar measure.

random_special_orthogonal(...): Returns a random special orthogonal matrix distributed with Haar measure.

random_special_unitary(...): Returns a random special unitary distributed with Haar measure.

random_superposition(...): Returns a random unit-length vector from the uniform distribution.

random_two_qubit_circuit_with_czs(...): Creates a random two qubit circuit with the given number of CNOTs.

random_unitary(...): Returns a random unitary matrix distributed with Haar measure.


 cirq.CNOT: 2,
 cirq.CZ: 2,
 cirq.H: 1,
 cirq.ISWAP: 2,
 cirq.S: 1,
 cirq.SWAP: 2,
 cirq.T: 1,
 cirq.X: 1,
 cirq.Y: 1,
 cirq.Z: 1

The default gate domain for cirq.testing.random_circuit.

This includes the gates CNOT, CZ, H, ISWAP, CZ, S, SWAP, T, X, Y, and Z gates.