diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..578ba67 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: Run Python Tests for Spaces +on: + push: + branches: + - main + pull_request: + branches: + - main + + +jobs: + build: + strategy: + matrix: + os: [ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-latest] + python-version: [3.6, 3.7, 3.8, 3.9] + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Test Search Space + run: | + python -m pip install pytest + echo $PWD + ls + python --version + python -m pytest AutoDL-Projects/tests --durations=0 + diff --git a/.latent-data/NATS-Bench b/.latent-data/NATS-Bench index 51187c1..fbfcba7 160000 --- a/.latent-data/NATS-Bench +++ b/.latent-data/NATS-Bench @@ -1 +1 @@ -Subproject commit 51187c1e9152ff79b02b11c80bca0b03b402a7e5 +Subproject commit fbfcba7eb3ad19e862eca32ee0bb3195f1a8a9ef diff --git a/lib/spaces/__init__.py b/lib/spaces/__init__.py index 792d600..5550320 100644 --- a/lib/spaces/__init__.py +++ b/lib/spaces/__init__.py @@ -1 +1,7 @@ -# +##################################################### +# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2021.01 # +##################################################### +# Define complex searc space for AutoDL # +##################################################### + +from .basic_space import Categorical diff --git a/lib/spaces/basic_space.py b/lib/spaces/basic_space.py new file mode 100644 index 0000000..3f04020 --- /dev/null +++ b/lib/spaces/basic_space.py @@ -0,0 +1,33 @@ +##################################################### +# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2021.01 # +##################################################### + +import abc +import random + + +class Space(metaclass=abc.ABCMeta): + @abc.abstractmethod + def random(self): + raise NotImplementedError + + @abc.abstractmethod + def __repr__(self): + raise NotImplementedError + + +class Categorical(Space): + def __init__(self, *data): + self._candidates = [*data] + + def __getitem__(self, index): + return self._candidates[index] + + def __len__(self): + return len(self._candidates) + + def __repr__(self): + return "{name:}(candidates={cs:})".format(name=self.__class__.__name__, cs=self._candidates) + + def random(self): + return random.choice(self._candidates) diff --git a/tests/test_basic.py b/tests/test_basic.py new file mode 100644 index 0000000..6757e3a --- /dev/null +++ b/tests/test_basic.py @@ -0,0 +1,22 @@ +##################################################### +# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2021.03 # +##################################################### +import sys +import unittest +import pytest +from pathlib import Path + +lib_dir = (Path(__file__).parent / ".." / "lib").resolve() +print("library path: {:}".format(lib_dir)) +if str(lib_dir) not in sys.path: + sys.path.insert(0, str(lib_dir)) + +from spaces import Categorical + + +class TestBasicSpace(unittest.TestCase): + def test_categorical(self): + space = Categorical(1, 2, 3, 4) + for i in range(4): + self.assertEqual(space[i], i + 1) + self.assertEqual("Categorical(candidates=[1, 2, 3, 4])", str(space))