def test_unparsed_args(): with pytest.raises(ValueError, match='Unparsed arguments'): run( shlex.split( '--random-seed 12345 --T 100 --n-runs 200 --environment rlai.environments.bandit.KArmedBandit --k 10 --agent rlai.agents.q_value.EpsilonGreedy --epsilon 0.2 0.0 --testing' ))
def test_plot(): # without pdf (without random seed) run( shlex.split( '--T 100 --n-runs 200 --environment rlai.environments.bandit.KArmedBandit --k 10 --agent rlai.agents.q_value.EpsilonGreedy --epsilon 0.2 0.0 --plot --figure-name test' )) # with pdf run( shlex.split( f'--random-seed 12345 --T 100 --n-runs 200 --environment rlai.environments.bandit.KArmedBandit --k 10 --agent rlai.agents.q_value.EpsilonGreedy --epsilon 0.2 0.0 --plot --pdf-save-path {tempfile.NamedTemporaryFile(delete=False).name}' ))
def test_mancala(): monitors = run( shlex.split( f'--random-seed 12345 --T 100 --n-runs 200 --environment rlai.environments.mancala.Mancala --initial-count 4 --agent {dump_agent()}' )) # uncomment the following line and run test to update fixture # with open(f'{os.path.dirname(__file__)}/fixtures/test_mancala.pickle', 'wb') as file: # pickle.dump(monitors, file) with open(f'{os.path.dirname(__file__)}/fixtures/test_mancala.pickle', 'rb') as file: monitors_fixture = pickle.load(file) assert_monitors(monitors, monitors_fixture)
def test_k_armed_bandit_epsilon_greedy_optimistic(): monitors = run( shlex.split( '--random-seed 12345 --T 100 --n-runs 200 --environment rlai.environments.bandit.KArmedBandit --k 10 --agent rlai.agents.q_value.EpsilonGreedy --epsilon 0.0 --initial-q-value 5 --alpha 0.1' )) # uncomment the following line and run test to update fixture # with open(f'{os.path.dirname(__file__)}/fixtures/test_k_armed_bandit_epsilon_greedy_optimistic.pickle', 'wb') as file: # pickle.dump(monitors, file) with open( f'{os.path.dirname(__file__)}/fixtures/test_k_armed_bandit_epsilon_greedy_optimistic.pickle', 'rb') as file: monitors_fixture = pickle.load(file) assert_monitors(monitors, monitors_fixture)
def test_gamblers_problem(): monitors = run( shlex.split( f'--random-seed 12345 --T 100 --n-runs 200 --environment rlai.environments.gamblers_problem.GamblersProblem --p-h 0.4 --agent {dump_agent()} --log INFO' )) # uncomment the following line and run test to update fixture # with open(f'{os.path.dirname(__file__)}/fixtures/test_gamblers_problem.pickle', 'wb') as file: # pickle.dump(monitors, file) with open( f'{os.path.dirname(__file__)}/fixtures/test_gamblers_problem.pickle', 'rb') as file: monitors_fixture = pickle.load(file) assert_monitors(monitors, monitors_fixture)
def test_k_armed_bandit_preference_gradient_without_baseline(): monitors = run( shlex.split( '--random-seed 12345 --T 100 --n-runs 200 --environment rlai.environments.bandit.KArmedBandit --k 10 --q-star-mean 4 --agent rlai.agents.h_value.PreferenceGradient --step-size-alpha 0.1' )) # uncomment the following line and run test to update fixture # with open(f'{os.path.dirname(__file__)}/fixtures/test_k_armed_bandit_preference_gradient_without_baseline.pickle', 'wb') as file: # pickle.dump(monitors, file) with open( f'{os.path.dirname(__file__)}/fixtures/test_k_armed_bandit_preference_gradient_without_baseline.pickle', 'rb') as file: monitors_fixture = pickle.load(file) assert_monitors(monitors, monitors_fixture)
def test_k_armed_bandit_upper_confidence_bound(): monitors = run( shlex.split( '--random-seed 12345 --T 100 --n-runs 200 --environment rlai.environments.bandit.KArmedBandit --k 10 --agent rlai.agents.q_value.UpperConfidenceBound --c 0 1' )) # uncomment the following line and run test to update fixture # with open(f'{os.path.dirname(__file__)}/fixtures/test_k_armed_bandit_upper_confidence_bound.pickle', 'wb') as file: # pickle.dump(monitors, file) with open( f'{os.path.dirname(__file__)}/fixtures/test_k_armed_bandit_upper_confidence_bound.pickle', 'rb') as file: monitors_fixture = pickle.load(file) assert_monitors(monitors, monitors_fixture)