Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove combined config #485

Merged
merged 63 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
36024c8
solved #484 without check
jannikgro May 26, 2022
473ddf7
introduced JSONConfigurable class and demanded class entry in config
jannikgro May 26, 2022
7cef3e7
added rules and verifications
jannikgro May 26, 2022
b6a4945
reintroduced test_hyperparameter_config_rl
jannikgro May 26, 2022
3fded29
reintroduced test_hyperparameter_config_market
jannikgro May 26, 2022
561fc00
tried to fix config_validation
jannikgro May 26, 2022
6986513
small change in docker_manager
jannikgro May 26, 2022
39bc238
tried with assert False
jannikgro May 26, 2022
75a674e
restored docker_manager
jannikgro May 26, 2022
f1cdf45
debug print
jannikgro May 26, 2022
068abaa
tried with dirty fix
jannikgro May 26, 2022
61c0d8e
tried without reading check
jannikgro May 26, 2022
1d1a3c4
restored last changes
jannikgro May 26, 2022
511d38a
printf debug
jannikgro May 26, 2022
de9f5eb
more printf debug
jannikgro May 26, 2022
09a433e
another printf try
jannikgro May 26, 2022
1e80e8c
next try
jannikgro May 26, 2022
1b139e0
test
jannikgro May 26, 2022
31a212f
more information
jannikgro May 26, 2022
3d3ac9d
more information
jannikgro May 26, 2022
14f181d
restored last changes
jannikgro May 26, 2022
4e174e6
restored changes
jannikgro May 26, 2022
2588f6d
preconditions for actor critic parameters and stable baselines parame…
jannikgro May 26, 2022
4107aaf
Added some debugging to docker
NikkelM May 27, 2022
c90a8d6
Fixed config validation for webserver
NikkelM May 27, 2022
1d025c9
Reintroduced `main` for testing purposes
NikkelM May 27, 2022
dd40104
Removed debug comment, fixed policyanalyzer
NikkelM May 27, 2022
da05474
New feather website
NikkelM May 27, 2022
0fa7eb5
rl config works in view
felix-20 May 30, 2022
26cb54b
Simplified and extended key validation
NikkelM May 31, 2022
7610c6e
script for creating rl model
felix-20 May 31, 2022
16df8c4
Merge branch '484-configuration-remove-combined-config' of https://gi…
felix-20 May 31, 2022
f9aa012
Fixed Agent_monitoring with stable_baselines agents
NikkelM May 31, 2022
c51dab7
renamed rl_config to q_learning_config
NikkelM Jun 1, 2022
2ccee78
Removed `class` keywords from config files
NikkelM Jun 1, 2022
c912309
Removed references to `class`-field
NikkelM Jun 1, 2022
59136b1
Fixed most tests
NikkelM Jun 1, 2022
70492c8
Fixed remaining tests(?)
NikkelM Jun 1, 2022
d326245
fix prefill
felix-20 Jun 1, 2022
135e8f3
fix webserver tests
felix-20 Jun 1, 2022
f50fe65
implement new config validation for webserver
felix-20 Jun 2, 2022
b8c43b7
New config format
NikkelM Jun 2, 2022
caf5c01
Merge branch '484-configuration-remove-combined-config' of https://gi…
NikkelM Jun 2, 2022
fff9b47
Renamed `market` to `sim_market`
NikkelM Jun 2, 2022
dca24f3
Added some tests
NikkelM Jun 2, 2022
c9657a9
Added back needed functionality of validating "complete" configs
NikkelM Jun 2, 2022
b3780cd
Fixed validation
NikkelM Jun 2, 2022
57dbb33
Webserver format
NikkelM Jun 2, 2022
bce03bd
fix webserver tests
felix-20 Jun 2, 2022
507cbc1
dynamic table for sim_market possible
felix-20 Jun 3, 2022
dac92d3
Fixed tests
NikkelM Jun 3, 2022
bd15108
Merge branch '484-configuration-remove-combined-config' of https://gi…
NikkelM Jun 3, 2022
e623413
Added `config_type` field to default modelfiles
NikkelM Jun 3, 2022
179e0da
fix javascript error
felix-20 Jun 3, 2022
6a09267
Merge branch '484-configuration-remove-combined-config' of https://gi…
felix-20 Jun 3, 2022
99ab681
Fixed config validation
NikkelM Jun 4, 2022
53d79f9
Review feedback by @SinNeax
NikkelM Jun 7, 2022
8839f90
remove `config_is_final`
felix-20 Jun 7, 2022
ab704ca
improved prefill (#496)
felix-20 Jun 7, 2022
bc9d3a3
Removed dead methods
NikkelM Jun 7, 2022
af12e13
Merge branch '484-configuration-remove-combined-config' of https://gi…
NikkelM Jun 7, 2022
ae9e85b
added common-rule for number_customers
nick-bessin Jun 8, 2022
10cc747
removed unnecessary else-condition
nick-bessin Jun 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions recommerce/configuration/common_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def greater_zero_rule(field_name: str):
return (lambda x: x > 0, f'{field_name} should be positive')


def non_negative_rule(field_name: str):
return (lambda x: x >= 0, f'{field_name} should be non-negative')


def between_zero_one_rule(field_name: str):
return (lambda x: x >= 0 and x <= 1, f'{field_name} should be between 0 (included) and 1 (included)')
134 changes: 70 additions & 64 deletions recommerce/configuration/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from recommerce.configuration.environment_config import EnvironmentConfig
from recommerce.configuration.hyperparameter_config import HyperparameterConfigValidator
from recommerce.market.circular.circular_sim_market import CircularEconomyRebuyPriceDuopoly
from recommerce.rl.q_learning.q_learning_agent import QLearningAgent


def validate_config(config: dict, config_is_final: bool) -> tuple:
Expand All @@ -29,12 +31,16 @@ def validate_config(config: dict, config_is_final: bool) -> tuple:
# try to split the config. If any keys are unknown, an AssertionError will be thrown
hyperparameter_config, environment_config = split_mixed_config(config)
# then validate that all given values have the correct types
check_config_types(hyperparameter_config, environment_config, config_is_final)
# check_config_types(hyperparameter_config, environment_config, config_is_final)

if 'rl' in hyperparameter_config:
HyperparameterConfigValidator.check_rl_ranges(hyperparameter_config['rl'], config_is_final)
hyperparameter_config['rl']['class'] = QLearningAgent # This is a dirty fix
HyperparameterConfigValidator.validate_config(hyperparameter_config['rl'])
hyperparameter_config['rl'].pop('class')
if 'sim_market' in hyperparameter_config:
HyperparameterConfigValidator.check_sim_market_ranges(hyperparameter_config['sim_market'], config_is_final)
hyperparameter_config['sim_market']['class'] = CircularEconomyRebuyPriceDuopoly # This is a dirty fix
HyperparameterConfigValidator.validate_config(hyperparameter_config['sim_market'])
hyperparameter_config['sim_market'].pop('class')

return True, (hyperparameter_config, environment_config)
except Exception as error:
Expand Down Expand Up @@ -111,64 +117,64 @@ def split_mixed_config(config: dict) -> tuple:
return hyperparameter_config, environment_config


def check_config_types(hyperparameter_config: dict, environment_config: dict, must_contain: bool = False) -> None:
"""
Utility function that checks (incomplete) config dictionaries for their correct types.

Args:
hyperparameter_config (dict): The config containing hyperparameter_config-keys.
environment_config (dict): The config containing environment_config-keys.
must_contain (bool): Whether or not the configuration should contain all required keys.

Raises:
AssertionError: If one of the values has the wrong type.
"""
# check types for hyperparameter_config
# @NikkelM Why was this here?
# HyperparameterConfigValidator.check_types(hyperparameter_config, 'top-dict', must_contain)
if 'rl' in hyperparameter_config:
HyperparameterConfigValidator.check_types(hyperparameter_config['rl'], 'rl', must_contain)
if 'sim_market' in hyperparameter_config:
HyperparameterConfigValidator.check_types(hyperparameter_config['sim_market'], 'sim_market', must_contain)

# check types for environment_config
task = environment_config['task'] if must_contain else 'None'
EnvironmentConfig.check_types(environment_config, task, False, must_contain)


if __name__ == '__main__': # pragma: no cover
test_config = {
'rl': {
'batch_size': 32,
'replay_size': 100000,
'learning_rate': 1e-6,
'sync_target_frames': 1000,
'replay_start_size': 10000,
'epsilon_decay_last_frame': 75000,
'epsilon_start': 1.0,
'epsilon_final': 0.1
},
'sim_market': {
'max_storage': 100,
'episode_length': 50,
'max_price': 10,
'max_quality': 50,
'production_price': 3,
'storage_cost_per_product': 0.1
},
'episodes': 5,
'agents': [
{
'name': 'CE Rebuy Agent (QLearning)',
'agent_class': 'recommerce.rl.q_learning.q_learning_agent.QLearningAgent',
'argument': ''
},
{
'name': 'CE Rebuy Agent (QLearaning)',
'agent_class': 'recommerce.rl.q_learning.q_learning_agent.QLearningAgent',
'argument': ''
}
]
}
hyper, env = split_mixed_config(test_config)
check_config_types(hyper, env)
# def check_config_types(hyperparameter_config: dict, environment_config: dict, must_contain: bool = False) -> None:
# """
# Utility function that checks (incomplete) config dictionaries for their correct types.

# Args:
# hyperparameter_config (dict): The config containing hyperparameter_config-keys.
# environment_config (dict): The config containing environment_config-keys.
# must_contain (bool): Whether or not the configuration should contain all required keys.

# Raises:
# AssertionError: If one of the values has the wrong type.
# """
# # check types for hyperparameter_config
# # @NikkelM Why was this here?
# # HyperparameterConfigValidator.check_types(hyperparameter_config, 'top-dict', must_contain)
# if 'rl' in hyperparameter_config:
# HyperparameterConfigValidator.check_types(hyperparameter_config['rl'], 'rl', must_contain)
# if 'sim_market' in hyperparameter_config:
# HyperparameterConfigValidator.check_types(hyperparameter_config['sim_market'], 'sim_market', must_contain)

# # check types for environment_config
# task = environment_config['task'] if must_contain else 'None'
# EnvironmentConfig.check_types(environment_config, task, False, must_contain)


# if __name__ == '__main__': # pragma: no cover
# test_config = {
# 'rl': {
# 'batch_size': 32,
# 'replay_size': 100000,
# 'learning_rate': 1e-6,
# 'sync_target_frames': 1000,
# 'replay_start_size': 10000,
# 'epsilon_decay_last_frame': 75000,
# 'epsilon_start': 1.0,
# 'epsilon_final': 0.1
# },
# 'sim_market': {
# 'max_storage': 100,
# 'episode_length': 50,
# 'max_price': 10,
# 'max_quality': 50,
# 'production_price': 3,
# 'storage_cost_per_product': 0.1
# },
# 'episodes': 5,
# 'agents': [
# {
# 'name': 'CE Rebuy Agent (QLearning)',
# 'agent_class': 'recommerce.rl.q_learning.q_learning_agent.QLearningAgent',
# 'argument': ''
# },
# {
# 'name': 'CE Rebuy Agent (QLearaning)',
# 'agent_class': 'recommerce.rl.q_learning.q_learning_agent.QLearningAgent',
# 'argument': ''
# }
# ]
# }
# hyper, env = split_mixed_config(test_config)
# check_config_types(hyper, env)
Loading