-
Notifications
You must be signed in to change notification settings - Fork 670
Simulate cluster for testing remote context #1982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
04ec6d4
FEAT-#1981: Add fixture that enables local "cluster" when requested
vnlitvinov 3356daa
FEAT-#1981: Implement automatic local cluster spawning
vnlitvinov 9da749e
FEAT-#1981: Make --simulate-cloud work
vnlitvinov 061c421
FEAT-#1981: Format by black
vnlitvinov c27aa52
FEAT-#1981: Make LocalCluster actually switch engine
vnlitvinov 248e402
FEAT-#1981: Add rpyc tracing support for local cluster simulation
vnlitvinov 751e1e2
FEAT-#1981: Init remote Python engine for Cloudpython
vnlitvinov 16d4f46
FEAT-#1981: Address review comments
vnlitvinov b169c78
FEAT-#1981: Warn when LocalCluster() receives ignored arguments
vnlitvinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,49 @@ | ||
| # Licensed to Modin Development Team under one or more contributor license agreements. | ||
| # See the NOTICE file distributed with this work for additional information regarding | ||
| # copyright ownership. The Modin Development Team licenses this file to you 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 pytest | ||
| import os | ||
|
|
||
|
|
||
| def pytest_addoption(parser): | ||
| parser.addoption( | ||
| "--simulate-cloud", | ||
| action="store", | ||
| default="off", | ||
| help="simulate cloud for testing: off|normal|experimental", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session", autouse=True) | ||
| def simulate_cloud(request): | ||
| mode = request.config.getoption("--simulate-cloud").lower() | ||
| if mode == "off": | ||
| yield | ||
| return | ||
| if mode not in ("normal", "experimental"): | ||
| raise ValueError(f"Unsupported --simulate-cloud mode: {mode}") | ||
| os.environ["MODIN_EXPERIMENTAL"] = "True" | ||
|
|
||
| from modin.experimental.cloud import create_cluster, get_connection | ||
|
|
||
| with create_cluster("local", __spawner__="local"): | ||
|
|
||
| def set_env(mode): | ||
| import os | ||
|
|
||
| os.environ["MODIN_EXPERIMENTAL"] = ( | ||
| "True" if mode == "experimental" else "False" | ||
| ) | ||
|
|
||
| get_connection().teleport(set_env)(mode) | ||
| yield |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,114 @@ | ||
| # Licensed to Modin Development Team under one or more contributor license agreements. | ||
| # See the NOTICE file distributed with this work for additional information regarding | ||
| # copyright ownership. The Modin Development Team licenses this file to you 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 subprocess | ||
| import sys | ||
| import warnings | ||
|
|
||
| from .base import ConnectionDetails | ||
| from .cluster import BaseCluster | ||
| from .connection import Connection | ||
| from .rpyc_proxy import WrappingConnection, WrappingService, _TRACE_RPYC | ||
| from .tracing.tracing_connection import TracingWrappingConnection | ||
|
|
||
|
|
||
| class LocalWrappingConnection( | ||
| TracingWrappingConnection if _TRACE_RPYC else WrappingConnection | ||
| ): | ||
| def _init_deliver(self): | ||
| def ensure_modin(modin_init): | ||
| import sys | ||
| import os | ||
|
|
||
| modin_dir = os.path.abspath(os.path.join(os.path.dirname(modin_init), "..")) | ||
| # make sure "import modin" will be taken from current modin, not something potentially installed in the system | ||
| if modin_dir not in sys.path: | ||
| sys.path.insert(0, modin_dir) | ||
vnlitvinov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import modin | ||
|
|
||
| self.teleport(ensure_modin)(modin.__file__) | ||
| super()._init_deliver() | ||
|
|
||
|
|
||
| class LocalWrappingService(WrappingService): | ||
| _protocol = LocalWrappingConnection | ||
|
|
||
|
|
||
| class LocalConnection(Connection): | ||
| def _build_sshcmd(self, details: ConnectionDetails, forward_port: int = None): | ||
| return [] | ||
|
|
||
| @staticmethod | ||
| def _run(sshcmd: list, cmd: list, capture_out: bool = True): | ||
| assert not sshcmd, "LocalConnection does not support running things via ssh" | ||
| redirect = subprocess.PIPE if capture_out else subprocess.DEVNULL | ||
| return subprocess.Popen( | ||
| cmd, | ||
| stdin=subprocess.DEVNULL, | ||
| stdout=redirect, | ||
| stderr=redirect, | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def _get_service(): | ||
| return LocalWrappingService | ||
|
|
||
|
|
||
| _UNUSED = object() | ||
|
|
||
|
|
||
| class LocalCluster(BaseCluster): | ||
| target_engine = "Cloudpython" | ||
| target_partition = "Pandas" | ||
|
|
||
| Connector = LocalConnection | ||
|
|
||
| def __init__( | ||
| self, | ||
| provider, | ||
| project_name=_UNUSED, | ||
| cluster_name=_UNUSED, | ||
| worker_count=_UNUSED, | ||
| head_node_type=_UNUSED, | ||
| worker_node_type=_UNUSED, | ||
| ): | ||
| assert ( | ||
| provider == "local" | ||
| ), "Local cluster can only be spawned with 'local' provider" | ||
| if any( | ||
| arg is not _UNUSED | ||
| for arg in ( | ||
| project_name, | ||
| cluster_name, | ||
| worker_count, | ||
| head_node_type, | ||
| worker_node_type, | ||
| ) | ||
| ): | ||
| warnings.warn( | ||
| "All parameters except 'provider' are ignored for LocalCluster, do not pass them" | ||
| ) | ||
| super().__init__(provider, "test-project", "test-cluster", 1, "head", "worker") | ||
|
|
||
| def _spawn(self, wait=False): | ||
| pass | ||
|
|
||
| def _destroy(self, wait=False): | ||
| pass | ||
|
|
||
| def _get_connection_details(self) -> ConnectionDetails: | ||
| return ConnectionDetails() | ||
|
|
||
| def _get_main_python(self) -> str: | ||
| return sys.executable | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.