Skip to content

Commit 4dfb30d

Browse files
committed
new testing and setup
1 parent 14c35bd commit 4dfb30d

10 files changed

Lines changed: 44 additions & 33 deletions

File tree

PyXAB/algos/GPO.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ def pull(self, time):
9898
self.curr_algo = self.algo(
9999
nu=self.numax, rho=rho, domain=self.domain, partition=self.partition
100100
)
101-
else:
102-
# TODO: add more algorithms that do not need nu or rho
103-
raise NotImplementedError('GPO has not yet included implementations for this algorithm')
101+
# TODO: add more algorithms that do not need nu or rho
104102
if self.counter < self.half_phase_length:
105103
point = self.curr_algo.pull(time)
106104
self.goodx = point

PyXAB/algos/POO.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ def pull(self, time):
9797
self.curr_algo = self.algo(
9898
nu=self.numax, rho=rho, domain=self.domain, partition=self.partition
9999
)
100-
else:
101-
# TODO: add more algorithms that do not need nu or rho
102-
raise NotImplementedError('POO has not yet included implementations for this algorithm')
100+
# TODO: add more algorithms that do not need nu or rho
103101
self.V_algo.append(self.curr_algo)
104102
self.V_reward.append(0)
105103
self.Times.append(0)

PyXAB/tests/test_algos/test_DOO.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
def test_DOO_ValueError_1():
1313
partition = BinaryPartition
1414
with pytest.raises(ValueError):
15-
algo = DOO(partition=partition)
15+
DOO(partition=partition)
1616

1717
def test_DOO_ValueError_2():
1818
domain = [[0, 1]]
1919
with pytest.raises(ValueError):
20-
algo = DOO(domain=domain)
20+
DOO(domain=domain)
2121

2222
def test_DOO_DoubleSine():
2323
T = 500

PyXAB/tests/test_algos/test_POO.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def test_POO_value_error_3():
3535
def test_POO_not_implemented_error():
3636
# wrong algorithm
3737
T = 100
38-
Target = Garland.Garland()
3938
domain = [[0, 1]]
4039
partition = BinaryPartition
4140
with pytest.raises(NotImplementedError):

PyXAB/tests/test_algos/test_SOO.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
def test_SOO_ValueError_1():
1414
partition = BinaryPartition
1515
with pytest.raises(ValueError):
16-
algo = SOO(partition=partition)
16+
SOO(partition=partition)
1717

1818
def test_SOO_ValueError_2():
1919
domain = [[0, 1]]
2020
with pytest.raises(ValueError):
21-
algo = SOO(domain=domain)
21+
SOO(domain=domain)
2222

2323
def test_SOO_Garland():
2424
T = 100

PyXAB/tests/test_algos/test_SequOOL.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
def test_SequOOL_ValueError_1():
1212
partition = BinaryPartition
1313
with pytest.raises(ValueError):
14-
algo = SequOOL(partition=partition)
14+
SequOOL(partition=partition)
1515

1616
def test_SequOOL_ValueError_2():
1717
domain = [[0, 1]]
1818
with pytest.raises(ValueError):
19-
algo = SequOOL(domain=domain)
19+
SequOOL(domain=domain)
2020

2121
def test_SequOOL_DoubleSine():
2222
T = 500
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from PyXAB.partition.DimensionBinaryPartition import DimensionBinaryPartition
2+
from numpy.testing import assert_allclose
23
import pytest
3-
4+
import copy
45

56
def test_dimension_binary_partition_value_error():
67
with pytest.raises(ValueError):
@@ -14,17 +15,26 @@ def test_dimension_binary_partition_1D_deepen():
1415
for i in range(5):
1516
part.deepen()
1617
nodelist = part.get_node_list()
17-
for node in nodelist[-1]:
18-
print(node.depth, node.index, node.domain, "\\")
19-
print(part.get_root().get_domain())
18+
for j in range(len(nodelist[-1])):
19+
assert_allclose(
20+
nodelist[-1][j].get_domain(),
21+
[[j / (2 ** (i + 1)), (j + 1) / (2 ** (i + 1))]],
22+
)
2023

2124

2225
def test_dimension_binary_partition_3D_deepen():
23-
domain = [[0, 1], [10, 50], [-5, -10]]
26+
domain = [[0, 1], [0, 1], [0, 1]]
2427
part = DimensionBinaryPartition(domain)
25-
26-
for i in range(2):
28+
for i in range(5):
2729
part.deepen()
28-
nodelist = part.get_node_list()
29-
for node in nodelist[-1]:
30-
print(node.depth, node.index, node.domain, "\\")
30+
nodelist = part.get_node_list()
31+
32+
for depth in range(part.get_depth() - 1):
33+
for parent in nodelist[depth]:
34+
parent_domain = parent.get_domain()
35+
children = parent.get_children()
36+
37+
children_domain = []
38+
for child in children:
39+
children_domain.append(child.get_domain())
40+
print(child.get_depth(), child.get_index(), child.get_domain(), "\\")

PyXAB/tests/test_partition/test_random_kary_partition.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from PyXAB.partition.RandomKaryPartition import RandomKaryPartition
2+
from numpy.testing import assert_allclose
23
import pytest
34

45

@@ -7,15 +8,20 @@ def test_random_kary_partition_value_error():
78
RandomKaryPartition()
89

910

10-
def test_random_kary_partition_1D_deepen():
11+
def test_random_kary_partition_1D_K3_make_children():
1112
domain = [[0, 1]]
12-
part = RandomKaryPartition(domain)
13-
14-
for i in range(5):
15-
part.deepen()
16-
nodelist = part.get_node_list()
17-
for node in nodelist[-1]:
18-
print(node.depth, node.index, node.domain, "\\")
13+
part = RandomKaryPartition(domain, K=3)
14+
15+
parent = part.get_root()
16+
part.make_children(parent, newlayer=True)
17+
newlayer = part.get_node_list()[-1]
18+
assert newlayer[0].get_domain()[0][1] == newlayer[1].get_domain()[0][0] # [[0, n1]] and [[n1, n2]] and [[n2, 1]]
19+
assert newlayer[1].get_domain()[0][1] == newlayer[2].get_domain()[0][0]
20+
assert 1 >= newlayer[0].get_domain()[0][1] >= 0
21+
assert 1 >= newlayer[1].get_domain()[0][1] >= 0
22+
assert_allclose(newlayer[0].get_domain(), [[0, newlayer[0].get_domain()[0][1]]])
23+
assert_allclose(newlayer[1].get_domain(), [[newlayer[0].get_domain()[0][1], newlayer[1].get_domain()[0][1]]])
24+
assert_allclose(newlayer[2].get_domain(), [[newlayer[1].get_domain()[0][1], 1]])
1925

2026

2127
def test_random_kary_partition_3D_deepen():

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
author = 'Wenjie Li'
2424

2525
# The full version, including alpha/beta/rc tags
26-
release = '0.1.2'
26+
release = '0.2.0'
2727

2828

2929
# -- General configuration ---------------------------------------------------

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
EMAIL = 'lil3549@purdue.edu'
1919
AUTHOR = 'Wenjie Li, Haoze Li'
2020
REQUIRES_PYTHON = '>=3.6.0'
21-
VERSION = '0.1.2'
21+
VERSION = '0.2.0'
2222

2323
# What packages are required for this module to be executed?
2424
REQUIRED = [

0 commit comments

Comments
 (0)