Skip to content

Commit

Permalink
Add CI to develop branch (#20)
Browse files Browse the repository at this point in the history
Update continuous_integration.yml

* Add CI to develop branch
* Add deadline to CMAB tests
  • Loading branch information
dariodandrea authored Oct 16, 2023
1 parent 55c3206 commit 92d6c5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ name: CI

on:
push:
branches: [master]
branches:
- master
- develop # Add the develop branch here
pull_request:
branches: [master]
branches:
- master
- develop # Add the develop branch here

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
16 changes: 14 additions & 2 deletions tests/test_cmab.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# CmabBernoulli with strategy=ClassicBandit()


@settings(deadline=500)
@given(st.integers(max_value=100))
def test_create_cmab_bernoulli_cold_start(a_int):
# n_features must be > 0
Expand All @@ -71,6 +72,7 @@ def test_create_cmab_bernoulli_cold_start(a_int):
assert mab1 == mab2


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=10))
def test_cmab_can_instantiate(n_features):
with pytest.raises(TypeError):
Expand Down Expand Up @@ -119,6 +121,7 @@ def test_cmab_can_instantiate(n_features):
assert mab.predict_with_proba


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=10), st.integers(min_value=1, max_value=10))
def test_cmab_init_with_wrong_blr_models(a, b):
# all blr models must have the same n_betas. If not raise a ValueError.
Expand Down Expand Up @@ -185,6 +188,7 @@ def test_cmab_update_not_all_actions(n_samples=100, n_feat=3):
mab.actions["a4"] != create_bayesian_logistic_regression_cold_start(n_betas=n_feat)


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=1000), st.integers(min_value=1, max_value=100))
def test_cmab_update_shape_mismatch(n_samples, n_features):
actions = np.random.choice(["a1", "a2"], size=n_samples).tolist()
Expand All @@ -204,6 +208,7 @@ def test_cmab_update_shape_mismatch(n_samples, n_features):
mab.update(context=[], actions=actions, rewards=rewards)


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=1000), st.integers(min_value=1, max_value=100))
def test_cmab_predict_cold_start(n_samples, n_features):
def run_predict(context):
Expand Down Expand Up @@ -231,7 +236,7 @@ def run_predict(context):
run_predict(context=context)


@settings(deadline=400) # Set the deadline to 400 ms
@settings(deadline=500)
@given(st.integers(min_value=1, max_value=100), st.integers(min_value=1, max_value=3))
def test_cmab_predict_not_cold_start(n_samples, n_features):
def run_predict(context):
Expand Down Expand Up @@ -261,6 +266,7 @@ def run_predict(context):
run_predict(context=context)


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=10))
def test_cmab_predict_shape_mismatch(a_int):
context = np.random.uniform(low=-1.0, high=1.0, size=(100, a_int - 1))
Expand Down Expand Up @@ -312,6 +318,7 @@ def run_predict(mab):
# CmabBernoulli with strategy=BestActionIdentification()


@settings(deadline=500)
@given(st.integers(max_value=100))
def test_create_cmab_bernoulli_bai_cold_start(a_int):
# n_features must be > 0
Expand Down Expand Up @@ -343,6 +350,7 @@ def test_create_cmab_bernoulli_bai_cold_start(a_int):
assert mab1 == mab2


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=10))
def test_cmab_bai_can_instantiate(n_features):
with pytest.raises(TypeError):
Expand Down Expand Up @@ -400,6 +408,7 @@ def test_cmab_bai_can_instantiate(n_features):
assert mab.strategy == BestActionIdentification(exploit_p=0.42)


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=100), st.integers(min_value=1, max_value=3))
def test_cmab_bai_predict(n_samples, n_features):
context = np.random.uniform(low=-1.0, high=1.0, size=(n_samples, n_features))
Expand Down Expand Up @@ -445,9 +454,10 @@ def test_cmab_bai_update(n_samples=100, n_features=3):
########################################################################################################################


# SmabBernoulli with strategy=CostControlBandit()
# CmabBernoulli with strategy=CostControlBandit()


@settings(deadline=500)
@given(st.integers(max_value=100))
def test_create_cmab_bernoulli_cc_cold_start(a_int):
action_ids_cost = {"a1": 10, "a2": 20.5}
Expand Down Expand Up @@ -482,6 +492,7 @@ def test_create_cmab_bernoulli_cc_cold_start(a_int):
assert mab1 == mab2


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=10))
def test_cmab_cc_can_instantiate(n_features):
with pytest.raises(TypeError):
Expand Down Expand Up @@ -539,6 +550,7 @@ def test_cmab_cc_can_instantiate(n_features):
assert mab.strategy == CostControlBandit(subsidy_factor=0.42)


@settings(deadline=500)
@given(st.integers(min_value=1, max_value=100), st.integers(min_value=1, max_value=3))
def test_cmab_cc_predict(n_samples, n_features):
context = np.random.uniform(low=-1.0, high=1.0, size=(n_samples, n_features))
Expand Down

0 comments on commit 92d6c5b

Please sign in to comment.