Module: cirq.testing

Utilities for testing code.

Modules

circuit_compare module

consistent_act_on module

consistent_channels 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

consistent_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.

repr_pretty_tester module

routing_devices module: Provides test devices that can validate circuits during a routing procedure.

sample_circuits module

sample_gates module

Classes

class DoesNotSupportSerializationGate: A gate that can't be serialized.

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

class FakePrinter: A fake of iPython's PrettyPrinter which captures text added to this printer.

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 PhaseUsingCleanAncilla: Phases the state \(|phase_state>\) by \(\exp(1j * \pi * \theta)\) using one clean ancilla.

class PhaseUsingDirtyAncilla: Phases the state \(|phase_state>\) by -1 using one dirty ancilla.

class RoutingTestingDevice: Testing device to be used for testing qubit connectivity in routing procedures.

class SingleQubitGate: A gate that must be applied to exactly one qubit.

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 leveraged in Circuit functions.

Functions

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_have_same_unitary_given_final_permutation(...): Asserts two circuits have the same unitary up to a final permutation of qubits.

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

assert_commutes_magic_method_consistent_with_unitaries(...)

assert_consistent_channel(...): Asserts that a given gate has Kraus operators and that they are properly normalized.

assert_consistent_mixture(...): Asserts that a given gate is a mixture and the mixture probabilities sum to one.

assert_consistent_resolve_parameters(...)

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

assert_controlled_unitary_consistent(...): Checks that unitary of ControlledGate(gate) is consistent with gate.controlled().

assert_decompose_ends_at_default_gateset(...): Asserts that cirq.decompose(val) ends at default cirq gateset or a known gate.

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 good repr.

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_channel(...): Tests whether a value's _applychannel is correct.

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 consistent.

assert_has_consistent_trace_distance_bound(...)

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_repr_pretty(...): Assert that the given object has a _repr_pretty_ method that produces the given text.

assert_repr_pretty_contains(...): Assert that the given object has a _repr_pretty_ output that contains the given text.

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.

assert_unitary_is_consistent(...)

construct_grid_device(...)

construct_ring_device(...)

highlight_text_differences(...)

nonoptimal_toffoli_circuit(...)

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.

DEFAULT_GATE_DOMAIN

{ 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.