Skip to content

Commit dcc090d

Browse files
fyrestone刘宝
and
刘宝
authored
Update Mars on Ray doc (#3311)
* Update Mars doc * Compatible with sphinx 6 * Unpin sphinx<6 * Refine doc * Refine Co-authored-by: 刘宝 <[email protected]>
1 parent aa1b261 commit dcc090d

File tree

4 files changed

+95
-83
lines changed

4 files changed

+95
-83
lines changed

README.rst

+2-13
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,9 @@ Starting a new Mars on Ray runtime locally via:
244244

245245
.. code-block:: python
246246
247-
import ray
248-
ray.init()
249247
import mars
250-
mars.new_ray_session(worker_num=2)
251-
import mars.tensor as mt
252-
mt.random.RandomState(0).rand(1000_0000, 5).sum().execute()
253-
254-
Or connecting to a Mars on Ray runtime which is already initialized.
255-
256-
.. code-block:: python
257-
258-
import mars
259-
mars.new_ray_session('http://<web_ip>:<ui_port>')
260-
# perform computation
248+
mars.new_session(backend='ray')
249+
# Perform compute
261250
262251
Interact with Ray Dataset:
263252

docs/requirements-doc.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pytest-cov>=2.5.0
1010
pytest-timeout>=1.2.0
1111
cloudpickle>=1.0.0
1212
sqlalchemy>=1.2.0
13-
sphinx<6.0.0
13+
sphinx>=3.0.0
1414
pydata-sphinx-theme>=0.3.0
1515
sphinx-intl>=0.9.9
1616
ipython>=4.0

docs/source/conf.py

+43-37
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
# -- Project information -----------------------------------------------------
2121
from mars import __version__
2222

23-
project = 'mars'
24-
copyright = '1999-2020, The Alibaba Group Holding Ltd.'
25-
author = 'jisheng, qinxing'
23+
project = "mars"
24+
copyright = "1999-2020, The Alibaba Group Holding Ltd."
25+
author = "jisheng, qinxing"
2626

2727
# The short X.Y version
2828
version = __version__
@@ -40,29 +40,29 @@
4040
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4141
# ones.
4242
extensions = [
43-
'sphinx.ext.mathjax',
44-
'sphinx.ext.ifconfig',
45-
'sphinx.ext.intersphinx',
46-
'sphinx.ext.viewcode',
47-
'sphinx.ext.githubpages',
48-
'sphinx.ext.autosummary',
49-
'sphinx.ext.napoleon',
50-
'IPython.sphinxext.ipython_directive',
51-
'IPython.sphinxext.ipython_console_highlighting',
52-
'matplotlib.sphinxext.plot_directive',
43+
"sphinx.ext.mathjax",
44+
"sphinx.ext.ifconfig",
45+
"sphinx.ext.intersphinx",
46+
"sphinx.ext.viewcode",
47+
"sphinx.ext.githubpages",
48+
"sphinx.ext.autosummary",
49+
"sphinx.ext.napoleon",
50+
"IPython.sphinxext.ipython_directive",
51+
"IPython.sphinxext.ipython_console_highlighting",
52+
"matplotlib.sphinxext.plot_directive",
5353
]
5454

5555
# Add any paths that contain templates here, relative to this directory.
56-
templates_path = ['_templates']
56+
templates_path = ["_templates"]
5757

5858
# The suffix(es) of source filenames.
5959
# You can specify multiple suffix as a list of string:
6060
#
6161
# source_suffix = ['.rst', '.md']
62-
source_suffix = '.rst'
62+
source_suffix = ".rst"
6363

6464
# The master toctree document.
65-
master_doc = 'index'
65+
master_doc = "index"
6666

6767
# The language for content autogenerated by Sphinx. Refer to documentation
6868
# for a list of supported languages.
@@ -77,16 +77,16 @@
7777
exclude_patterns = []
7878

7979
# The name of the Pygments (syntax highlighting) style to use.
80-
pygments_style = 'sphinx'
80+
pygments_style = "sphinx"
8181

8282

8383
# -- Options for HTML output -------------------------------------------------
8484

8585
# The theme to use for HTML and HTML Help pages. See the documentation for
8686
# a list of builtin themes.
8787
#
88-
html_theme = 'pydata_sphinx_theme'
89-
html_logo = 'images/mars.svg'
88+
html_theme = "pydata_sphinx_theme"
89+
html_logo = "images/mars.svg"
9090

9191
# Theme options are theme-specific and customize the look and feel of a theme
9292
# further. For a list of options available for each theme, see the
@@ -96,14 +96,21 @@
9696
"github_url": "https://github.com/mars-project/mars",
9797
"twitter_url": "https://twitter.com/pymars_dev",
9898
"external_links": [
99-
{"name": "Release Notes", "url": "https://github.com/mars-project/mars/releases"},
100-
]
99+
{
100+
"name": "Release Notes",
101+
"url": "https://github.com/mars-project/mars/releases",
102+
},
103+
],
104+
"logo": {
105+
"image_light": "mars.svg",
106+
"image_dark": "mars.svg",
107+
},
101108
}
102109

103110
# Add any paths that contain custom static files (such as style sheets) here,
104111
# relative to this directory. They are copied after the builtin static files,
105112
# so a file named "default.css" will overwrite the builtin "default.css".
106-
html_static_path = ['images']
113+
html_static_path = ["images"]
107114

108115
# Custom sidebar templates, must be a dictionary that maps document names
109116
# to template names.
@@ -119,7 +126,7 @@
119126
# -- Options for HTMLHelp output ---------------------------------------------
120127

121128
# Output file base name for HTML help builder.
122-
htmlhelp_basename = 'marsdoc'
129+
htmlhelp_basename = "marsdoc"
123130

124131

125132
# -- Options for LaTeX output ------------------------------------------------
@@ -128,15 +135,12 @@
128135
# The paper size ('letterpaper' or 'a4paper').
129136
#
130137
# 'papersize': 'letterpaper',
131-
132138
# The font size ('10pt', '11pt' or '12pt').
133139
#
134140
# 'pointsize': '10pt',
135-
136141
# Additional stuff for the LaTeX preamble.
137142
#
138143
# 'preamble': '',
139-
140144
# Latex figure (float) alignment
141145
#
142146
# 'figure_align': 'htbp',
@@ -146,19 +150,15 @@
146150
# (source start file, target name, title,
147151
# author, documentclass [howto, manual, or own class]).
148152
latex_documents = [
149-
(master_doc, 'mars.tex', 'mars Documentation',
150-
'jisheng,qinxing', 'manual'),
153+
(master_doc, "mars.tex", "mars Documentation", "jisheng,qinxing", "manual"),
151154
]
152155

153156

154157
# -- Options for manual page output ------------------------------------------
155158

156159
# One entry per manual page. List of tuples
157160
# (source start file, name, description, authors, manual section).
158-
man_pages = [
159-
(master_doc, 'mars', 'mars Documentation',
160-
[author], 1)
161-
]
161+
man_pages = [(master_doc, "mars", "mars Documentation", [author], 1)]
162162

163163

164164
# -- Options for Texinfo output ----------------------------------------------
@@ -167,9 +167,15 @@
167167
# (source start file, target name, title, author,
168168
# dir menu entry, description, category)
169169
texinfo_documents = [
170-
(master_doc, 'mars', 'mars Documentation',
171-
author, 'mars', 'One line description of project.',
172-
'Miscellaneous'),
170+
(
171+
master_doc,
172+
"mars",
173+
"mars Documentation",
174+
author,
175+
"mars",
176+
"One line description of project.",
177+
"Miscellaneous",
178+
),
173179
]
174180

175181
autosummary_generate = True
@@ -191,8 +197,8 @@
191197

192198
# -- Extension configuration -------------------------------------------------
193199

194-
locale_dirs = ['locale/'] # path is example but recommended.
195-
gettext_compact = False # optional.
200+
locale_dirs = ["locale/"] # path is example but recommended.
201+
gettext_compact = False # optional.
196202
ipython_warning_is_error = False
197203

198204

docs/source/installation/ray.rst

+49-32
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ Install Ray locally:
1111

1212
.. code-block:: bash
1313
14-
pip install ray>=1.8.0
14+
pip install ray
1515
16-
Start a Ray cluster:
16+
(Optional) Start a Ray cluster or Mars starts a Ray cluster automatically:
1717

1818
.. code-block:: python
1919
2020
import ray
2121
ray.init()
2222
23-
Or connecting to a existing Ray cluster using `Ray client <https://docs.ray.io/en/latest/cluster/ray-client.html>`_:
23+
(Optional) Or connecting to a existing Ray cluster using `Ray client <https://docs.ray.io/en/latest/cluster/ray-client.html>`_:
2424

2525
.. code-block:: python
2626
2727
import ray
28-
ray.init(address="ray://<head_node_host>:10001")
28+
ray.init(address='ray://<head_node_host>:10001')
2929
3030
Creating a Mars on Ray runtime in the Ray cluster and do the computing:
3131

@@ -34,7 +34,8 @@ Creating a Mars on Ray runtime in the Ray cluster and do the computing:
3434
import mars
3535
import mars.tensor as mt
3636
import mars.dataframe as md
37-
session = mars.new_ray_session(worker_num=2, worker_mem=2 * 1024 ** 3)
37+
# This driver is the Mars supervisor.
38+
session = mars.new_session(backend='ray')
3839
mt.random.RandomState(0).rand(1000_0000, 5).sum().execute()
3940
df = md.DataFrame(
4041
mt.random.rand(1000_0000, 4, chunk_size=500_0000),
@@ -44,66 +45,82 @@ Creating a Mars on Ray runtime in the Ray cluster and do the computing:
4445
# Convert mars dataframe to ray dataset
4546
ds = md.to_ray_dataset(df)
4647
print(ds.schema(), ds.count())
47-
ds.filter(lambda row: row["a"] > 0.5).show(5)
48+
ds.filter(lambda row: row['a'] > 0.5).show(5)
4849
# Convert ray dataset to mars dataframe
4950
df2 = md.read_ray_dataset(ds)
5051
print(df2.head(5).execute())
5152
5253
53-
Create a Mars on Ray runtime independently in the Ray cluster:
54+
Stop the created Mars on Ray runtime:
5455

5556
.. code-block:: python
5657
57-
import mars
58-
import mars.tensor as mt
59-
cluster = mars.new_cluster_in_ray(worker_num=2, worker_mem=2 * 1024 ** 3)
58+
session.stop_server()
59+
60+
61+
Customizing cluster
62+
-------------------
6063

61-
Connect to the created Mars on Ray runtime and do the computing:
64+
There are two ways to initialize a Mars on Ray session:
65+
66+
- `mars.new_session(...) # Start Mars supervisor in current process.`
67+
Recommend for most use cases.
68+
- `mars.new_ray_session(...) # Start a Ray actor for Mars supervisor.`
69+
Recommend for large scale compute or compute through Ray client.
70+
71+
72+
Start a Ray actor for Mars supervisor:
6273

6374
.. code-block:: python
6475
6576
import mars
66-
import mars.tensor as mt
67-
session = mars.new_ray_session(address="http://ip:port", session_id="abcd", default=True)
68-
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
77+
# Start a Ray actor for Mars supervisor.
78+
session = mars.new_ray_session(backend='ray')
6979
70-
Stop the created Mars on Ray runtime:
80+
Connect to the created Mars on Ray runtime and do the computing, the supervisor virtual address is the name of Ray actor for Mars supervisor,
81+
e.g. `ray://ray-cluster-1672904753/0/0`.
7182

7283
.. code-block:: python
7384
74-
cluster.stop()
75-
85+
import mars
86+
import mars.tensor as mt
87+
# Be aware that `mars.new_ray_session()` connects to an existing Mars
88+
# cluster requires Ray runtime.
89+
# e.g. Current process is a initialized Ray driver, client or worker.
90+
session = mars.new_ray_session(
91+
address='ray://<supervisor virtual address>',
92+
session_id='abcd',
93+
backend='ray',
94+
default=True)
95+
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
7696
77-
Customizing cluster
78-
-------------------
79-
``new_ray_session``/``new_cluster_in_ray`` function provides several keyword arguments for users to define
97+
The ``new_ray_session`` function provides several keyword arguments for users to define
8098
the cluster.
8199

82100
Arguments for supervisors:
83101

84-
+----------------------+-----------------------------------------------------------+
85-
| Argument | Description |
86-
+======================+===========================================================+
87-
| supervisor_mem | Memory size for supervisor in the cluster, in bytes. |
88-
+----------------------+-----------------------------------------------------------+
102+
+--------------------+-----------------------------------------------------------------+
103+
| Argument | Description |
104+
+====================+=================================================================+
105+
| supervisor_cpu | Number of CPUs for supervisor, 1 by default. |
106+
+--------------------+-----------------------------------------------------------------+
107+
| supervisor_mem | Memory size for supervisor in bytes, 1G by default. |
108+
+--------------------+-----------------------------------------------------------------+
89109

90110
Arguments for workers:
91111

92112
+--------------------+-----------------------------------------------------------------+
93113
| Argument | Description |
94114
+====================+=================================================================+
95-
| worker_num | Number of workers in the cluster, 1 by default. |
96-
+--------------------+-----------------------------------------------------------------+
97115
| worker_cpu | Number of CPUs for every worker, 2 by default. |
98116
+--------------------+-----------------------------------------------------------------+
99-
| worker_mem | Memory size for workers in the cluster, in bytes, 2G by default.|
117+
| worker_mem | Memory size for workers in bytes, 2G by default. |
100118
+--------------------+-----------------------------------------------------------------+
101119

102-
For instance, if you want to create a Mars cluster with 100 workers,
103-
each worker has 4 cores and 16GB memory, you can use the code below:
120+
For instance, if you want to create a Mars cluster with a standalone supervisor,
121+
you can use the code below (In this example, one Ray node has 16 CPUs in total):
104122

105123
.. code-block:: python
106124
107125
import mars
108-
import mars.tensor as mt
109-
cluster = mars.new_cluster_in_ray(worker_num=100, worker_cpu=4, worker_mem=16 * 1024 ** 3)
126+
session = mars.new_ray_session(supervisor_cpu=16)

0 commit comments

Comments
 (0)