当前位置: 首页>>代码示例>>Python>>正文


Python ray.is_initialized方法代码示例

本文整理汇总了Python中ray.is_initialized方法的典型用法代码示例。如果您正苦于以下问题:Python ray.is_initialized方法的具体用法?Python ray.is_initialized怎么用?Python ray.is_initialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ray的用法示例。


在下文中一共展示了ray.is_initialized方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ray_local_session_fixture

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def ray_local_session_fixture():
    """Initializes Ray and shuts down Ray in local mode.

    Yields:
        None: Yield is for purposes of pytest module style.
            All statements before the yield are apart of module setup, and all
            statements after the yield are apart of module teardown.

    """
    if not ray.is_initialized():
        ray.init(local_mode=True,
                 ignore_reinit_error=True,
                 log_to_driver=False,
                 include_webui=False)
    yield
    if ray.is_initialized():
        ray.shutdown() 
开发者ID:rlworkgroup,项目名称:garage,代码行数:19,代码来源:ray_fixtures.py

示例2: ray_session_fixture

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def ray_session_fixture():
    """Initializes Ray and shuts down Ray.

    Yields:
        None: Yield is for purposes of pytest module style.
            All statements before the yield are apart of module setup, and all
            statements after the yield are apart of module teardown.

    """
    if not ray.is_initialized():
        ray.init(memory=52428800,
                 object_store_memory=78643200,
                 ignore_reinit_error=True,
                 log_to_driver=False,
                 include_webui=False)
    yield
    if ray.is_initialized():
        ray.shutdown() 
开发者ID:rlworkgroup,项目名称:garage,代码行数:20,代码来源:ray_fixtures.py

示例3: test_make_sampler_ray_sampler

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def test_make_sampler_ray_sampler(self, ray_session_fixture):
        del ray_session_fixture
        assert ray.is_initialized()
        with LocalTFRunner(snapshot_config) as runner:
            env = GarageEnv(env_name='CartPole-v1')

            policy = CategoricalMLPPolicy(name='policy',
                                          env_spec=env.spec,
                                          hidden_sizes=(8, 8))

            baseline = LinearFeatureBaseline(env_spec=env.spec)

            algo = VPG(env_spec=env.spec,
                       policy=policy,
                       baseline=baseline,
                       max_path_length=100,
                       discount=0.99,
                       optimizer_args=dict(learning_rate=0.01, ))

            runner.setup(algo, env, sampler_cls=RaySampler)
            assert isinstance(runner._sampler, RaySampler)
            runner.train(n_epochs=1, batch_size=10) 
开发者ID:rlworkgroup,项目名称:garage,代码行数:24,代码来源:test_local_tf_runner.py

示例4: test_init_with_env_updates

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def test_init_with_env_updates(ray_local_session_fixture):
    del ray_local_session_fixture
    assert ray.is_initialized()
    max_path_length = 16
    env = GarageEnv(PointEnv())
    policy = FixedPolicy(env.spec,
                         scripted_actions=[
                             env.action_space.sample()
                             for _ in range(max_path_length)
                         ])
    tasks = SetTaskSampler(lambda: GarageEnv(PointEnv()))
    n_workers = 8
    workers = WorkerFactory(seed=100,
                            max_path_length=max_path_length,
                            n_workers=n_workers)
    sampler = RaySampler.from_worker_factory(workers,
                                             policy,
                                             envs=tasks.sample(n_workers))
    rollouts = sampler.obtain_samples(0, 160, policy)
    assert sum(rollouts.lengths) >= 160 
开发者ID:rlworkgroup,项目名称:garage,代码行数:22,代码来源:test_ray_batched_sampler.py

示例5: test_bc_point_deterministic

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def test_bc_point_deterministic(ray_local_session_fixture):  # NOQA
    del ray_local_session_fixture
    assert ray.is_initialized()
    deterministic.set_seed(100)
    runner = LocalRunner(snapshot_config)
    goal = np.array([1., 1.])
    env = GarageEnv(PointEnv(goal=goal))
    expert = OptimalPolicy(env.spec, goal=goal)
    policy = DeterministicMLPPolicy(env.spec, hidden_sizes=[8, 8])
    batch_size = 600
    algo = BC(env.spec,
              policy,
              batch_size=batch_size,
              source=expert,
              max_path_length=200,
              policy_lr=1e-2,
              loss='mse')
    runner.setup(algo, env)
    run_bc(runner, algo, batch_size) 
开发者ID:rlworkgroup,项目名称:garage,代码行数:21,代码来源:test_bc.py

示例6: test_bc_point

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def test_bc_point(ray_local_session_fixture):  # NOQA
    del ray_local_session_fixture
    assert ray.is_initialized()
    deterministic.set_seed(100)
    runner = LocalRunner(snapshot_config)
    goal = np.array([1., 1.])
    env = GarageEnv(PointEnv(goal=goal))
    expert = OptimalPolicy(env.spec, goal=goal)
    policy = GaussianMLPPolicy(env.spec, [4])
    batch_size = 400
    algo = BC(env.spec,
              policy,
              batch_size=batch_size,
              source=expert,
              max_path_length=200,
              policy_lr=1e-2,
              loss='log_prob')
    runner.setup(algo, env)
    run_bc(runner, algo, batch_size) 
开发者ID:rlworkgroup,项目名称:garage,代码行数:21,代码来源:test_bc.py

示例7: __init__

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def __init__(self, worker_factory, agents, envs):
        # pylint: disable=super-init-not-called
        if not ray.is_initialized():
            ray.init(log_to_driver=False)
        self._sampler_worker = ray.remote(SamplerWorker)
        self._worker_factory = worker_factory
        self._agents = agents
        self._envs = self._worker_factory.prepare_worker_messages(envs)
        self._all_workers = defaultdict(None)
        self._workers_started = False
        self.start_worker() 
开发者ID:rlworkgroup,项目名称:garage,代码行数:13,代码来源:ray_sampler.py

示例8: test_ray_batch_sampler

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def test_ray_batch_sampler(self, ray_local_session_fixture):
        del ray_local_session_fixture
        assert ray.is_initialized()
        workers = WorkerFactory(seed=100,
                                max_path_length=self.algo.max_path_length)
        sampler1 = RaySampler(workers, self.policy, self.env)
        sampler1.start_worker()
        sampler1.shutdown_worker() 
开发者ID:rlworkgroup,项目名称:garage,代码行数:10,代码来源:test_ray_batched_sampler_tf.py

示例9: test_update_envs_env_update

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def test_update_envs_env_update(ray_local_session_fixture):
    del ray_local_session_fixture
    assert ray.is_initialized()
    max_path_length = 16
    env = GarageEnv(PointEnv())
    policy = FixedPolicy(env.spec,
                         scripted_actions=[
                             env.action_space.sample()
                             for _ in range(max_path_length)
                         ])
    tasks = SetTaskSampler(PointEnv)
    n_workers = 8
    workers = WorkerFactory(seed=100,
                            max_path_length=max_path_length,
                            n_workers=n_workers)
    sampler = RaySampler.from_worker_factory(workers, policy, env)
    rollouts = sampler.obtain_samples(0,
                                      160,
                                      np.asarray(policy.get_param_values()),
                                      env_update=tasks.sample(n_workers))
    mean_rewards = []
    goals = []
    for rollout in rollouts.split():
        mean_rewards.append(rollout.rewards.mean())
        goals.append(rollout.env_infos['task'][0]['goal'])
    assert np.var(mean_rewards) > 0
    assert np.var(goals) > 0
    with pytest.raises(ValueError):
        sampler.obtain_samples(0,
                               10,
                               np.asarray(policy.get_param_values()),
                               env_update=tasks.sample(n_workers + 1)) 
开发者ID:rlworkgroup,项目名称:garage,代码行数:34,代码来源:test_ray_batched_sampler.py

示例10: test_obtain_exact_trajectories

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def test_obtain_exact_trajectories(ray_local_session_fixture):
    del ray_local_session_fixture
    assert ray.is_initialized()
    max_path_length = 15
    n_workers = 8
    env = GarageEnv(PointEnv())
    per_worker_actions = [env.action_space.sample() for _ in range(n_workers)]
    policies = [
        FixedPolicy(env.spec, [action] * max_path_length)
        for action in per_worker_actions
    ]
    workers = WorkerFactory(seed=100,
                            max_path_length=max_path_length,
                            n_workers=n_workers)
    sampler = RaySampler.from_worker_factory(workers, policies, envs=env)
    n_traj_per_worker = 3
    rollouts = sampler.obtain_exact_trajectories(n_traj_per_worker, policies)
    # At least one action per trajectory.
    assert sum(rollouts.lengths) >= n_workers * n_traj_per_worker
    # All of the trajectories.
    assert len(rollouts.lengths) == n_workers * n_traj_per_worker
    worker = -1
    for count, rollout in enumerate(rollouts.split()):
        if count % n_traj_per_worker == 0:
            worker += 1
        assert (rollout.actions == per_worker_actions[worker]).all() 
开发者ID:rlworkgroup,项目名称:garage,代码行数:28,代码来源:test_ray_batched_sampler.py

示例11: init

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def init():
    """Initialize plasma event handlers for asyncio support."""
    assert ray.is_initialized(), "Please call ray.init before async_api.init"

    global handler
    if handler is None:
        worker = ray.worker.global_worker
        loop = asyncio.get_event_loop()
        handler = PlasmaEventHandler(loop, worker)
        worker.core_worker.set_plasma_added_callback(handler)
        logger.debug("AsyncPlasma Connection Created!") 
开发者ID:ray-project,项目名称:ray,代码行数:13,代码来源:async_api.py

示例12: __init__

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def __init__(self,
                 queue_trials=False,
                 reuse_actors=False,
                 ray_auto_init=False,
                 refresh_period=RESOURCE_REFRESH_PERIOD):
        super(RayTrialExecutor, self).__init__(queue_trials)
        # Check for if we are launching a trial without resources in kick off
        # autoscaler.
        self._trial_queued = False
        self._running = {}
        # Since trial resume after paused should not run
        # trial.train.remote(), thus no more new remote object id generated.
        # We use self._paused to store paused trials here.
        self._paused = {}

        self._trial_cleanup = _TrialCleanup()
        self._reuse_actors = reuse_actors
        self._cached_actor = None

        self._avail_resources = Resources(cpu=0, gpu=0)
        self._committed_resources = Resources(cpu=0, gpu=0)
        self._resources_initialized = False
        self._refresh_period = refresh_period
        self._last_resource_refresh = float("-inf")
        self._last_nontrivial_wait = time.time()
        if not ray.is_initialized() and ray_auto_init:
            logger.info("Initializing Ray automatically."
                        "For cluster usage or custom Ray initialization, "
                        "call `ray.init(...)` before `tune.run`.")
            ray.init()

        if ray.is_initialized():
            self._update_avail_resources() 
开发者ID:ray-project,项目名称:ray,代码行数:35,代码来源:ray_trial_executor.py

示例13: testTuneRestore

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def testTuneRestore(self):
        self.assertFalse(ray.is_initialized())
        tune.run(
            "__fake",
            name="TestAutoInit",
            stop={"training_iteration": 1},
            ray_auto_init=True)
        self.assertTrue(ray.is_initialized()) 
开发者ID:ray-project,项目名称:ray,代码行数:10,代码来源:test_tune_restore.py

示例14: shutdown_only_with_initialization_check

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def shutdown_only_with_initialization_check():
    yield None
    # The code after the yield will run as teardown code.
    ray.shutdown()
    assert not ray.is_initialized() 
开发者ID:ray-project,项目名称:ray,代码行数:7,代码来源:test_advanced_3.py

示例15: test_initialized_local_mode

# 需要导入模块: import ray [as 别名]
# 或者: from ray import is_initialized [as 别名]
def test_initialized_local_mode(shutdown_only_with_initialization_check):
    assert not ray.is_initialized()
    ray.init(num_cpus=0, local_mode=True)
    assert ray.is_initialized() 
开发者ID:ray-project,项目名称:ray,代码行数:6,代码来源:test_advanced_3.py


注:本文中的ray.is_initialized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。