예제 #1
0
def test_numpy_types():
    """
    Test that we can save numpy types in the data set
    """

    p = ParamSpecBase(name="p", paramtype="numeric")
    test_set = qc.new_data_set("test-dataset")
    test_set.set_interdependencies(InterDependencies_(standalones=(p, )))
    test_set.mark_started()

    idps = InterDependencies_(standalones=(p, ))

    data_saver = DataSaver(dataset=test_set, write_period=0, interdeps=idps)

    dtypes = [
        np.int8, np.int16, np.int32, np.int64, np.float16, np.float32,
        np.float64
    ]

    for dtype in dtypes:
        data_saver.add_result(("p", dtype(2)))

    data_saver.flush_data_to_database()
    data = test_set.get_data("p")
    assert data == [[2] for _ in range(len(dtypes))]
예제 #2
0
def test_numpy_types(bg_writing):
    """
    Test that we can save numpy types in the data set
    """

    p = ParamSpecBase(name="p", paramtype="numeric")
    test_set = qc.new_data_set("test-dataset")
    test_set.set_interdependencies(InterDependencies_(standalones=(p, )))
    test_set.mark_started(start_bg_writer=bg_writing)

    idps = InterDependencies_(standalones=(p, ))

    data_saver = DataSaver(dataset=test_set,
                           write_period=0,
                           interdeps=idps,
                           write_in_background=bg_writing)

    dtypes = [
        np.int8, np.int16, np.int32, np.int64, np.float16, np.float32,
        np.float64
    ]

    for dtype in dtypes:
        data_saver.add_result(("p", dtype(2)))

    data_saver.flush_data_to_database()
    test_set.mark_completed()
    data = test_set.get_parameter_data("p")["p"]["p"]
    expected_data = np.ones(len(dtypes))
    expected_data[:] = 2
    np.testing.assert_array_equal(data, expected_data)
예제 #3
0
def test_string(experiment):
    """
    Test that we can save text in the data set
    """
    p = ParamSpec("p", "text")

    test_set = qc.new_data_set("test-dataset")
    test_set.add_parameter(p)
    data_saver = DataSaver(dataset=test_set,
                           write_period=0,
                           parameters={"p": p})

    data_saver.add_result(("p", "some text"))
    data_saver.flush_data_to_database()
    assert test_set.get_data("p") == [["some text"]]
예제 #4
0
def test_string_via_datasaver(experiment):
    """
    Test that we can save text into database via DataSaver API
    """
    p = ParamSpecBase(name="p", paramtype="text")

    test_set = qc.new_data_set("test-dataset")
    idps = InterDependencies_(standalones=(p, ))
    test_set.prepare(snapshot={}, interdeps=idps)

    idps = InterDependencies_(standalones=(p, ))

    data_saver = DataSaver(dataset=test_set, write_period=0, interdeps=idps)

    data_saver.add_result(("p", "some text"))
    data_saver.flush_data_to_database()

    assert test_set.get_parameter_data()["p"]["p"] == np.array(["some text"])
예제 #5
0
def test_string_via_datasaver(experiment):
    """
    Test that we can save text into database via DataSaver API
    """
    p = ParamSpec(name="p", paramtype="text")

    test_set = qc.new_data_set("test-dataset")
    test_set.add_parameter(p)
    test_set.mark_started()

    idps = InterDependencies_(standalones=(p.base_version(), ))

    data_saver = DataSaver(dataset=test_set, write_period=0, interdeps=idps)

    data_saver.add_result(("p", "some text"))
    data_saver.flush_data_to_database()

    assert test_set.get_data("p") == [["some text"]]
예제 #6
0
def test_numpy_types():
    """
    Test that we can save numpy types in the data set
    """

    p = ParamSpec("p", "numeric")
    test_set = qc.new_data_set("test-dataset")
    test_set.add_parameter(p)
    test_set.mark_started()

    data_saver = DataSaver(
        dataset=test_set, write_period=0, parameters={"p": p})

    dtypes = [np.int8, np.int16, np.int32, np.int64, np.float16, np.float32,
              np.float64]

    for dtype in dtypes:
        data_saver.add_result(("p", dtype(2)))

    data_saver.flush_data_to_database()
    data = test_set.get_data("p")
    assert data == [[2] for _ in range(len(dtypes))]