Пример #1
0
def test_deprecated():
    with capture_logging() as log:
        _ = cirq.SingleQubitMatrixGate(np.eye(2))
    assert len(log) == 1
    assert "cirq.SingleQubitMatrixGate" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()

    with capture_logging() as log:
        _ = cirq.TwoQubitMatrixGate(np.eye(4))
    assert len(log) == 1
    assert "cirq.TwoQubitMatrixGate" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()
Пример #2
0
def test_deprecated():
    with capture_logging() as log:
        _ = cirq.linalg.eye_tensor((1, ), dtype=float)
    assert len(log) == 1
    assert "cirq.eye_tensor" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()

    with capture_logging() as log:
        _ = cirq.linalg.one_hot(shape=(1, ), dtype=float)
    assert len(log) == 1
    assert "cirq.one_hot" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()
Пример #3
0
def test_deprecated():
    with capture_logging() as log:
        _ = cirq.sim.to_valid_density_matrix(0, 1)
    assert len(log) == 1
    assert "cirq.to_valid_density_matrix" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()

    with capture_logging() as log:
        _ = cirq.sim.von_neumann_entropy(np.eye(2) / 2)
    assert len(log) == 1
    assert "cirq.von_neumann_entropy" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()
Пример #4
0
def test_deprecated_givens_rotation(angle_rads):
    with capture_logging() as log:
        u = cirq.unitary(cirq.GivensRotation(angle_rads))
    assert len(log) == 1
    assert 'deprecated' in log[0].getMessage()
    assert 'GivensRotation' in log[0].getMessage()
    np.testing.assert_allclose(u, cirq.unitary(cirq.givens(angle_rads)))
Пример #5
0
def test_deprecated_rxyz_rotations(rads):
    with capture_logging():
        assert np.all(
            cirq.unitary(cirq.Rx(rads)) == cirq.unitary(cirq.rx(rads)))
        assert np.all(
            cirq.unitary(cirq.Ry(rads)) == cirq.unitary(cirq.ry(rads)))
        assert np.all(
            cirq.unitary(cirq.Rz(rads)) == cirq.unitary(cirq.rz(rads)))
Пример #6
0
def test_create_deprecated():
    with capture_logging() as log:
        actual = cirq.Duration.create(timedelta(0))
    assert len(log) == 1
    assert 'cirq.Duration.create was used' in log[0].getMessage()
    assert 'deprecated' in log[0].getMessage()

    assert actual == cirq.Duration()
Пример #7
0
def test_deprecated_from_single():
    q0 = cirq.LineQubit(0)
    with capture_logging() as log:
        actual = cirq.PauliString.from_single(q0, cirq.X)
    assert len(log) == 1  # May fail if deprecated thing is used elsewhere.
    assert 'PauliString.from_single' in log[0].getMessage()
    assert 'deprecated' in log[0].getMessage()

    assert actual == cirq.PauliString([cirq.X(q0)])
Пример #8
0
def test_identity_operation_deprecated():
    a, b = cirq.LineQubit.range(2)
    with capture_logging() as log:
        actual = cirq.IdentityOperation([a, b])
    assert len(log) == 1  # May fail if deprecated thing is used elsewhere.
    assert 'IdentityOperation' in log[0].getMessage()
    assert 'deprecated' in log[0].getMessage()

    assert actual == cirq.IdentityGate(2).on(a, b)
Пример #9
0
def test_deprecated_operations_parameter():
    with capture_logging() as log:
        op = cirq.X(cirq.LineQubit(0))
        assert not log
        # pylint: disable=unexpected-keyword-arg
        m = cirq.Moment(operations=[op])
        # pylint: enable=unexpected-keyword-arg
        assert log
    assert m == cirq.Moment(op)
Пример #10
0
def test_op_gate_of_type():
    a = cirq.NamedQubit('a')
    op = cirq.X(a)
    with capture_logging():
        assert cirq.op_gate_of_type(op, cirq.XPowGate) == op.gate
        assert cirq.op_gate_of_type(op, cirq.YPowGate) is None

        class NonGateOperation(cirq.Operation):
            def qubits(self):
                pass

            def with_qubits(self, *new_qubits):
                pass

        assert cirq.op_gate_of_type(NonGateOperation(), cirq.XPowGate) is None
Пример #11
0
def test_deprecated():
    with capture_logging() as log:
        _ = cirq.sim.bloch_vector_from_state_vector(np.array([1, 0]), 0)
    assert len(log) == 1
    assert "cirq.bloch_vector_from_state_vector" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()

    with capture_logging() as log:
        _ = cirq.sim.density_matrix_from_state_vector(np.array([1, 0]))
    assert len(log) == 1
    assert "cirq.density_matrix_from_state_vector" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()

    with capture_logging() as log:
        _ = cirq.sim.dirac_notation(np.array([1, 0]))
    assert len(log) == 1
    assert "cirq.dirac_notation" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()

    with capture_logging() as log:
        _ = cirq.sim.to_valid_state_vector(0, 1)
    assert len(log) == 1
    assert "cirq.to_valid_state_vector" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()

    with capture_logging() as log:
        _ = cirq.sim.validate_normalized_state(np.array([1, 0],
                                                        dtype=np.complex64),
                                               qid_shape=(2, ))
    assert len(log) == 1
    assert "cirq.validate_normalized_state" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()

    with capture_logging() as log:
        # Reason for type: ignore: https://github.com/python/mypy/issues/5354
        _ = cirq.sim.STATE_VECTOR_LIKE  # type: ignore
    assert len(log) == 1
    assert "cirq.STATE_VECTOR_LIKE" in log[0].getMessage()
    assert "deprecated" in log[0].getMessage()
Пример #12
0
def test_deprecated_ms(rads):
    with capture_logging():
        assert np.all(
            cirq.unitary(cirq.ms(rads)) == cirq.unitary(cirq.MS(rads)))
Пример #13
0
def test_deprecated_riswap(angle_rads):
    with capture_logging():
        assert np.all(
            cirq.unitary(cirq.ISwapRotation(angle_rads)) == cirq.unitary(
                cirq.riswap(angle_rads)))