Skip to content

Commit

Permalink
Support Python 3.7+ clients.
Browse files Browse the repository at this point in the history
All changes:
1. Copybara in `from __future__ import annotations` to all Python files to deal with list[] and dict[]. (Supports 3.7+)
2. Copybara out `def f(x, /) -> f(x)` (Supports 3.7+)
3. Copybara `from_collections.abc import` -> `typing import` and change code `from collections import abc` -> `from collections.abc import Collection` (Supports 3.7+)
4. Copybara out use of `typing.Literal`. (Only helps 3.7)
5. Copybara `functools.cache`/`functools.lru_cache` (Helps both 3.7 and 3.8)
6. Use delayed import on local Vizier Server when endpoint is not given to client, to avoid importing server-logic. (Only helps 3.7)

PiperOrigin-RevId: 497017707
  • Loading branch information
xingyousong authored and copybara-github committed Dec 21, 2022
1 parent 2a288a1 commit 5d4a06b
Show file tree
Hide file tree
Showing 183 changed files with 448 additions and 36 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/client_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: pytest_clients

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
test-ubuntu:
name: "pytest on ${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
strategy:
matrix:
python-version: [
3.7, # Cloud Vertex
3.8, # Public Colab
3.9, # Preferred Version
]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install essential dependencies
run: |
sudo apt-get install -y libprotobuf-dev
python -m pip install --upgrade pip setuptools
pip install wheel
pip install grpcio-tools==1.48.2
pip install pytest pytest-xdist
- name: Install Vizier
run: |
pip wheel -e .
pip install -e .
- name: Print installed dependencies
run: |
pip freeze
- name: Check OSS Client import.
run: |
python vizier/service/clients.py
2 changes: 2 additions & 0 deletions demos/run_vizier_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Example of a Vizier Client, which can be run on multiple machines.
For distributed cases, this is meant to be used after the Vizier Server (see
Expand Down
2 changes: 2 additions & 0 deletions demos/run_vizier_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Sets up the Vizier Service gRPC server.
This should be done on a server machine:
Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Sphinx configuration."""
import os
import sys
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Setup for pip package."""
import os
import sys
Expand Down
4 changes: 3 additions & 1 deletion vizier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Init file."""
import os
import sys
Expand All @@ -21,4 +23,4 @@

sys.path.append(PROTO_ROOT)

__version__ = "0.0.15"
__version__ = "0.0.16"
2 changes: 2 additions & 0 deletions vizier/_src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations


2 changes: 2 additions & 0 deletions vizier/_src/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations


2 changes: 2 additions & 0 deletions vizier/_src/algorithms/classification/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Binary classifiers for Bayesian Optimization."""

from typing import Optional
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/classification/classifiers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for Sklearn classifier."""

import numpy as np
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations


2 changes: 2 additions & 0 deletions vizier/_src/algorithms/core/abstractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Abstractions."""

import abc
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations


2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/bocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Bayesian Optimization of Combinatorial Structures (BOCS) from https://arxiv.org/abs/1806.08838.
Code is a cleaned-up exact version from /BOCSpy/ in
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/bocs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for bocs."""
from vizier._src.algorithms.designers import bocs
from vizier._src.algorithms.testing import test_runners
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/cmaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""CMA-ES designer."""
import json
import queue
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/cmaes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for cmaes."""
from vizier import benchmarks
from vizier._src.algorithms.designers import cmaes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Convergence test for Eagle Strategy."""

from vizier import benchmarks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Pythia Eagle Strategy Designer.
Implements a variation of Eagle Strategy without the Levy random walk, aka
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for eagle_strategy."""

from vizier import pyvizier as vz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Utils functions to support Eagle Strategy designer."""

import collections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for Eagle Strategy utils."""

import copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Eagle strategy designer serialization."""

import json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for serialization."""

import numpy as np
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/eagle_strategy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Testing utils for Eagle designer."""
from typing import List, Optional

Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/emukit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""EmukitDesigner wraps emukit into Vizier Designer."""

import enum
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/emukit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for emukit."""

from vizier import pyvizier as vz
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Grid Search Designer which searches over a discretized grid of Trial parameter values.
"""
from typing import List, Mapping, Optional, Sequence
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/grid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for grid."""
from vizier import pythia
from vizier import pyvizier
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/harmonica.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Harmonica algorithm for boolean search spaces from 'Hyperparameter Optimization: A Spectral Approach' (https://arxiv.org/abs/1706.00764).
This is a faithful re-implementation based off
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/harmonica_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for bocs."""
from vizier._src.algorithms.designers import harmonica
from vizier._src.algorithms.testing import test_runners
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/quasi_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Quasi-random designer."""

import collections
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/quasi_random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import random

from vizier import pyvizier as vz
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Random designer."""

from typing import Any, Optional, Sequence
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/designers/random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for random."""

from vizier import pyvizier as vz
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/evolution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations


2 changes: 2 additions & 0 deletions vizier/_src/algorithms/evolution/nsga2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""NSGA-II algorithm: https://ieeexplore.ieee.org/document/996017."""

from typing import Callable, Optional, Tuple
Expand Down
2 changes: 2 additions & 0 deletions vizier/_src/algorithms/evolution/nsga2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Tests for nsga2."""

import datetime
Expand Down
4 changes: 3 additions & 1 deletion vizier/_src/algorithms/evolution/numpy_populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

"""Core population utilities."""
import collections
import json
Expand Down Expand Up @@ -202,7 +204,7 @@ def __len__(self) -> int:
def __getitem__(
self,
index: Any,
/,

) -> 'Population':
return Population(**{k: v[index] for k, v in attr.asdict(self).items()})

Expand Down
Loading

0 comments on commit 5d4a06b

Please sign in to comment.