Exemple #1
0
def test_update_history_f():
    hist, sim_specs, _, _, _ = setup.hist_setup2()
    exp_vals = [0.0] * 10

    # First update a single point
    size = 1
    sim_ids = 0  # First row to be filled
    sim_ids = np.atleast_1d(sim_ids)
    calc_out = np.zeros(size, dtype=sim_specs['out'])
    a = np.arange(9) - 4
    calc_out['g'] = sim_specs['sim_f'](a)  #np.linalg.norm
    exp_vals[0] = calc_out['g'][0]
    D_recv = {
        'calc_out': calc_out,
        'persis_info': {},
        'libE_info': {
            'H_rows': sim_ids
        },
        'calc_status': WORKER_DONE,
        'calc_type': 2
    }

    hist.update_history_f(D_recv)
    assert isclose(exp_vals[0], hist.H['g'][0])
    assert np.all(hist.H['returned'][0:1])
    assert np.all(hist.H['returned'][1:10] == False)  #Check the rest
    assert hist.sim_count == 1
    assert hist.given_count == 0  # In real case this would be ahead.....
    assert hist.index == 0  # In real case this would be ahead....

    # Update two further consecutive points
    size = 2
    sim_ids = [1, 2]  # First row to be filled
    sim_ids = np.atleast_1d(sim_ids)
    calc_out = np.zeros(size, dtype=sim_specs['out'])
    a = np.arange(9) - 3
    calc_out['g'][0] = sim_specs['sim_f'](a)  #np.linalg.norm
    exp_vals[1] = calc_out['g'][0]
    a = np.arange(9) - 2
    calc_out['g'][1] = sim_specs['sim_f'](a)  #np.linalg.norm
    exp_vals[2] = calc_out['g'][1]
    D_recv = {
        'calc_out': calc_out,
        'persis_info': {},
        'libE_info': {
            'H_rows': sim_ids
        },
        'calc_status': WORKER_DONE,
        'calc_type': 2
    }

    hist.update_history_f(D_recv)
    assert np.allclose(exp_vals, hist.H['g'])
    assert np.all(hist.H['returned'][0:3])
    assert np.all(hist.H['returned'][3:10] == False)  #Check the rest
    assert hist.sim_count == 3
    assert hist.given_count == 0  # In real case this would be ahead.....
    assert hist.index == 0  # In real case this would be ahead....
Exemple #2
0
def test_update_history_x_in_Oempty():
    hist, sim_specs, gen_specs, _, _ = setup.hist_setup2()
    O = np.zeros(0, dtype=gen_specs['out'])
    gen_worker = 1
    hist.update_history_x_in(gen_worker, O)
    assert np.array_equal(hist.H, wrs2), "H Array does not match expected"
    assert hist.given_count == 0
    assert hist.index == 0
    assert hist.sim_count == 0
Exemple #3
0
def test_update_history_x_in():
    hist, _, gen_specs, _, _ = setup.hist_setup2(7)
    #import pdb; pdb.set_trace()
    #calc_in = hist.H[gen_specs['in']][0]

    np.random.seed(1)
    single_rand = gen_specs['gen_f']()  # np.random.uniform()

    # Check seeded correctly going in
    assert isclose(
        single_rand,
        0.417022004702574), "Random numbers not correct before function"

    size = 1
    gen_worker = 2
    O = np.zeros(size, dtype=gen_specs['out'])
    O['x'] = single_rand

    hist.update_history_x_in(gen_worker, O)
    assert isclose(single_rand, hist.H['x'][0])
    assert hist.given_count == 0
    assert hist.index == 1
    assert hist.sim_count == 0

    size = 6
    gen_worker = 3
    O = np.zeros(size, dtype=gen_specs['out'])
    O['x'] = gen_specs['gen_f'](size=size)

    hist.update_history_x_in(gen_worker, O)
    # Compare by column
    exp_x = exp_x_in_setup2[:size + 1]
    for field in exp_x.dtype.names:
        np.allclose(hist.H[field], exp_x[field])

    assert hist.given_count == 0
    assert hist.index == 7
    assert hist.sim_count == 0

    # Force H to grow when add points
    size = 3
    gen_worker = 3
    O = np.zeros(size, dtype=gen_specs['out'])
    O['x'] = gen_specs['gen_f'](size=size)

    hist.update_history_x_in(gen_worker, O)
    # Compare by column
    exp_x = exp_x_in_setup2
    for field in exp_x.dtype.names:
        np.allclose(hist.H[field], exp_x[field])

    assert hist.given_count == 0
    assert hist.index == 10
    assert hist.sim_count == 0
def test_term_test_3():
    # Test 3.
    # Terminate because enough time has passed
    H0 = np.zeros(3,
                  dtype=[('g', float)] + [('x', float), ('priority', float)])
    hist, sim_specs, gen_specs, exit_criteria, al = setup.hist_setup2(H0_in=H0)
    mgr = man.Manager(hist, libE_specs, al, sim_specs, gen_specs,
                      exit_criteria)
    hist.index = 4
    hist.H['given_time'][0] = time.time()
    time.sleep(0.5)
    hist.given_count = 4
    assert mgr.term_test()
Exemple #5
0
def test_term_test_2():
    # Test 2 - these could also be sep - with a setup or fixture....
    # Shouldn't terminate
    hist, sim_specs, gen_specs, exit_criteria, al = setup.hist_setup2()
    mgr = man.Manager(hist, libE_specs, al, sim_specs, gen_specs,
                      exit_criteria)
    assert not mgr.term_test()
    #
    # Terminate because we've found a good 'g' value
    hist.H['g'][0] = -1
    hist.H['returned'][0] = True
    hist.index = 1
    hist.given_count = 1
    assert mgr.term_test()
    #
    # Terminate because everything has been given.
    hist.H['given'] = np.ones
    hist.given_count = len(hist.H)
    assert mgr.term_test()
Exemple #6
0
def test_hist_init_2():
    hist, _, _, _, _ = setup.hist_setup2()
    assert np.array_equal(hist.H, wrs2), "Array does not match expected"
    assert hist.given_count == 0
    assert hist.index == 0
    assert hist.sim_count == 0