-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/mldataset
- Loading branch information
Showing
150 changed files
with
13,583 additions
and
2,310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Pre-commit Checks | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
checks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 2 | ||
|
||
- name: Set up conda ${{ matrix.python-version }} | ||
env: | ||
PYTHON: ${{ matrix.python-version }} | ||
shell: bash | ||
run: | | ||
source ./ci/install-conda.sh | ||
python -m pip install --upgrade pip setuptools wheel coverage; | ||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
source ./ci/reload-env.sh | ||
export DEFAULT_VENV=$VIRTUAL_ENV | ||
pip install numpy scipy cython | ||
pip install -e ".[dev,extra]" | ||
pip install virtualenv flake8 codespell sphinx sphinx-intl | ||
conda list -n test | ||
- name: Lint with flake8 | ||
shell: bash | ||
run: | | ||
source ./ci/reload-env.sh | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 mars --count --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 mars --config="default" --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Check spellings | ||
shell: bash | ||
run: | | ||
source ./ci/reload-env.sh | ||
codespell | ||
- name: Check copyright headers | ||
shell: bash | ||
run: | | ||
source ./ci/reload-env.sh | ||
python ci/copycheck.py | ||
- name: Check JS with ESLint | ||
shell: bash | ||
run: | | ||
source ./ci/reload-env.sh | ||
pushd mars/services/web/ui | ||
npm install | ||
npm run lint | ||
popd | ||
- name: Check documentation build | ||
shell: bash | ||
run: | | ||
source ./ci/reload-env.sh | ||
pushd docs | ||
pip install -r requirements-doc.txt | ||
make html | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
# Copyright 1999-2021 Alibaba Group Holding Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import sys | ||
from pathlib import PurePath | ||
|
||
_MATCH_FILES = [ | ||
'*.py', | ||
'*.pyx', | ||
] | ||
_IGNORES = [ | ||
'mars/learn/**/*.pyx', | ||
'mars/lib/**/*.py', | ||
] | ||
|
||
|
||
def main(): | ||
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
miss_files = [] | ||
for root, _dirs, files in os.walk(os.path.join(root_path, 'mars')): | ||
for fn in files: | ||
rel_path = os.path.relpath(os.path.join(root, fn), root_path) | ||
if any(PurePath(rel_path).match(patt) for patt in _IGNORES): | ||
continue | ||
if all(not PurePath(rel_path).match(patt) for patt in _MATCH_FILES): | ||
continue | ||
|
||
file_path = os.path.join(root, fn) | ||
with open(file_path, 'rb') as input_file: | ||
file_lines = [line for line in input_file.read().split(b'\n') | ||
if line.startswith(b'#')] | ||
comments = b'\n'.join(file_lines) | ||
if b'Copyright' not in comments: | ||
miss_files.append(rel_path) | ||
if miss_files: | ||
file_list = '\n '.join(miss_files) | ||
sys.stderr.write(f'Please add missing copyright header for files:\n' | ||
f' {file_list}\n') | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.. _batch_index: | ||
|
||
Create and Use Batch Methods | ||
============================ | ||
|
||
Oscar provides a set of APIs to write batch methods. You can simply add a | ||
``@extensible`` decorator to your actor method and create a batch version. All | ||
calls wrapped in a batch will be sent together, reducing possible RPC cost. | ||
|
||
Create a Batch Method | ||
--------------------- | ||
|
||
You can create a batch method with a ``@extensible`` decorator: | ||
|
||
.. code-block:: python | ||
import mars.oscar as mo | ||
class ExampleActor(mo.Actor): | ||
@mo.extensible | ||
async def batch_method(self, a, b=None): | ||
pass | ||
Sometimes we need to process received batch requests. For instance, we need to | ||
group requests by certain keys and resent them to different handlers in | ||
batches. Oscar supports creating a batch version of the method: | ||
|
||
.. code-block:: python | ||
class ExampleActor(mo.Actor): | ||
@mo.extensible | ||
async def batch_method(self, a, b=None): | ||
raise NotImplementedError # this will redirect all requests to the batch version | ||
@batch_method.batch | ||
async def batch_method(self, args_list, kwargs_list): | ||
results = [] | ||
for args, kwargs in zip(args_list, kwargs_list): | ||
a, b = self.batch_method.bind(*args, **kwargs) | ||
# process the request | ||
results.append(result) | ||
return results # return a list of results | ||
In the code above, we simply raises a ``NotImplementedError`` to let the batch | ||
version handle all requests. The batch version have two arguments accepting | ||
``args`` and ``kwargs`` of all batched calls as lists. To make argument | ||
extraction easier, a utility function ``bind`` is added as an attribute of the | ||
method which extracts ``args`` and ``kwargs`` into real arguments. | ||
|
||
Call Batch Methods | ||
------------------ | ||
|
||
Calling batch methods is easy. You can use ``<method_name>.delay`` to make a | ||
batched call and use ``<method_name>.batch`` to send them: | ||
|
||
.. code-block:: python | ||
ref = await mo.actor_ref(uid='ExampleActor', address='127.0.0.1:13425') | ||
results = await ref.batch_method.batch( | ||
ref.batch_method.delay(10, b=20), | ||
ref.batch_method.delay(20), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ for entire distributed layer. | |
:maxdepth: 2 | ||
|
||
usage | ||
batch | ||
internals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.