def test_max(): space = TargetSpace(target_func, PBOUNDS) assert space.max() == {} space.probe(params={"p1": 1, "p2": 2}) space.probe(params={"p1": 5, "p2": 4}) space.probe(params={"p1": 2, "p2": 3}) space.probe(params={"p1": 1, "p2": 6}) assert space.max() == {"params": {"p1": 5, "p2": 4}, "target": 9}
def test_probe(): space = TargetSpace(target_func, PBOUNDS, PTYPES) assert len(space) == 0 # probing with dict space.probe(params={"p1": 1, "p2": 2}) assert len(space) == 1 assert all(space.params[0] == np.array([1, 2])) assert all(space.target == np.array([3])) # probing with array space.probe(np.array([5, 4])) assert len(space) == 2 assert all(space.params[1] == np.array([5, 4])) assert all(space.target == np.array([3, 9])) # probing same point with dict space.probe(params={"p1": 1, "p2": 2}) assert len(space) == 2 assert all(space.params[1] == np.array([5, 4])) assert all(space.target == np.array([3, 9])) # probing same point with array space.probe(np.array([5, 4])) assert len(space) == 2 assert all(space.params[1] == np.array([5, 4])) assert all(space.target == np.array([3, 9]))
def test_res(): space = TargetSpace(target_func, PBOUNDS) assert space.res() == [] space.probe(params={"p1": 1, "p2": 2}) space.probe(params={"p1": 5, "p2": 4}) space.probe(params={"p1": 2, "p2": 3}) space.probe(params={"p1": 1, "p2": 6}) expected_res = [ {"params": {"p1": 1, "p2": 2}, "target": 3}, {"params": {"p1": 5, "p2": 4}, "target": 9}, {"params": {"p1": 2, "p2": 3}, "target": 5}, {"params": {"p1": 1, "p2": 6}, "target": 7}, ] assert len(space.res()) == 4 assert space.res() == expected_res