Skip to content
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

remove Plugins from Singleton get_state, fix ray launcher default key pair name #1330

Merged
merged 4 commits into from Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion hydra/core/singleton.py
Expand Up @@ -18,12 +18,22 @@ def instance(cls: Any, *args: Any, **kwargs: Any) -> Any:

@staticmethod
def get_state() -> Any:
instances = deepcopy(Singleton._instances)
# Plugins can cause issues for pickling the singleton state
# Exclude them and re-initialize them on set_state()
from hydra.core.plugins import Plugins

instances.pop(Plugins, None)
return {
"instances": Singleton._instances,
"instances": instances,
"omegaconf_resolvers": deepcopy(BaseContainer._resolvers),
}

@staticmethod
def set_state(state: Any) -> None:
Singleton._instances = state["instances"]
# Reinitialize the the Plugin singleton (discover all plugins etc).
from hydra.core.plugins import Plugins

Plugins.instance()
BaseContainer._resolvers = deepcopy(state["omegaconf_resolvers"])
1 change: 1 addition & 0 deletions news/1330.maintenance
@@ -0,0 +1 @@
Remove `Plugins` from `Singleton.get_state()`
Expand Up @@ -59,7 +59,9 @@ class RayProviderConf:
region: str = "us-west-2"
availability_zone: str = "us-west-2a,us-west-2b"
cache_stopped_nodes: bool = False
key_pair: Dict[str, str] = field(default_factory=lambda: {"key_name": "hydra"})
key_pair: Dict[str, str] = field(
default_factory=lambda: {"key_name": "hydra-${env:USER,user}"}
)


@dataclass
Expand Down
17 changes: 1 addition & 16 deletions plugins/hydra_ray_launcher/tests/test_ray_aws_launcher.py
Expand Up @@ -108,22 +108,7 @@
chdir_plugin_root()


def build_ray_launcher_wheel(tmpdir: str) -> str:
"""
This only works on ray launcher plugin wheels for now, reasons being in our base AMI
we do not necessarily have the dependency for other plugins.
"""
command = "python -m pip --disable-pip-version-check list | grep hydra | grep -v hydra-core "
output = subprocess.getoutput(command).split("\n")
plugins_path = [x.split()[0].replace("-", "_") for x in output]
assert (
len(plugins_path) == 1 and "hydra_ray_launcher" == plugins_path[0]
), "Ray test AMI doesn't have dependency installed for other plugins."

return build_plugin_wheel(tmpdir)


def build_plugin_wheel(tmp_wheel_dir: str) -> str:
def build_ray_launcher_wheel(tmp_wheel_dir: str) -> str:
chdir_hydra_root()
plugin = "hydra_ray_launcher"
os.chdir(Path("plugins") / plugin)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_config_repository.py
Expand Up @@ -13,6 +13,7 @@
from hydra._internal.core_plugins.structured_config_source import StructuredConfigSource
from hydra.core.object_type import ObjectType
from hydra.core.plugins import Plugins
from hydra.core.singleton import Singleton
from hydra.plugins.config_source import ConfigSource
from hydra.test_utils.config_source_common_tests import ConfigSourceTestSuite
from hydra.test_utils.test_utils import chdir_hydra_root
Expand Down Expand Up @@ -182,3 +183,11 @@ def test_get_config_header(cfg_text: str, expected: Any, sep: str) -> None:
else:
with expected:
ConfigSource._get_header_dict(cfg_text)


def test_singleton_get_state(hydra_restore_singletons: Any) -> None:
s = Singleton.get_state()
assert Plugins not in s["instances"]
assert Plugins in Singleton._instances
Singleton.set_state(s)
assert Plugins in Singleton._instances