Skip to content

Commit

Permalink
support Python3.11 (facebookresearch#2418)
Browse files Browse the repository at this point in the history
Co-authored-by: Jasha <[email protected]>
  • Loading branch information
skshetry and Jasha10 authored Dec 5, 2022
1 parent b94f039 commit afde761
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 161 deletions.
20 changes: 10 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ commands:
- run:
name: Preparing environment - Hydra
command: |
conda create -n hydra python=<< parameters.py_version >> -yq
conda create -n hydra python=<< parameters.py_version >> -yqc conda-forge
conda run -n hydra pip install nox --progress-bar off
- save_cache:
key: -<< pipeline.parameters.cache_key_version >>-macos-sys-{{ .Branch }}-<< parameters.py_version >>
Expand Down Expand Up @@ -84,7 +84,7 @@ commands:
name: Preparing environment - Hydra
command: |
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda create -n hydra python=<< parameters.py_version >> -yq
~/miniconda3/bin/conda create -n hydra python=<< parameters.py_version >> -yqc conda-forge
win:
Expand All @@ -105,7 +105,7 @@ commands:
- run:
name: Preparing environment - Hydra
command: |
conda create -n hydra python=<< parameters.py_version >> -qy
conda create -n hydra python=<< parameters.py_version >> -yqc conda-forge
conda activate hydra
pip install nox dataclasses --progress-bar off
- save_cache:
Expand Down Expand Up @@ -288,19 +288,19 @@ workflows:
- test_macos:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
- test_linux:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
- test_win:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
- test_linux_omc_dev:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]


plugin_tests:
Expand All @@ -309,17 +309,17 @@ workflows:
- test_plugin_linux:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
test_plugin: [<< pipeline.parameters.test_plugins >>]
- test_plugin_macos:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
test_plugin: [<< pipeline.parameters.test_plugins >>]
- test_plugin_win:
matrix:
parameters:
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
py_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
test_plugin: [<< pipeline.parameters.test_plugins >>]


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from dataclasses import dataclass
from dataclasses import dataclass, field

import hydra
from hydra.core.config_store import ConfigStore
Expand All @@ -20,8 +20,8 @@ class UserInterface:

@dataclass
class MyConfig:
db: MySQLConfig = MySQLConfig()
ui: UserInterface = UserInterface()
db: MySQLConfig = field(default_factory=MySQLConfig)
ui: UserInterface = field(default_factory=UserInterface)


cs = ConfigStore.instance()
Expand Down
18 changes: 9 additions & 9 deletions hydra/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class OverrideDirname:
item_sep: str = ","
exclude_keys: List[str] = field(default_factory=list)

override_dirname: OverrideDirname = OverrideDirname()
override_dirname: OverrideDirname = field(default_factory=OverrideDirname)

config: JobConfig = JobConfig()
config: JobConfig = field(default_factory=JobConfig)


@dataclass
Expand Down Expand Up @@ -129,9 +129,9 @@ class HydraConf:
searchpath: List[str] = field(default_factory=list)

# Normal run output configuration
run: RunDir = RunDir()
run: RunDir = field(default_factory=RunDir)
# Multi-run output configuration
sweep: SweepDir = SweepDir()
sweep: SweepDir = field(default_factory=SweepDir)
# Logging configuration for Hydra
hydra_logging: Dict[str, Any] = MISSING
# Logging configuration for the job
Expand All @@ -145,9 +145,9 @@ class HydraConf:
callbacks: Dict[str, Any] = field(default_factory=dict)

# Program Help template
help: HelpConf = HelpConf()
help: HelpConf = field(default_factory=HelpConf)
# Hydra's Help template
hydra_help: HydraHelpConf = HydraHelpConf()
hydra_help: HydraHelpConf = field(default_factory=HydraHelpConf)

# Output directory for produced configuration files and overrides.
# E.g., hydra.yaml, overrides.yaml will go here. Useful for debugging
Expand All @@ -156,12 +156,12 @@ class HydraConf:
output_subdir: Optional[str] = ".hydra"

# Those lists will contain runtime overrides
overrides: OverridesConf = OverridesConf()
overrides: OverridesConf = field(default_factory=OverridesConf)

job: JobConf = JobConf()
job: JobConf = field(default_factory=JobConf)

# populated at runtime
runtime: RuntimeConf = RuntimeConf()
runtime: RuntimeConf = field(default_factory=RuntimeConf)

# Can be a boolean, string or a list of strings
# If a boolean, setting to true will set the log level for the root logger to debug
Expand Down
1 change: 1 addition & 0 deletions news/2443.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support python3.11
6 changes: 2 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

BASE = os.path.abspath(os.path.dirname(__file__))

DEFAULT_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"]
DEFAULT_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
DEFAULT_OS_NAMES = ["Linux", "MacOS", "Windows"]

PYTHON_VERSIONS = os.environ.get(
Expand Down Expand Up @@ -608,9 +608,7 @@ def test_jupyter_notebooks(session: Session) -> None:

session.install("jupyter", "nbval", "pyzmq", "pytest")
if platform.system() == "Windows":
# Newer versions of pywin32 are causing CI issues on Windows.
# see https://github.com/mhammond/pywin32/issues/1709
session.install("pywin32==225")
session.install("pywin32")

install_hydra(session, ["pip", "install", "-e"])
args = pytest_args(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class AxConfig:

# max_trials is application-specific. Tune it for your use case
max_trials: int = 10
early_stop: EarlyStopConfig = EarlyStopConfig()
experiment: ExperimentConfig = ExperimentConfig()
client: ClientConfig = ClientConfig()
early_stop: EarlyStopConfig = field(default_factory=EarlyStopConfig)
experiment: ExperimentConfig = field(default_factory=ExperimentConfig)
client: ClientConfig = field(default_factory=ClientConfig)
params: Dict[str, Any] = field(default_factory=dict)
# is_noisy = True indicates measurements have unknown uncertainty
# is_noisy = False indicates measurements have an uncertainty of zero
Expand All @@ -60,7 +60,7 @@ class AxSweeperConf:
_target_: str = "hydra_plugins.hydra_ax_sweeper.ax_sweeper.AxSweeper"
# Maximum number of trials to run in parallel
max_batch_size: Optional[int] = None
ax_config: AxConfig = AxConfig()
ax_config: AxConfig = field(default_factory=AxConfig)


ConfigStore.instance().store(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class NevergradSweeperConf:
)

# configuration of the optimizer
optim: OptimConf = OptimConf()
optim: OptimConf = field(default_factory=OptimConf)

# default parametrization of the search space
# can be specified:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RayConf:
@dataclass
class RayLauncherConf:
_target_: str = "hydra_plugins.hydra_ray_launcher.ray_launcher.RayLauncher"
ray: RayConf = RayConf()
ray: RayConf = field(default_factory=RayConf)


def _pkg_version(mdl_name: str) -> Optional[str]:
Expand Down Expand Up @@ -251,9 +251,9 @@ class RayClusterConf:
# If a node is idle for this many minutes, it will be removed.
idle_timeout_minutes: int = 5

docker: RayDockerConf = RayDockerConf()
docker: RayDockerConf = field(default_factory=RayDockerConf)

provider: RayProviderConf = RayProviderConf()
provider: RayProviderConf = field(default_factory=RayProviderConf)

# For additional options, check:
# https://github.com/ray-project/ray/blob/master/python/ray/autoscaler/aws/example-full.yaml
Expand Down Expand Up @@ -330,17 +330,17 @@ class RayClusterConf:

@dataclass
class RayAWSConf(RayConf):
cluster: RayClusterConf = RayClusterConf()
cluster: RayClusterConf = field(default_factory=RayClusterConf)
run_env: RayRunEnv = RayRunEnv.auto


@dataclass
class RayAWSLauncherConf:
_target_: str = "hydra_plugins.hydra_ray_launcher.ray_aws_launcher.RayAWSLauncher"

env_setup: EnvSetupConf = EnvSetupConf()
env_setup: EnvSetupConf = field(default_factory=EnvSetupConf)

ray: RayAWSConf = RayAWSConf()
ray: RayAWSConf = field(default_factory=RayAWSConf)

# Stop Ray AWS cluster after jobs are finished.
# (if False, cluster will remain provisioned and can be started with "ray up cluster.yaml").
Expand All @@ -350,21 +350,25 @@ class RayAWSLauncherConf:
# This can be used for syncing up source code to remote cluster for execution.
# You need to sync up if your code contains multiple modules.
# source is local dir, target is remote dir
sync_up: RsyncConf = RsyncConf()
sync_up: RsyncConf = field(default_factory=RsyncConf)

# sync_down is executed after jobs finishes on the cluster.
# This can be used to download jobs output to local machine avoid the hassle to log on remote machine.
# source is remote dir, target is local dir
sync_down: RsyncConf = RsyncConf()
sync_down: RsyncConf = field(default_factory=RsyncConf)

# Ray sdk.configure_logging parameters: log_style, color_mode, verbosity
logging: RayLoggingConf = RayLoggingConf()
logging: RayLoggingConf = field(default_factory=RayLoggingConf)

# Ray sdk.create_or_update_cluster parameters: no_restart, restart_only, no_config_cache
create_update_cluster: RayCreateOrUpdateClusterConf = RayCreateOrUpdateClusterConf()
create_update_cluster: RayCreateOrUpdateClusterConf = field(
default_factory=RayCreateOrUpdateClusterConf
)

# Ray sdk.teardown parameters: workers_only, keep_min_workers
teardown_cluster: RayTeardownClusterConf = RayTeardownClusterConf()
teardown_cluster: RayTeardownClusterConf = field(
default_factory=RayTeardownClusterConf
)


config_store = ConfigStore.instance()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Optional

from hydra.core.config_store import ConfigStore
Expand Down Expand Up @@ -46,11 +46,11 @@ class EnqueueConf:
class RQLauncherConf:
_target_: str = "hydra_plugins.hydra_rq_launcher.rq_launcher.RQLauncher"
# enqueue configuration
enqueue: EnqueueConf = EnqueueConf()
enqueue: EnqueueConf = field(default_factory=EnqueueConf)
# queue name
queue: str = "default"
# redis configuration
redis: RedisConf = RedisConf()
redis: RedisConf = field(default_factory=RedisConf)
# stop after enqueueing by raising custom exception
stop_after_enqueue: bool = False
# wait time in seconds when polling results
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
Expand Down
8 changes: 4 additions & 4 deletions tests/instantiate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import collections
import collections.abc
from dataclasses import dataclass
from dataclasses import dataclass, field
from functools import partial
from typing import Any, Dict, List, NoReturn, Optional, Tuple

Expand Down Expand Up @@ -189,7 +189,7 @@ class Adam:

@dataclass
class NestingClass:
a: ASubclass = ASubclass(10)
a: ASubclass = field(default_factory=lambda: ASubclass(10))


nesting = NestingClass()
Expand Down Expand Up @@ -416,8 +416,8 @@ class SimpleClassDefaultPrimitiveConf:
@dataclass
class NestedConf:
_target_: str = "tests.instantiate.SimpleClass"
a: Any = User(name="a", age=1)
b: Any = User(name="b", age=2)
a: Any = field(default_factory=lambda: User(name="a", age=1))
b: Any = field(default_factory=lambda: User(name="b", age=2))


def recisinstance(got: Any, expected: Any) -> bool:
Expand Down
50 changes: 23 additions & 27 deletions tests/test_basic_sweeper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import re
import sys
from textwrap import dedent
from typing import Any, List, Optional
Expand All @@ -7,7 +8,7 @@

from hydra._internal.core_plugins.basic_sweeper import BasicSweeper
from hydra.core.override_parser.overrides_parser import OverridesParser
from hydra.test_utils.test_utils import assert_regex_match, run_process
from hydra.test_utils.test_utils import assert_multiline_regex_search, run_process


@mark.parametrize(
Expand Down Expand Up @@ -75,36 +76,31 @@ def test_partial_failure(
]
out, err = run_process(cmd=cmd, print_error=False, raise_exception=False)

expected_out = dedent(
"""\
[HYDRA] Launching 2 jobs locally
[HYDRA] \t#0 : +divisor=1
val=1.0
[HYDRA] \t#1 : +divisor=0"""
expected_out_regex = re.escape(
dedent(
"""
[HYDRA] Launching 2 jobs locally
[HYDRA] \t#0 : +divisor=1
val=1.0
[HYDRA] \t#1 : +divisor=0
"""
).strip()
)

assert_regex_match(
from_line=expected_out,
to_line=out,
from_name="Expected output",
to_name="Actual output",
)
assert_multiline_regex_search(expected_out_regex, out)

expected_err = dedent(
"""
Error executing job with overrides: ['+divisor=0']
Traceback (most recent call last):
File ".*my_app.py", line 9, in my_app
val = 1 / cfg.divisor
expected_err_regex = dedent(
r"""
Error executing job with overrides: \['\+divisor=0'\](
)?
Traceback \(most recent call last\):
File ".*my_app\.py", line 9, in my_app
val = 1 / cfg\.divisor(
~~\^~~~~~~~~~~~~)?
ZeroDivisionError: division by zero
Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.
Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace\.
"""
)
).strip()

assert_regex_match(
from_line=expected_err,
to_line=err,
from_name="Expected error",
to_name="Actual error",
)
assert_multiline_regex_search(expected_err_regex, err)
Loading

0 comments on commit afde761

Please sign in to comment.