def test_controlled_op_to_operations_omits_negligible_global_phase(): qc = cirq.QubitId() qt = cirq.QubitId() operations = cirq.controlled_op_to_operations( control=qc, target=qt, operation=cirq.H.matrix(), tolerance=0.0001) assert operations == [cirq.Y(qt)**-0.25, cirq.CZ(qc, qt), cirq.Y(qt)**0.25]
def test_controlled_op_to_operations_equivalent_on_known_and_random(mat): qc = cirq.NamedQubit('c') qt = cirq.NamedQubit('qt') operations = cirq.controlled_op_to_operations( control=qc, target=qt, operation=mat) actual_effect = _operations_to_matrix(operations, (qc, qt)) intended_effect = cirq.kron_with_controls(cirq.CONTROL_TAG, mat) assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect)
def test_controlled_op_to_operations_equivalent_on_known_and_random(mat): qc = cirq.QubitId() qt = cirq.QubitId() operations = cirq.controlled_op_to_operations( control=qc, target=qt, operation=mat) actual_effect = _operations_to_matrix(operations, (qc, qt)) intended_effect = cirq.kron_with_controls(cirq.CONTROL_TAG, mat) assert cirq.allclose_up_to_global_phase(actual_effect, intended_effect)
def test_controlled_op_to_operations_omits_negligible_global_phase(): qc = cirq.QubitId() qt = cirq.QubitId() operations = cirq.controlled_op_to_operations(control=qc, target=qt, operation=cirq.H.matrix(), tolerance=0.0001) assert operations == [cirq.Y(qt)**-0.25, cirq.CZ(qc, qt), cirq.Y(qt)**0.25]
def test_controlled_op_to_operations_omits_negligible_global_phase(): qc = cirq.NamedQubit('c') qt = cirq.NamedQubit('qt') operations = cirq.controlled_op_to_operations( control=qc, target=qt, operation=cirq.unitary(cirq.H), tolerance=0.0001) assert operations == [cirq.Y(qt)**-0.25, cirq.CZ(qc, qt), cirq.Y(qt)**0.25]
def test_controlled_op_to_operations_concrete_case(): c = cirq.NamedQubit('c') t = cirq.NamedQubit('t') operations = cirq.controlled_op_to_operations( control=c, target=t, operation=np.array([[1, 1j], [1j, 1]]) * np.sqrt(0.5), tolerance=0.0001) assert operations == [cirq.Y(t)**-0.5, cirq.CZ(c, t)**1.5, cirq.Z(c)**0.25, cirq.Y(t)**0.5]
def test_controlled_op_to_operations_concrete_case(): c = cirq.NamedQubit('c') t = cirq.NamedQubit('t') operations = cirq.controlled_op_to_operations( control=c, target=t, operation=np.array([[1, 1j], [1j, 1]]) * np.sqrt(0.5), tolerance=0.0001) assert operations == [ cirq.Y(t)**-0.5, cirq.CZ(c, t)**1.5, cirq.Z(c)**0.25, cirq.Y(t)**0.5 ]
def test_controlled_op_to_operations_concrete_case(): c = cirq.NamedQubit('c') t = cirq.NamedQubit('t') expected = [cirq.Y(t)**-0.5, cirq.CZ(c, t)**1.5, cirq.Z(c)**0.25, cirq.Y(t)**0.5] operations = cirq.controlled_op_to_operations( control=c, target=t, operation=np.array([[1, 1j], [1j, 1]]) * np.sqrt(0.5), tolerance=0.0001) # Test closeness as opposed to equality to avoid precision errors for actual_op, expected_op in zip(operations, expected): assert cirq.allclose_up_to_global_phase(cirq.unitary(actual_op), cirq.unitary(expected_op), atol=1e-8)