Skip to content

Commit 94706c1

Browse files
committed
test_nash_agent_w_start_solver and LIAP_AGENT_CASES
1 parent eef30ce commit 94706c1

2 files changed

Lines changed: 52 additions & 31 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ markers = [
8888
"nash_gnm_strategy: tests of gnm_solve in mixed strategies",
8989
"nash_ipa_strategy: tests of lpa_solve in mixed strategies",
9090
"nash_simpdiv: tests of simpdiv_solve (in mixed strategies)",
91+
"nash_liap_strategy: tests of liap_solve (in mixed strategies)",
92+
"nash_liap_agent: tests of liap_agent_solve (in mixed behaviors)",
9193
"qre_logit: tests of logit_solve and related methods",
9294
"qre_logit_lambda: tests of logit_solve_lambda",
9395
"qre_logit_branch: tests of logit_solve_branch",

tests/test_nash.py

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ def test_nash_strategy_solver(test_case: EquilibriumTestCase, subtests) -> None:
848848
# NASH SOLVERS WITH START PROFILES
849849
##################################################################################################
850850

851+
851852
LIAP_STRATEGY_CASES = [
852853
pytest.param(
853854
EquilibriumTestCaseWithStart(
@@ -858,8 +859,8 @@ def test_nash_strategy_solver(test_case: EquilibriumTestCase, subtests) -> None:
858859
regret_tol=TOL_LARGE,
859860
prob_tol=TOL,
860861
),
861-
marks=pytest.mark.nash_simpdiv,
862-
id="test_simpdiv_1",
862+
marks=pytest.mark.nash_liap_strategy,
863+
id="test_liap_strategy_1",
863864
),
864865
]
865866

@@ -2410,23 +2411,8 @@ def are_the_same(game, found, candidate):
24102411
]
24112412

24122413

2413-
# LIAP_AGENT_CASES = [
2414-
# pytest.param(
2415-
# EquilibriumTestCase(
2416-
# factory=functools.partial(
2417-
# games.read_from_file, "two_player_perfect_info_win_lose.efg"
2418-
# ),
2419-
# solver=functools.partial(gbt.nash.liap_agent_solve), # Need to pass the start arg
2420-
# expected=[[[[1, 0], ["1/3", "2/3"]], [["2/3", "1/3"]]]],
2421-
# ),
2422-
# marks=pytest.mark.nash_enumpure_strategy,
2423-
# id="test_liap_agent_1",
2424-
# ),
2425-
# ]
2426-
24272414
AGENT_CASES = []
24282415
AGENT_CASES += ENUMPURE_AGENT_CASES
2429-
# TO ADD: pygambit.nash.liap_agent_solve
24302416

24312417

24322418
@pytest.mark.nash
@@ -2457,24 +2443,57 @@ def test_nash_agent_solver(test_case: EquilibriumTestCase, subtests) -> None:
24572443

24582444

24592445
##################################################################################################
2460-
# TODO:
2446+
# AGENTS NASH SOLVERS WITH START PROFILE
24612447
##################################################################################################
24622448

24632449

2464-
def test_liap_agent():
2465-
"""Test calls of agent liap for mixed behavior equilibria."""
2450+
LIAP_AGENT_CASES = [
2451+
pytest.param(
2452+
EquilibriumTestCaseWithStart(
2453+
factory=functools.partial(games.read_from_file, "stripped_down_poker.efg"),
2454+
solver=gbt.nash.liap_agent_solve,
2455+
start_data=dict(data=None, rational=False),
2456+
expected=[
2457+
[[d(1, 0), d("1/3", "2/3")], [d("2/3", "1/3")]]
2458+
],
2459+
regret_tol=TOL_LARGE,
2460+
prob_tol=TOL_LARGE,
2461+
),
2462+
marks=pytest.mark.nash_liap_agent,
2463+
id="test_liap_agent_1",
2464+
),
2465+
]
24662466

2467-
game = games.read_from_file("stripped_down_poker.efg")
2468-
result = gbt.nash.liap_agent_solve(game.mixed_behavior_profile())
2469-
assert len(result.equilibria) == 1
2470-
eq = result.equilibria[0]
2467+
AGENT_WITH_START_CASES = []
2468+
AGENT_WITH_START_CASES += LIAP_AGENT_CASES
24712469

2472-
exp = [[[1, 0], ["1/3", "2/3"]], [["2/3", "1/3"]]]
2473-
exp = game.mixed_behavior_profile(exp, rational=True)
24742470

2475-
for player in game.players:
2476-
for action in player.actions:
2477-
assert abs(eq[action] - exp[action]) <= TOL_LARGE
2471+
@pytest.mark.nash
2472+
@pytest.mark.parametrize("test_case", AGENT_WITH_START_CASES, ids=lambda c: c.label)
2473+
def test_nash_agent_w_start_solver(test_case: EquilibriumTestCase, subtests) -> None:
2474+
"""Test calls of Nash solvers with starting profile in EFGs using "agent" versions.
2475+
2476+
Subtests:
2477+
- Agent max regret no more than `test_case.regret_tol`
2478+
- Agent max regret no more than max regret (+ `test_case.regret_tol`)
2479+
- Equilibria are output in the expected order. Equilibria are deemed to match if the maximum
2480+
difference in probabilities is no more than `test_case.prob_tol`
2481+
"""
2482+
game = test_case.factory()
2483+
start = game.mixed_behavior_profile(**test_case.start_data)
2484+
result = test_case.solver(start)
2485+
with subtests.test("number of equilibria found"):
2486+
assert len(result.equilibria) == len(test_case.expected)
2487+
for i, (eq, exp) in enumerate(zip(result.equilibria, test_case.expected, strict=True)):
2488+
with subtests.test(eq=i, check="agent_max_regret"):
2489+
assert eq.agent_max_regret() <= test_case.regret_tol
2490+
with subtests.test(eq=i, check="max_regret"):
2491+
assert eq.agent_max_regret() <= eq.max_regret() + test_case.regret_tol
2492+
with subtests.test(eq=i, check="strategy_profile"):
2493+
expected = game.mixed_behavior_profile(rational=True, data=exp)
2494+
for player in game.players:
2495+
for action in player.actions:
2496+
assert abs(eq[action] - expected[action]) <= test_case.prob_tol
24782497

24792498

24802499
##################################################################################################
@@ -2511,8 +2530,8 @@ def test_liap_agent():
25112530
{"idx": 1, "lam": 2, "profile": [d(0.7727, 0.2273), d(0.6117, 0.3883)]},
25122531
{"idx": 2, "lam": 3, "profile": [d(0.8595, 0.1405), d(0.6038, 0.39618)]},
25132532
],
2514-
prob_tol=TOL,
2515-
lam_tol=TOL,
2533+
prob_tol=TOL_LARGE,
2534+
lam_tol=TOL_LARGE,
25162535
),
25172536
marks=pytest.mark.qre_logit,
25182537
id="test_logit_lambda_1",

0 commit comments

Comments
 (0)