Skip to content

Latest commit

 

History

History
363 lines (281 loc) · 12 KB

index.rst

File metadata and controls

363 lines (281 loc) · 12 KB

What is Ray?

Getting Started with Ray

Check out :ref:`gentle-intro` to learn more about Ray and its ecosystem of libraries that enable things like distributed hyperparameter tuning, reinforcement learning, and distributed training.

Ray provides Python, Java, and EXPERIMENTAL C++ API. And Ray uses Tasks (functions) and Actors (Classes) to allow you to parallelize your code.

.. tabs::
  .. group-tab:: Python

    .. code-block:: python

        # First, run `pip install ray`.

        import ray
        ray.init()

        @ray.remote
        def f(x):
            return x * x

        futures = [f.remote(i) for i in range(4)]
        print(ray.get(futures)) # [0, 1, 4, 9]

        @ray.remote
        class Counter(object):
            def __init__(self):
                self.n = 0

            def increment(self):
                self.n += 1

            def read(self):
                return self.n

        counters = [Counter.remote() for i in range(4)]
        [c.increment.remote() for c in counters]
        futures = [c.read.remote() for c in counters]
        print(ray.get(futures)) # [1, 1, 1, 1]

  .. group-tab:: Java

    First, add the `ray-api <https://mvnrepository.com/artifact/io.ray/ray-api>`__ and `ray-runtime <https://mvnrepository.com/artifact/io.ray/ray-runtime>`__ dependencies in your project.

    .. code-block:: java

        import io.ray.api.ActorHandle;
        import io.ray.api.ObjectRef;
        import io.ray.api.Ray;
        import java.util.ArrayList;
        import java.util.List;
        import java.util.stream.Collectors;

        public class RayDemo {

          public static int square(int x) {
            return x * x;
          }

          public static class Counter {

            private int value = 0;

            public void increment() {
              this.value += 1;
            }

            public int read() {
              return this.value;
            }
          }

          public static void main(String[] args) {
            // Intialize Ray runtime.
            Ray.init();
            {
              List<ObjectRef<Integer>> objectRefList = new ArrayList<>();
              // Invoke the `square` method 4 times remotely as Ray tasks.
              // The tasks will run in parallel in the background.
              for (int i = 0; i < 4; i++) {
                objectRefList.add(Ray.task(RayDemo::square, i).remote());
              }
              // Get the actual results of the tasks with `get`.
              System.out.println(Ray.get(objectRefList));  // [0, 1, 4, 9]
            }

            {
              List<ActorHandle<Counter>> counters = new ArrayList<>();
              // Create 4 actors from the `Counter` class.
              // They will run in remote worker processes.
              for (int i = 0; i < 4; i++) {
                counters.add(Ray.actor(Counter::new).remote());
              }

              // Invoke the `increment` method on each actor.
              // This will send an actor task to each remote actor.
              for (ActorHandle<Counter> counter : counters) {
                counter.task(Counter::increment).remote();
              }
              // Invoke the `read` method on each actor, and print the results.
              List<ObjectRef<Integer>> objectRefList = counters.stream()
                  .map(counter -> counter.task(Counter::read).remote())
                  .collect(Collectors.toList());
              System.out.println(Ray.get(objectRefList));  // [1, 1, 1, 1]
            }
          }
        }

  .. group-tab:: C++ (EXPERIMENTAL)

    | The C++ Ray API is currently experimental with limited support. You can track its development `here <https://github.com/ray-project/ray/milestone/17>`__ and report issues on GitHub.
    | Run the following commands to get started:
    | - Build ray from source with *bazel* as shown `here <https://docs.ray.io/en/master/development.html#building-ray-full>`__.
    | - Modify and build `cpp/example/example.cc`.

    .. code-block:: shell

      bazel build //cpp/example:example

    | Option 1: run the example directly with a dynamic library path. It will start a Ray cluster automatically.

    .. code-block:: shell

      ray stop
      ./bazel-bin/cpp/example/example --dynamic-library-path=bazel-bin/cpp/example/example.so

    | Option 2: connect to an existing Ray cluster with a known redis address (e.g. `127.0.0.1:6379`).

    .. code-block:: shell

      ray stop
      ray start --head --port 6379 --redis-password 5241590000000000 --node-manager-port 62665
      ./bazel-bin/cpp/example/example --dynamic-library-path=bazel-bin/cpp/example/example.so --redis-address=127.0.0.1:6379

    .. literalinclude:: ../../cpp/example/example.cc
       :language: cpp

You can also get started by visiting our Tutorials. For the latest wheels (nightlies), see the installation page.

Getting Involved

If you're interested in contributing to Ray, visit our page on :ref:`Getting Involved <getting-involved>` to read about the contribution process and see what you can work on!

More Information

Here are some talks, papers, and press coverage involving Ray and its libraries. Please raise an issue if any of the below links are broken, or if you'd like to add your own talk!

Blog and Press

Talks (Videos)

Slides

Papers

Older papers:

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Overview of Ray

   ray-overview/index.rst
   ray-libraries.rst
   installation.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Ray Core

   walkthrough.rst
   using-ray.rst
   configure.rst
   ray-dashboard.rst
   Tutorial and Examples <auto_examples/overview.rst>
   package-ref.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Ray Clusters/Autoscaler

   cluster/index.rst
   cluster/quickstart.rst
   cluster/reference.rst
   cluster/cloud.rst
   cluster/deploy.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Ray Serve

   serve/index.rst
   serve/tutorial.rst
   serve/core-apis.rst
   serve/deployment.rst
   serve/ml-models.rst
   serve/advanced-traffic.rst
   serve/advanced.rst
   serve/performance.rst
   serve/architecture.rst
   serve/tutorials/index.rst
   serve/faq.rst
   serve/package-ref.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Ray Tune

   tune/index.rst
   tune/key-concepts.rst
   tune/user-guide.rst
   tune/tutorials/overview.rst
   tune/examples/index.rst
   tune/api_docs/overview.rst
   tune/contrib.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: RLlib

   rllib.rst
   rllib-toc.rst
   rllib-training.rst
   rllib-env.rst
   rllib-models.rst
   rllib-algorithms.rst
   rllib-sample-collection.rst
   rllib-offline.rst
   rllib-concepts.rst
   rllib-examples.rst
   rllib-package-ref.rst
   rllib-dev.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Ray SGD

   raysgd/raysgd.rst
   raysgd/raysgd_pytorch.rst
   raysgd/raysgd_tensorflow.rst
   raysgd/raysgd_dataset.rst
   raysgd/raysgd_ptl.rst
   raysgd/raysgd_tune.rst
   raysgd/raysgd_ref.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Data Processing

   modin/index.rst
   dask-on-ray.rst
   mars-on-ray.rst
   raydp.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: More Libraries

   multiprocessing.rst
   joblib.rst
   iter.rst
   xgboost-ray.rst
   ray-client.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Ray Observability

   ray-metrics.rst
   ray-debugging.rst
   ray-logging.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Contributing

   getting-involved.rst

.. toctree::
   :hidden:
   :maxdepth: -1
   :caption: Development and Ray Internals

   development.rst
   whitepaper.rst
   debugging.rst
   profiling.rst
   fault-tolerance.rst