diff --git a/.github/actions/install-examples/action.yml b/.github/actions/install-examples/action.yml new file mode 100644 index 000000000..7ea99b27e --- /dev/null +++ b/.github/actions/install-examples/action.yml @@ -0,0 +1,14 @@ +name: install-examples + +runs: + using: composite + steps: + - name: Install Melting Pot + uses: ./.github/actions/install-meltingpot + - name: Install requirements for examples + shell: bash + # run: pip -r examples/requirements.txt + run: pip install matplotlib + - name: Show installed dependencies + shell: bash + run: pip list diff --git a/.github/actions/install-meltingpot/action.yml b/.github/actions/install-meltingpot/action.yml new file mode 100644 index 000000000..cf1492fc5 --- /dev/null +++ b/.github/actions/install-meltingpot/action.yml @@ -0,0 +1,37 @@ +name: install-meltingpot + +inputs: + python-version: + description: Python version + required: false + default: '3.10' + type: string + +runs: + using: composite + steps: + - name: Set up Python + id: setup + uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 + with: + python-version: ${{ inputs.python-version }} + cache: 'pip' + cache-dependency-path: setup.py + - name: Cached=${{ ! steps.setup.outputs.cache-hit }} + shell: bash + run: pip cache list + - name: Show contents + shell: bash + run: ls -la + - name: Show mp contents + shell: bash + run: ls -la meltingpot + - name: Install Python dependencies + if: ${{ ! steps.setup.outputs.cache-hit }} + shell: bash + run: | + pip install -e .[dev] + pip cache list + - name: Show installed dependencies + shell: bash + run: pip list diff --git a/.github/workflows/pylint-examples.yml b/.github/workflows/pylint-examples.yml new file mode 100644 index 000000000..11c509071 --- /dev/null +++ b/.github/workflows/pylint-examples.yml @@ -0,0 +1,43 @@ +name: pylint-examples + +on: + push: + branches: + - main + paths: + - '.github/actions/install-examples.yml' + - '.github/actions/install-meltingpot.yml' + - '.github/workflows/pylint-examples.yml' + - '.pylintrc' + - 'examples/**' + - 'meltingpot/**' + pull_request: + branches: + - main + paths: + - '.github/actions/install-examples.yml' + - '.github/actions/install-meltingpot.yml' + - '.github/workflows/pylint-examples.yml' + - '.pylintrc' + - 'examples/**' + - 'meltingpot/**' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +permissions: read-all + +jobs: + pylint: + name: Lint Melting Pot + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout Melting Pot + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - name: Install examples + uses: ./.github/actions/install-examples + - name: Run PyLint on examples + run: pylint --errors-only examples diff --git a/.github/workflows/pylint-meltingpot.yml b/.github/workflows/pylint-meltingpot.yml new file mode 100644 index 000000000..d17c9b58a --- /dev/null +++ b/.github/workflows/pylint-meltingpot.yml @@ -0,0 +1,41 @@ +name: pylint-meltingpot + +on: + push: + branches: + - main + paths: + - '.github/actions/install-meltingpot.yml' + - '.github/workflows/pylint-meltingpot.yml' + - '.pylintrc' + - 'examples/**' + - 'meltingpot/**' + pull_request: + branches: + - main + paths: + - '.github/actions/install-meltingpot.yml' + - '.github/workflows/pylint-meltingpot.yml' + - '.pylintrc' + - 'examples/**' + - 'meltingpot/**' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +permissions: read-all + +jobs: + pylint: + name: Lint Melting Pot + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout Melting Pot + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - name: Install Melting Pot + uses: ./.github/actions/install-meltingpot + - name: Run PyLint on Melting Pot + run: pylint --errors-only meltingpot diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml deleted file mode 100644 index 686c99615..000000000 --- a/.github/workflows/pylint.yml +++ /dev/null @@ -1,47 +0,0 @@ -# Continuous integration tests. - -name: pylint - -on: - push: - branches: - - main - paths: - - '.github/workflows/pylint.yml' - - '.pylintrc' - - 'examples/**' - - 'meltingpot/**' - pull_request: - branches: - - main - paths: - - '.github/workflows/pylint.yml' - - '.pylintrc' - - 'examples/**' - - 'meltingpot/**' - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} - cancel-in-progress: true - -permissions: read-all - -jobs: - pylint: - name: Lint Melting Pot - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - name: Checkout Melting Pot - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - - name: Set up Python - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 - with: - python-version: '3.10' - - name: Install Python dependencies - run: | - pip install --upgrade pip - pip install pylint - - name: Run PyLint - run: pylint --disable=C,W,R --recursive=y meltingpot examples diff --git a/.github/workflows/pytype-examples.yml b/.github/workflows/pytype-examples.yml new file mode 100644 index 000000000..1a6e6862b --- /dev/null +++ b/.github/workflows/pytype-examples.yml @@ -0,0 +1,43 @@ +name: pytype-examples + +on: + push: + branches: + - main + paths: + - '.github/actions/install-examples.yml' + - '.github/actions/install-meltingpot.yml' + - '.github/workflows/pytype-examples.yml' + - 'examples/**' + - 'meltingpot/**' + - 'pyproject.toml' + pull_request: + branches: + - main + paths: + - '.github/actions/install-examples.yml' + - '.github/actions/install-meltingpot.yml' + - '.github/workflows/pytype-examples.yml' + - 'examples/**' + - 'meltingpot/**' + - 'pyproject.toml' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +permissions: read-all + +jobs: + pytype: + name: Typecheck Melting Pot + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout Melting Pot + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - name: Install examples + uses: ./.github/actions/install-examples + - name: Run PyType on examples + run: pytype examples diff --git a/.github/workflows/pytype-meltingpot.yml b/.github/workflows/pytype-meltingpot.yml new file mode 100644 index 000000000..8260bc723 --- /dev/null +++ b/.github/workflows/pytype-meltingpot.yml @@ -0,0 +1,41 @@ +name: pytype-meltingpot + +on: + push: + branches: + - main + paths: + - '.github/actions/install-meltingpot.yml' + - '.github/workflows/pytype-meltingpot.yml' + - 'examples/**' + - 'meltingpot/**' + - 'pyproject.toml' + pull_request: + branches: + - main + paths: + - '.github/actions/install-meltingpot.yml' + - '.github/workflows/pytype-meltingpot.yml' + - 'examples/**' + - 'meltingpot/**' + - 'pyproject.toml' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +permissions: read-all + +jobs: + pytype: + name: Typecheck Melting Pot + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout Melting Pot + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - name: Install Melting Pot + uses: ./.github/actions/install-meltingpot + - name: Run PyType on Melting Pot + run: pytype meltingpot diff --git a/.github/workflows/pytype.yml b/.github/workflows/pytype.yml deleted file mode 100644 index fd1b22ea2..000000000 --- a/.github/workflows/pytype.yml +++ /dev/null @@ -1,55 +0,0 @@ -# Continuous integration tests. - -name: pytype - -on: - push: - branches: - - main - paths: - - '.github/workflows/pytype.yml' - - 'examples/**' - - 'meltingpot/**' - - 'pyproject.toml' - pull_request: - branches: - - main - paths: - - '.github/workflows/pytype.yml' - - 'examples/**' - - 'meltingpot/**' - - 'pyproject.toml' - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} - cancel-in-progress: true - -permissions: read-all - -jobs: - pytype: - name: Typecheck Melting Pot - runs-on: ubuntu-latest - timeout-minutes: 30 - strategy: - fail-fast: ${{ github.event_name != 'workflow_dispatch' }} - steps: - - name: Checkout Melting Pot - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - - name: Set up Python - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 - with: - python-version: '3.10' - - name: Install Python dependencies - run: | - pip install --upgrade pip - pip install setuptools pytype - - name: Install Melting Pot - run: pip -vvv install . - - name: Run PyType on Melting Pot - run: pytype meltingpot - - name: Install example requirements - run: pip -vvv install -r examples/requirements.txt - - name: Run PyType on examples - run: pytype examples diff --git a/.github/workflows/test-examples.yml b/.github/workflows/test-examples.yml index 1bd4033b3..cda0aa597 100644 --- a/.github/workflows/test-examples.yml +++ b/.github/workflows/test-examples.yml @@ -1,5 +1,3 @@ -# Continuous integration tests. - name: test-examples on: @@ -7,18 +5,24 @@ on: branches: - main paths: + - '.github/actions/install-examples.yml' + - '.github/actions/install-meltingpot.yml' - '.github/workflows/test-examples.yml' - 'examples/**' - 'meltingpot/**' - 'setup.py' + - 'pyproject.toml' pull_request: branches: - main paths: + - '.github/actions/install-examples.yml' + - '.github/actions/install-meltingpot.yml' - '.github/workflows/test-examples.yml' - 'examples/**' - 'meltingpot/**' - 'setup.py' + - 'pyproject.toml' workflow_dispatch: concurrency: @@ -31,27 +35,11 @@ jobs: test-examples: name: Test examples runs-on: ubuntu-latest - env: - SYSTEM_VERSION_COMPAT: 0 # See https://github.com/actions/setup-python/issues/279. timeout-minutes: 90 steps: - name: Checkout Melting Pot - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - - name: Set up Python - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 - with: - python-version: '3.10' - - name: Install Python dependencies - run: | - pip install --upgrade pip - pip install setuptools pytest-xdist - - name: Install Melting Pot - run: | - pip -vvv install . - pip list + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - name: Install examples - run: | - pip install -r examples/requirements.txt - pip list + uses: ./.github/actions/install-examples - name: Test examples run: pytest examples diff --git a/.github/workflows/test-meltingpot.yml b/.github/workflows/test-meltingpot.yml index 744b0d66c..853135564 100644 --- a/.github/workflows/test-meltingpot.yml +++ b/.github/workflows/test-meltingpot.yml @@ -1,5 +1,3 @@ -# Continuous integration tests. - name: test-meltingpot on: @@ -7,16 +5,20 @@ on: branches: - main paths: + - '.github/actions/install-meltingpot.yml' - '.github/workflows/test-meltingpot.yml' - 'meltingpot/**' - 'setup.py' + - 'pyproject.toml' pull_request: branches: - main paths: + - '.github/actions/install-meltingpot.yml' - '.github/workflows/test-meltingpot.yml' - 'meltingpot/**' - 'setup.py' + - 'pyproject.toml' workflow_dispatch: concurrency: @@ -26,7 +28,7 @@ concurrency: permissions: read-all jobs: - test-meltingpot: + pytest: name: Test Melting Pot runs-on: ${{ matrix.os }} env: @@ -41,17 +43,11 @@ jobs: python-version: - '3.10' steps: - - name: Set up Python - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 + - name: Checkout Melting Pot + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - name: Install Melting Pot + uses: ./.github/actions/install-meltingpot with: python-version: ${{ matrix.python-version }} - - name: Install Python dependencies - run: | - pip install --upgrade pip - pip install setuptools pytest-xdist - - name: Install Melting Pot - run: | - pip -vvv install https://github.com/deepmind/meltingpot/archive/${{ github.sha }}.tar.gz - pip list - name: Test Melting Pot - run: pytest --pyargs meltingpot + run: pytest meltingpot diff --git a/meltingpot/testing/mocks_test.py b/meltingpot/testing/mocks_test.py index 166ad3456..7b94b5725 100644 --- a/meltingpot/testing/mocks_test.py +++ b/meltingpot/testing/mocks_test.py @@ -30,8 +30,8 @@ def test_value_from_specs(self): ) actual = mocks._values_from_specs(specs) expected = ( - {'a': np.zeros([1, 2, 3], dtype=np.uint8) + 0}, - {'b': np.zeros([1, 2, 3], dtype=np.uint8) + 1}, + {'a': np.zeros([1, 2, 3], dtype=np.uint8)}, + {'b': np.ones([1, 2, 3], dtype=np.uint8)}, ) np.testing.assert_equal(actual, expected) @@ -44,7 +44,10 @@ def test_mock_substrate(self): num_actions=num_actions, observation_spec=observation_spec) - expected_observation = ({'a': np.uint8()}, {'a': np.uint8() + 1}) + expected_observation = ( + {'a': np.zeros([], dtype=np.uint8)}, + {'a': np.ones([], dtype=np.uint8)}, + ) expected_reward = tuple(float(n) for n in range(num_players)) with self.subTest('is_substrate'): diff --git a/meltingpot/utils/policies/saved_model_policy.py b/meltingpot/utils/policies/saved_model_policy.py index 8df461f39..01fd4ea04 100644 --- a/meltingpot/utils/policies/saved_model_policy.py +++ b/meltingpot/utils/policies/saved_model_policy.py @@ -136,7 +136,7 @@ def __init__(self, model_path: str, device_name: str = 'cpu') -> None: @contextlib.contextmanager def _build_context(self): - with self._graph.as_default(): + with self._graph.as_default(): # pylint: disable=not-context-manager with tf.compat.v1.device(self._device_name): yield