Skip to content

Commit

Permalink
update ray version
Browse files Browse the repository at this point in the history
  • Loading branch information
kengz committed Nov 28, 2018
1 parent 399dce1 commit 6122e34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Expand Up @@ -54,7 +54,7 @@ dependencies:
- opencv-python==3.4.0.12
- plotly==3.2.1
- pyopengl==3.1.0
- ray==0.3.1
- ray==0.5.3
- redis==2.10.6
- unityagents==0.2.0
- vizdoom==1.1.6
Expand Down
20 changes: 14 additions & 6 deletions slm_lab/experiment/search.py
@@ -1,7 +1,8 @@
from abc import ABC, abstractmethod
from copy import deepcopy
from deap import creator, base, tools, algorithms
from ray.tune import grid_search, variant_generator
from ray.tune import grid_search
from ray.tune.suggest import variant_generator
from slm_lab.experiment import analysis
from slm_lab.experiment.monitor import InfoSpace
from slm_lab.lib import logger, util
Expand All @@ -16,6 +17,15 @@
logger = logger.get_logger(__name__)


def register_ray_serializer():
'''Helper to register so objects can be serialized in Ray'''
from slm_lab.experiment.control import Experiment
ray.register_custom_serializer(Experiment, use_pickle=True)
ray.register_custom_serializer(InfoSpace, use_pickle=True)
ray.register_custom_serializer(pd.DataFrame, use_pickle=True)
ray.register_custom_serializer(pd.Series, use_pickle=True)


def build_config_space(experiment):
'''
Build ray config space from flattened spec.search
Expand Down Expand Up @@ -111,11 +121,6 @@ class RaySearch(ABC):
'''

def __init__(self, experiment):
from slm_lab.experiment.control import Experiment
ray.register_custom_serializer(Experiment, use_pickle=True)
ray.register_custom_serializer(InfoSpace, use_pickle=True)
ray.register_custom_serializer(pd.DataFrame, use_pickle=True)
ray.register_custom_serializer(pd.Series, use_pickle=True)
self.experiment = experiment
self.config_space = build_config_space(experiment)
logger.info(f'Running {util.get_class_name(self)}, with meta spec:\n{self.experiment.spec["meta"]}')
Expand All @@ -139,6 +144,7 @@ def run(self):
Remember to call ray init and cleanup before and after loop.
'''
ray.init()
register_ray_serializer()
# loop for max_trial: generate_config(); run_trial.remote(config)
ray.worker.cleanup()
raise NotImplementedError
Expand All @@ -158,6 +164,7 @@ def generate_config(self):
def run(self):
meta_spec = self.experiment.spec['meta']
ray.init(**meta_spec.get('resources', {}))
register_ray_serializer()
max_trial = meta_spec['max_trial']
trial_data_dict = {}
ray_id_to_config = {}
Expand Down Expand Up @@ -233,6 +240,7 @@ def init_deap(self):
def run(self):
meta_spec = self.experiment.spec['meta']
ray.init(**meta_spec.get('resources', {}))
register_ray_serializer()
max_generation = meta_spec['max_generation']
pop_size = meta_spec['max_trial'] or calc_population_size(self.experiment)
logger.info(f'EvolutionarySearch max_generation: {max_generation}, population size: {pop_size}')
Expand Down

0 comments on commit 6122e34

Please sign in to comment.