Skip to content

Commit

Permalink
new testing and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamLwj committed Mar 21, 2023
1 parent 14c35bd commit 4dfb30d
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 33 deletions.
4 changes: 1 addition & 3 deletions PyXAB/algos/GPO.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ def pull(self, time):
self.curr_algo = self.algo(
nu=self.numax, rho=rho, domain=self.domain, partition=self.partition
)
else:
# TODO: add more algorithms that do not need nu or rho
raise NotImplementedError('GPO has not yet included implementations for this algorithm')
# TODO: add more algorithms that do not need nu or rho
if self.counter < self.half_phase_length:
point = self.curr_algo.pull(time)
self.goodx = point
Expand Down
4 changes: 1 addition & 3 deletions PyXAB/algos/POO.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def pull(self, time):
self.curr_algo = self.algo(
nu=self.numax, rho=rho, domain=self.domain, partition=self.partition
)
else:
# TODO: add more algorithms that do not need nu or rho
raise NotImplementedError('POO has not yet included implementations for this algorithm')
# TODO: add more algorithms that do not need nu or rho
self.V_algo.append(self.curr_algo)
self.V_reward.append(0)
self.Times.append(0)
Expand Down
4 changes: 2 additions & 2 deletions PyXAB/tests/test_algos/test_DOO.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
def test_DOO_ValueError_1():
partition = BinaryPartition
with pytest.raises(ValueError):
algo = DOO(partition=partition)
DOO(partition=partition)

def test_DOO_ValueError_2():
domain = [[0, 1]]
with pytest.raises(ValueError):
algo = DOO(domain=domain)
DOO(domain=domain)

def test_DOO_DoubleSine():
T = 500
Expand Down
1 change: 0 additions & 1 deletion PyXAB/tests/test_algos/test_POO.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_POO_value_error_3():
def test_POO_not_implemented_error():
# wrong algorithm
T = 100
Target = Garland.Garland()
domain = [[0, 1]]
partition = BinaryPartition
with pytest.raises(NotImplementedError):
Expand Down
4 changes: 2 additions & 2 deletions PyXAB/tests/test_algos/test_SOO.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
def test_SOO_ValueError_1():
partition = BinaryPartition
with pytest.raises(ValueError):
algo = SOO(partition=partition)
SOO(partition=partition)

def test_SOO_ValueError_2():
domain = [[0, 1]]
with pytest.raises(ValueError):
algo = SOO(domain=domain)
SOO(domain=domain)

def test_SOO_Garland():
T = 100
Expand Down
4 changes: 2 additions & 2 deletions PyXAB/tests/test_algos/test_SequOOL.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
def test_SequOOL_ValueError_1():
partition = BinaryPartition
with pytest.raises(ValueError):
algo = SequOOL(partition=partition)
SequOOL(partition=partition)

def test_SequOOL_ValueError_2():
domain = [[0, 1]]
with pytest.raises(ValueError):
algo = SequOOL(domain=domain)
SequOOL(domain=domain)

def test_SequOOL_DoubleSine():
T = 500
Expand Down
30 changes: 20 additions & 10 deletions PyXAB/tests/test_partition/test_dimension_binary_partition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from PyXAB.partition.DimensionBinaryPartition import DimensionBinaryPartition
from numpy.testing import assert_allclose
import pytest

import copy

def test_dimension_binary_partition_value_error():
with pytest.raises(ValueError):
Expand All @@ -14,17 +15,26 @@ def test_dimension_binary_partition_1D_deepen():
for i in range(5):
part.deepen()
nodelist = part.get_node_list()
for node in nodelist[-1]:
print(node.depth, node.index, node.domain, "\\")
print(part.get_root().get_domain())
for j in range(len(nodelist[-1])):
assert_allclose(
nodelist[-1][j].get_domain(),
[[j / (2 ** (i + 1)), (j + 1) / (2 ** (i + 1))]],
)


def test_dimension_binary_partition_3D_deepen():
domain = [[0, 1], [10, 50], [-5, -10]]
domain = [[0, 1], [0, 1], [0, 1]]
part = DimensionBinaryPartition(domain)

for i in range(2):
for i in range(5):
part.deepen()
nodelist = part.get_node_list()
for node in nodelist[-1]:
print(node.depth, node.index, node.domain, "\\")
nodelist = part.get_node_list()

for depth in range(part.get_depth() - 1):
for parent in nodelist[depth]:
parent_domain = parent.get_domain()
children = parent.get_children()

children_domain = []
for child in children:
children_domain.append(child.get_domain())
print(child.get_depth(), child.get_index(), child.get_domain(), "\\")
22 changes: 14 additions & 8 deletions PyXAB/tests/test_partition/test_random_kary_partition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from PyXAB.partition.RandomKaryPartition import RandomKaryPartition
from numpy.testing import assert_allclose
import pytest


Expand All @@ -7,15 +8,20 @@ def test_random_kary_partition_value_error():
RandomKaryPartition()


def test_random_kary_partition_1D_deepen():
def test_random_kary_partition_1D_K3_make_children():
domain = [[0, 1]]
part = RandomKaryPartition(domain)

for i in range(5):
part.deepen()
nodelist = part.get_node_list()
for node in nodelist[-1]:
print(node.depth, node.index, node.domain, "\\")
part = RandomKaryPartition(domain, K=3)

parent = part.get_root()
part.make_children(parent, newlayer=True)
newlayer = part.get_node_list()[-1]
assert newlayer[0].get_domain()[0][1] == newlayer[1].get_domain()[0][0] # [[0, n1]] and [[n1, n2]] and [[n2, 1]]
assert newlayer[1].get_domain()[0][1] == newlayer[2].get_domain()[0][0]
assert 1 >= newlayer[0].get_domain()[0][1] >= 0
assert 1 >= newlayer[1].get_domain()[0][1] >= 0
assert_allclose(newlayer[0].get_domain(), [[0, newlayer[0].get_domain()[0][1]]])
assert_allclose(newlayer[1].get_domain(), [[newlayer[0].get_domain()[0][1], newlayer[1].get_domain()[0][1]]])
assert_allclose(newlayer[2].get_domain(), [[newlayer[1].get_domain()[0][1], 1]])


def test_random_kary_partition_3D_deepen():
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = 'Wenjie Li'

# The full version, including alpha/beta/rc tags
release = '0.1.2'
release = '0.2.0'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
EMAIL = '[email protected]'
AUTHOR = 'Wenjie Li, Haoze Li'
REQUIRES_PYTHON = '>=3.6.0'
VERSION = '0.1.2'
VERSION = '0.2.0'

# What packages are required for this module to be executed?
REQUIRED = [
Expand Down

0 comments on commit 4dfb30d

Please sign in to comment.