コード例 #1
0
ファイル: test_backends_init.py プロジェクト: mlazzarin/qibo
def test_set_precision(backend, precision):
    original_precision = backends.get_precision()
    backends.set_precision(precision)
    if precision == "single":
        expected_dtype = K.backend.complex64
    else:
        expected_dtype = K.backend.complex128
    assert backends.get_precision() == precision
    assert K.dtypes('DTYPECPX') == expected_dtype
    # Test that circuits use proper precision
    circuit = models.Circuit(2)
    circuit.add([gates.H(0), gates.H(1)])
    final_state = circuit()
    assert final_state.dtype == expected_dtype
    backends.set_precision(original_precision)
コード例 #2
0
ファイル: test_backends_init.py プロジェクト: NourO93/qibo
def test_set_precision_errors():
    original_precision = backends.get_precision()
    gate = gates.H(0)
    with pytest.warns(RuntimeWarning):
        backends.set_precision("single")
    with pytest.raises(ValueError):
        backends.set_precision("test")
    backends.set_precision(original_precision)
コード例 #3
0
ファイル: test_backends_init.py プロジェクト: mlazzarin/qibo
def test_set_precision_errors(backend, caplog):
    original_precision = backends.get_precision()
    gate = gates.H(0)
    backends.set_precision("single")
    assert "WARNING" in caplog.text
    with pytest.raises(ValueError):
        backends.set_precision("test")
    backends.set_precision(original_precision)
コード例 #4
0
ファイル: test_backends_init.py プロジェクト: mlazzarin/qibo
def test_set_precision_matrices(backend, precision):
    import numpy as np
    from qibo import matrices
    original_precision = backends.get_precision()
    backends.set_precision(precision)
    if precision == "single":
        assert matrices.dtype == "complex64"
        assert matrices.H.dtype == np.complex64
        assert K.matrices.dtype == "complex64"
        assert K.matrices.X.dtype == K.backend.complex64
    else:
        assert matrices.dtype == "complex128"
        assert matrices.H.dtype == np.complex128
        assert K.matrices.dtype == "complex128"
        assert K.matrices.X.dtype == K.backend.complex128
    backends.set_precision(original_precision)