From 72c4c454ccdfcfcccf4fd19cec22d7606b6fb42d Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Sat, 25 Nov 2023 03:32:14 +0100 Subject: [PATCH 1/9] Remove the misleading text when joining/hosting multiplayer game --- src/vizdoom/src/posix/sdl/st_start.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vizdoom/src/posix/sdl/st_start.cpp b/src/vizdoom/src/posix/sdl/st_start.cpp index a4b55cb0f..ec2be5189 100644 --- a/src/vizdoom/src/posix/sdl/st_start.cpp +++ b/src/vizdoom/src/posix/sdl/st_start.cpp @@ -192,8 +192,10 @@ void FTTYStartupScreen::NetInit(const char *message, int numplayers) { termios rawtermios; - fprintf (stderr, "Press 'Q' to abort network game synchronization."); - fprintf (stderr, "\nNetwork game synchronization timeout: %ds.", (unsigned int)*viz_connect_timeout); + // VIZDOOM_CODE + //fprintf (stderr, "Press 'Q' to abort network game synchronization.\n"); // When using as controlled subpcrocess, this won't work. + + fprintf (stderr, "Network game synchronization timeout: %ds.", (unsigned int)*viz_connect_timeout); // Set stdin to raw mode so we can get keypresses in ST_CheckNetAbort() // immediately without waiting for an EOL. tcgetattr (STDIN_FILENO, &OldTermIOS); From 087d739cb49eda1659d4f4f2c2c269c97166a32c Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Sat, 25 Nov 2023 13:45:03 +0100 Subject: [PATCH 2/9] Remove usage of deprecated distutils from setup.py --- setup.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index aa4c2dc62..65ee7a1fa 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ import subprocess import sys import warnings -from distutils import sysconfig -from distutils.command.build import build +import sysconfig from multiprocessing import cpu_count from setuptools import Distribution, setup from setuptools.command.install import install +from setuptools.command.build import build from wheel.bdist_wheel import bdist_wheel @@ -182,7 +182,7 @@ def run(self): subprocess.check_call(["make", "-j", str(cpu_cores)]) except subprocess.CalledProcessError: sys.stderr.write( - "\033[1m\nInstallation failed, you may be missing some dependencies. " + "\033[1m\nInstallation from source failed, you may be missing some dependencies. " "\nPlease check https://github.com/mwydmuch/ViZDoom/blob/master/doc/Installation.md " "for details\n\n\033[0m" ) @@ -197,14 +197,15 @@ def run(self): description="ViZDoom is Doom-based AI Research Platform for Reinforcement Learning from Raw Visual Information.", long_description=get_long_description(), long_description_content_type="text/markdown", - url="http://vizdoom.cs.put.edu.pl/", - author="Marek Wydmuch, Michał Kempka, Wojciech Jaśkowski, Grzegorz Runc, Jakub Toczek, and the respective contributors", + url="https://vizdoom.farama.org", + author="Marek Wydmuch, Michał Kempka, Wojciech Jaśkowski, Farama Foundation, and the respective contributors", author_email="mwydmuch@cs.put.poznan.pl", extras_require={ "gym": ["gym>=0.26.0", "pygame>=2.1.3"], "test": ["pytest", "psutil"], }, install_requires=["numpy", "gymnasium>=0.28.0", "pygame>=2.1.3"], + python_requires=">=3.8.0,<3.13", packages=["vizdoom"], package_dir={"vizdoom": package_path}, package_data={"vizdoom": package_data}, @@ -224,6 +225,7 @@ def run(self): "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Operating System :: Microsoft :: Windows", "Operating System :: MacOS :: MacOS X", "Operating System :: POSIX :: Linux", From f290240690f6ff8fcb09fa18aad50a1e688cc89c Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Mon, 11 Dec 2023 17:36:44 +0100 Subject: [PATCH 3/9] Update the setup.py to list all subpackages --- docs/introduction/building.md | 4 +-- docs/introduction/pythonQuickstart.md | 14 ++++---- scripts/assemble_pip_package.bat | 2 +- scripts/assemble_pip_package.sh | 2 +- scripts/windows_build_cmake.bat | 6 ++-- setup.py | 46 ++++++++++++++++----------- src/lib_python/CMakeLists.txt | 4 +-- 7 files changed, 43 insertions(+), 35 deletions(-) diff --git a/docs/introduction/building.md b/docs/introduction/building.md index b0fc8e11d..c238f0c91 100644 --- a/docs/introduction/building.md +++ b/docs/introduction/building.md @@ -172,9 +172,9 @@ Compilation output will be placed in `build/bin` and it should contain the follo * `bin/libvizdoom.a / vizdoom.lib` - C++ ViZDoom static library * `bin/libvizdoom.so / vizdoom.dll / libvizdoom.dylib` - C++ ViZDoom dynamically linked library * `bin/pythonX.X/vizdoom.so / vizdoom.pyd / vizdoom.dylib ` - ViZDoom Python X.X module -* `bin/pythonX.X/pip_package` - complete ViZDoom Python X.X package +* `bin/pythonX.X/vizdoom` - complete ViZDoom Python X.X package ### Manual installation -To manually install Python package copy `vizdoom_root_dir/build/bin/pythonX.X/pip_package` contents to `python_root_dir/lib/pythonX.X/site-packages/site-packages/vizdoom`. +To manually install Python package copy `vizdoom_root_dir/build/bin/pythonX.X/vizdoom` contents to `python_root_dir/lib/pythonX.X/site-packages/site-packages/vizdoom`. diff --git a/docs/introduction/pythonQuickstart.md b/docs/introduction/pythonQuickstart.md index cacd7555b..ce3d34660 100644 --- a/docs/introduction/pythonQuickstart.md +++ b/docs/introduction/pythonQuickstart.md @@ -8,8 +8,8 @@ pip install vizdoom Both x86-64 and AArch64 (ARM64) architectures are supported. Wheels are available for Python 3.8+ on Linux. -If Python wheel is not available for your platform (Python version <3.8, distros below manylinux_2_28 standard), pip will try to install (build) ViZDoom from the source. -ViZDoom requires a C++11 compiler, CMake 3.12+, Boost 1.54+ SDL2, OpenAL (optional), and Python 3.7+ to install from source. Below, you will find instructions on how to install these dependencies. +If Python wheel is not available for your platform (distros incompatible with manylinux_2_28 standard), pip will try to install (build) ViZDoom from the source. +ViZDoom requires a C++11 compiler, CMake 3.12+, Boost 1.54+ SDL2, OpenAL (optional), and Python 3.8+ to install from source. Below, you will find instructions on how to install these dependencies. ### apt-based distros (Ubuntu, Debian, Linux Mint, etc.) @@ -27,7 +27,7 @@ To install ViZDoom, run (it may take a few minutes): dnf install cmake git boost-devel SDL2-devel openal-soft-devel pip install vizdoom ``` -We recommend using at least Fedora 35+ or RHEL/CentOS/Alma/Rocky Linux 9+ with Python 3.7+. +We recommend using at least Fedora 35+ or RHEL/CentOS/Alma/Rocky Linux 9+ with Python 3.8+. To install openal-soft-devel on RHEL/CentOS/Alma/Rocky Linux 9, one needs to use `dnf --enablerepo=crb install`. ### master branch version @@ -44,9 +44,9 @@ To install the latest release of ViZDoom, just run (it may take a few minutes as brew install cmake boost sdl2 openal-soft pip install vizdoom ``` -Both Intel and Apple Silicon CPUs are supported. -We recommend using at least macOS High Sierra 10.13+ with Python 3.7+. -On Apple Silicon (M1 and M2), make sure you are using Python/Pip for Apple Silicon. +Both Intel and Apple Silicon (M1/2/3) CPUs are supported. +We recommend using at least macOS High Sierra 10.13+ with Python 3.8+. +On Apple Silicon, make sure you are using Python/Pip for Apple Silicon. To install the master branch version of ViZDoom, run: ```sh @@ -60,7 +60,7 @@ To install the latest release of ViZDoom, just run: pip install vizdoom ``` At the moment, only x86-64 architecture is supported on Windows. -Wheels are available for Python 3.8+ on Windows. +Wheels are available for Python 3.8+ x86-64 on Windows. Please note that the Windows version is not as well-tested as Linux and macOS versions. It can be used for development and testing but if you want to conduct serious (time and resource-extensive) experiments on Windows, diff --git a/scripts/assemble_pip_package.bat b/scripts/assemble_pip_package.bat index 466e22679..f39e68106 100755 --- a/scripts/assemble_pip_package.bat +++ b/scripts/assemble_pip_package.bat @@ -10,7 +10,7 @@ set "BIN_PATH=%BIN_PATH:/=\%" set "SRC_PATH=%SRC_PATH:/=\%" set PACKAGE_DEST_DIRECTORY=%BIN_PATH%\python%PYTHON_VERSION% -set PACKAGE_DEST_PATH=%PACKAGE_DEST_DIRECTORY%\pip_package +set PACKAGE_DEST_PATH=%PACKAGE_DEST_DIRECTORY%\vizdoom set PACAKGE_INIT_FILE_SRC=%SRC_PATH%\src\lib_python\__init__.py set VIZDOOM_EXEC_PATH=%BIN_PATH%\vizdoom.exe diff --git a/scripts/assemble_pip_package.sh b/scripts/assemble_pip_package.sh index 810f2afa9..a7502d197 100755 --- a/scripts/assemble_pip_package.sh +++ b/scripts/assemble_pip_package.sh @@ -10,7 +10,7 @@ if [ $# -ne 3 ];then fi PACKAGE_DEST_DIRECTORY="${BIN_PATH}/python${PYTHON_VERSION}" -PACKAGE_DEST_PATH="${PACKAGE_DEST_DIRECTORY}/pip_package" +PACKAGE_DEST_PATH="${PACKAGE_DEST_DIRECTORY}/vizdoom" PACKAGE_INIT_FILE_SRC="${SRC_PATH}/src/lib_python/__init__.py" if [ "$(uname)" == "Darwin" ]; then diff --git a/scripts/windows_build_cmake.bat b/scripts/windows_build_cmake.bat index 67990fafc..3b95a873d 100755 --- a/scripts/windows_build_cmake.bat +++ b/scripts/windows_build_cmake.bat @@ -61,7 +61,7 @@ for %%P in (38 39 310 311) do ( :: Run build cmake --build . --config Release - copy /Y !MPG123_DLL! .\bin\python!PYTHON_VERSION_DOT!\pip_package\ - copy /Y !SNDFILE_DLL! .\bin\python!PYTHON_VERSION_DOT!\pip_package\ - copy /Y !OPENAL_DLL! .\bin\python!PYTHON_VERSION_DOT!\pip_package\ + copy /Y !MPG123_DLL! .\bin\python!PYTHON_VERSION_DOT!\vizdoom\ + copy /Y !SNDFILE_DLL! .\bin\python!PYTHON_VERSION_DOT!\vizdoom\ + copy /Y !OPENAL_DLL! .\bin\python!PYTHON_VERSION_DOT!\vizdoom\ ) diff --git a/setup.py b/setup.py index 65ee7a1fa..23364776b 100644 --- a/setup.py +++ b/setup.py @@ -2,34 +2,42 @@ import shutil import subprocess import sys -import warnings import sysconfig +import warnings from multiprocessing import cpu_count from setuptools import Distribution, setup -from setuptools.command.install import install from setuptools.command.build import build +from setuptools.command.install import install from wheel.bdist_wheel import bdist_wheel +# Configure paths platform = sys.platform python_version = sysconfig.get_python_version() build_output_path = "bin" -package_path = build_output_path + "/python" + python_version + "/pip_package" -supported_platforms = ["Linux", "Mac OS X", "Windows"] -package_data = [ - "__init__.py", - "bots.cfg", - "freedoom2.wad", - "vizdoom.pk3", - "vizdoom", - "scenarios/*", - "gym_wrapper/*", - "gymnasium_wrapper/*", -] +package_root = os.path.join(build_output_path, f"python{python_version}") +package_path = os.path.join(package_root, "vizdoom") +# Configure packages and package data +packages = ["vizdoom"] +shutil.rmtree(package_path, ignore_errors=True) os.makedirs(package_path, exist_ok=True) +package_data = ["__init__.py", "bots.cfg", "freedoom2.wad", "vizdoom.pk3"] + + +# Add subpackages +def add_subpackage(dir_path): + shutil.copytree(dir_path, os.path.join(package_path, dir_path)) + packages.append(f"vizdoom.{dir_path}") + package_data.append(f"{dir_path}/*") + + +add_subpackage("scenarios") +add_subpackage("gym_wrapper") +add_subpackage("gymnasium_wrapper") +# Platform specific package data if platform.startswith("win"): package_data.extend(["vizdoom.exe", "*.pyd", "*.dll"]) library_extension = "lib" @@ -167,6 +175,7 @@ def run(self): if os.path.exists("CMakeCache.txt"): os.remove("CMakeCache.txt") + cmake_arg_list.append(".") print(f"Running cmake with arguments: {cmake_arg_list}", file=sys.stderr) try: @@ -183,8 +192,7 @@ def run(self): except subprocess.CalledProcessError: sys.stderr.write( "\033[1m\nInstallation from source failed, you may be missing some dependencies. " - "\nPlease check https://github.com/mwydmuch/ViZDoom/blob/master/doc/Installation.md " - "for details\n\n\033[0m" + "\nPlease check https://vizdoom.farama.org/introduction/pythonQuickstart for details.\n\n\033[0m" ) raise @@ -206,13 +214,13 @@ def run(self): }, install_requires=["numpy", "gymnasium>=0.28.0", "pygame>=2.1.3"], python_requires=">=3.8.0,<3.13", - packages=["vizdoom"], - package_dir={"vizdoom": package_path}, + packages=packages, + package_dir={"": package_root}, package_data={"vizdoom": package_data}, include_package_data=True, cmdclass={"bdist_wheel": Wheel, "build": BuildCommand, "install": InstallPlatlib}, distclass=BinaryDistribution, - platforms=supported_platforms, + platforms=["Linux", "Mac OS X", "Windows"], classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Education", diff --git a/src/lib_python/CMakeLists.txt b/src/lib_python/CMakeLists.txt index 2ad84d8f3..eaa46d94d 100644 --- a/src/lib_python/CMakeLists.txt +++ b/src/lib_python/CMakeLists.txt @@ -73,11 +73,11 @@ set_target_properties(libvizdoom_python if(UNIX) add_custom_target(python_pip_package ALL COMMAND ${VIZDOOM_SCRIPTS_DIR}/assemble_pip_package.sh ${BUILD_PYTHON_VERSION} ${VIZDOOM_OUTPUT_DIR} ${CMAKE_SOURCE_DIR} - COMMENT "Assembling pip package in ${VIZDOOM_PYTHON_OUTPUT_DIR}/pip_package") + COMMENT "Assembling pip package in ${VIZDOOM_PYTHON_OUTPUT_DIR}/vizdoom") elseif(WIN32) add_custom_target(python_pip_package ALL COMMAND ${VIZDOOM_SCRIPTS_DIR}/assemble_pip_package.bat ${BUILD_PYTHON_VERSION} ${VIZDOOM_OUTPUT_DIR} ${CMAKE_SOURCE_DIR} - COMMENT "Assembling pip package in ${VIZDOOM_PYTHON_OUTPUT_DIR}/pip_package") + COMMENT "Assembling pip package in ${VIZDOOM_PYTHON_OUTPUT_DIR}/vizdoom") endif() set_target_properties(python_pip_package From 6e62e6f27307272c513d790bcd5e4c61d7d8f636 Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Mon, 11 Dec 2023 17:40:30 +0100 Subject: [PATCH 4/9] Update the tests --- examples/python/README.md | 2 +- examples/python/audio_buffer.py | 5 +- tests/build_test_cibuildwheel_linux.sh | 8 ++- tests/build_test_local_linux_builds.sh | 4 +- tests/test_get_state.py | 46 +++++++++++++--- tests/test_make_action.py | 55 ++++++++++++++----- .../apt-based.Dockerfile | 2 +- .../conda-based.Dockerfile | 2 + .../dnf-based.Dockerfile | 2 +- 9 files changed, 96 insertions(+), 30 deletions(-) diff --git a/examples/python/README.md b/examples/python/README.md index a6937db5d..084f20e05 100644 --- a/examples/python/README.md +++ b/examples/python/README.md @@ -1,6 +1,6 @@ # Python examples -For the examples to work properly you need to install ViZDoom or create a link to dir with ViZDoom pip_package. +For the examples to work properly you need to install ViZDoom. ## The list of examples diff --git a/examples/python/audio_buffer.py b/examples/python/audio_buffer.py index 8204a6c6a..a03143d51 100755 --- a/examples/python/audio_buffer.py +++ b/examples/python/audio_buffer.py @@ -43,7 +43,8 @@ frameskip = 4 game.set_audio_buffer_size(frameskip) - # This could fix "no audio in buffer" bug on Ubuntu 20.04. + # This could fix "BiquadFilter_setParams: Assertion `gain > 0.00001f' failed" issue + # or "no audio in buffer" issue caused by a bug in OpenAL version 1.19. # game.add_game_args("+snd_efx 0") # Initialize the game. Further configuration won't take any effect from now on. @@ -92,7 +93,7 @@ " See https://github.com/Farama-Foundation/ViZDoom/pull/486\n" " Two possible fixes:\n" " 1) Try setting game.add_game_args('+snd_efx 0'). This my disable some audio effects\n" - " 2) Try installing a newer version of OpenAL Soft library, see https://github.com/Farama-Foundation/ViZDoom/pull/486#issuecomment-889389185" + " 2) Try installing OpenAL or a newer version of OpenAL Soft library, see https://github.com/Farama-Foundation/ViZDoom/pull/486#issuecomment-889389185" ) # Save audio file wavfile.write("basic_sounds.wav", 22050, np.concatenate(audio_slices, axis=0)) diff --git a/tests/build_test_cibuildwheel_linux.sh b/tests/build_test_cibuildwheel_linux.sh index 61077e08a..22ab30aca 100755 --- a/tests/build_test_cibuildwheel_linux.sh +++ b/tests/build_test_cibuildwheel_linux.sh @@ -13,13 +13,15 @@ IMAGE_PREFIX="vizdoom_wheels" # Array in format " " DOCKERFILES_TO_BUILD_AND_RUN=( - "almalinux:9 dnf-based.Dockerfile" # Python 3.9 + "almalinux:9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb" # Python 3.9 "fedora:36 dnf-based.Dockerfile" # Python 3.10 "fedora:37 dnf-based.Dockerfile" # Python 3.11 - "rockylinux:9 dnf-based.Dockerfile" # Python 3.9 - "debian:11.6 apt-based.Dockerfile ENV LANG C.UTF-8" # Python 3.9 + "rockylinux:9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb" # Python 3.9 + "debian:11 apt-based.Dockerfile ENV LANG C.UTF-8" # Python 3.9 + "debian:latest apt-based.Dockerfile ENV LANG C.UTF-8" # Python 3.11 "ubuntu:20.04 apt-based.Dockerfile" # Python 3.8 "ubuntu:22.04 apt-based.Dockerfile" # Python 3.10 + "ubuntu:latest apt-based.Dockerfile" # Python 3.11 "continuumio/miniconda3:latest conda-based.Dockerfile" # Python 3.10 ) diff --git a/tests/build_test_local_linux_builds.sh b/tests/build_test_local_linux_builds.sh index 7f8b79f16..428afdb0a 100755 --- a/tests/build_test_local_linux_builds.sh +++ b/tests/build_test_local_linux_builds.sh @@ -17,9 +17,11 @@ DOCKERFILES_TO_BUILD_AND_RUN=( "fedora:36 dnf-based.Dockerfile" "fedora:37 dnf-based.Dockerfile" "rockylinux:9 dnf-based.Dockerfile RUN dnf install -y 'dnf-command(config-manager)' && dnf config-manager --set-enabled crb" - "debian:11.6 apt-based.Dockerfile ENV LANG C.UTF-8" + "debian:11 apt-based.Dockerfile ENV LANG C.UTF-8" + "debian:latest apt-based.Dockerfile ENV LANG C.UTF-8" "ubuntu:20.04 apt-based.Dockerfile" "ubuntu:22.04 apt-based.Dockerfile" + "ubuntu:latest apt-based.Dockerfile" "ubuntu:20.04 apt+conda-based.Dockerfile" # Ubuntu build with dependencies installed via conda #"continuumio/miniconda3:latest conda-based.Dockerfile" # Does not work at the moment ) diff --git a/tests/test_get_state.py b/tests/test_get_state.py index 8c3eb698e..4caa87fd4 100755 --- a/tests/test_get_state.py +++ b/tests/test_get_state.py @@ -5,8 +5,8 @@ import os import pickle +import random from itertools import product -from random import choice import numpy as np import psutil @@ -23,9 +23,12 @@ def _test_get_state( automapBuffer=False, objectsInfo=False, sectorsInfo=False, + audioBuffer=False, ): print("Testing get_state() ...") + random.seed(1993) + buttons = [ vzd.Button.MOVE_FORWARD, vzd.Button.MOVE_BACKWARD, @@ -48,6 +51,20 @@ def _test_get_state( game.set_automap_buffer_enabled(automapBuffer) game.set_objects_info_enabled(objectsInfo) game.set_sectors_info_enabled(sectorsInfo) + game.set_audio_buffer_enabled(audioBuffer) + + buffers = ["screen_buffer"] + if depthBuffer: + buffers.append("depth_buffer") + if labelsBuffer: + buffers.append("labels_buffer") + if automapBuffer: + buffers.append("automap_buffer") + if audioBuffer: + buffers.append("audio_buffer") + # This fixes "BiquadFilter_setParams: Assertion `gain > 0.00001f' failed" issue + # or "no audio in buffer" issue caused by a bug in OpenAL version 1.19. + game.add_game_args("+snd_efx 0") game.init() @@ -56,7 +73,7 @@ def _test_get_state( for i in range(num_iterations): states = [] - screen_buffer_copies = [] + buffers_copies = [] game.new_episode() for _ in range(num_states): @@ -65,16 +82,28 @@ def _test_get_state( state = game.get_state() states.append(state) - screen_buffer_copies.append(np.copy(state.screen_buffer)) - - game.make_action(choice(actions), 4) + copies = {} + for b in buffers: + copies[b] = np.copy(getattr(state, b)) + buffers_copies.append(copies) + game.make_action(random.choice(actions), 4) assert len(states) == num_states - assert len(screen_buffer_copies) == num_states + assert len(buffers_copies) == num_states # Compare states with their copies - confirms that states don't mutate. - for s, sb_copy in zip(states, screen_buffer_copies): - assert np.array_equal(s.screen_buffer, sb_copy) + # Check min and max values of buffers - confirms that buffers are not empty. + min_vals = {b: np.inf for b in buffers} + max_vals = {b: -np.inf for b in buffers} + for s, bs_copy in zip(states, buffers_copies): + for b in buffers: + assert np.array_equal(getattr(s, b), bs_copy[b]) + min_vals[b] = min(min_vals[b], np.min(bs_copy[b])) + max_vals[b] = max(max_vals[b], np.max(bs_copy[b])) + + for b in buffers: + print(f"Buffer {b} min: {min_vals[b]}, max: {max_vals[b]}") + assert min_vals[b] != max_vals[b] # Save and load states via pickle - confirms that states and all sub-objects (labels, lines, objects) are picklable. with open("tmp_states.pkl", "wb") as f: @@ -118,6 +147,7 @@ def test_get_state(num_iterations=10, num_states=20): automapBuffer=True, objectsInfo=True, sectorsInfo=True, + audioBuffer=True, # Turned off by default, because it fails on some systems without audio backend and OpenAL installed ) diff --git a/tests/test_make_action.py b/tests/test_make_action.py index d9ae8dce2..79535bea4 100755 --- a/tests/test_make_action.py +++ b/tests/test_make_action.py @@ -8,6 +8,18 @@ import vizdoom as vzd +def _init_game(): + game = vzd.DoomGame() + game.set_window_visible(False) + game.set_available_buttons( + [vzd.Button.MOVE_LEFT, vzd.Button.MOVE_RIGHT, vzd.Button.ATTACK] + ) + game.set_episode_start_time(35) + game.init() + + return game + + def _test_exception(func, error, msg): try: func() @@ -47,20 +59,14 @@ def __test_make_action_input( ) # Prepare game - game = vzd.DoomGame() - game.set_window_visible(False) - game.set_available_buttons( - [vzd.Button.MOVE_LEFT, vzd.Button.MOVE_RIGHT, vzd.Button.ATTACK] - ) - game.set_episode_start_time(35) + game = _init_game() - game.init() prev_pos_y = game.get_game_variable(vzd.GameVariable.POSITION_Y) prev_ammo = game.get_game_variable(vzd.GameVariable.AMMO2) # make_action() with correct arguments next_action = type_name([1, 0, 1], **type_args) - game.make_action(next_action, 8) + make_action_func(game, next_action, 8) assert prev_pos_y < game.get_game_variable(vzd.GameVariable.POSITION_Y) prev_pos_y = game.get_game_variable(vzd.GameVariable.POSITION_Y) assert prev_ammo > game.get_game_variable(vzd.GameVariable.AMMO2) @@ -70,11 +76,7 @@ def __test_make_action_input( # make_action() without skipping frames make_action_func(game, next_action) - # use set_action() instead of make_action() - game.set_action(next_action) - game.advance_action() - - # make_action() with negative frames and other types + # make_action_func() with negative frames and other types error_msg = "make_action() should raise TypeError when called with negative frames or type other than unsigned int" _test_exception( lambda: make_action_func(game, next_action, -10), TypeError, error_msg @@ -147,8 +149,35 @@ def mixed_typed_list(data, dtypes): _test_make_action_input(mixed_typed_list, {"dtypes": [bool, int, float, bool]}) +def test_keyword_arguments(): + game = _init_game() + + game.make_action(action=[1, 1, 1], tics=10) + game.set_action(action=[1, 0, 1]) + game.advance_action(update_state=False) + game.advance_action(tics=10, update_state=True) + game.advance_action(tics=1) + + +def test_advance_action(): + game = _init_game() + + # advance_action() without set_action() + game.advance_action() + + # advance_action() with update_state argument set to False + prev_tic = game.get_state().tic + tics_to_advance = 10 + game.advance_action(tics_to_advance, update_state=False) + assert game.get_state().tic == prev_tic + game.advance_action() + assert game.get_state().tic == prev_tic + tics_to_advance + 1 + + if __name__ == "__main__": test_make_action_list() test_make_action_numpy() test_make_action_tuple() test_make_action_mixed_list() + test_keyword_arguments() + test_advance_action() diff --git a/tests/wheels_test_dockerfiles/apt-based.Dockerfile b/tests/wheels_test_dockerfiles/apt-based.Dockerfile index 74d5e195f..d76287529 100644 --- a/tests/wheels_test_dockerfiles/apt-based.Dockerfile +++ b/tests/wheels_test_dockerfiles/apt-based.Dockerfile @@ -6,7 +6,7 @@ ENV TZ=Europe/Warsaw WORKDIR /vizdoom # Install Python and pip -RUN apt update && apt install -y python3-dev python3-pip +RUN apt update && apt install -y python3-dev python3-pip libopenal1 COPY . ./ CMD ["bash", "./scripts/install_and_test_wheel.sh"] diff --git a/tests/wheels_test_dockerfiles/conda-based.Dockerfile b/tests/wheels_test_dockerfiles/conda-based.Dockerfile index 0937512c5..a568a62af 100644 --- a/tests/wheels_test_dockerfiles/conda-based.Dockerfile +++ b/tests/wheels_test_dockerfiles/conda-based.Dockerfile @@ -2,5 +2,7 @@ FROM continuumio/miniconda3:latest WORKDIR /vizdoom +RUN conda install -y -c openal-soft + COPY . ./ CMD ["bash", "./scripts/install_and_test_wheel.sh"] diff --git a/tests/wheels_test_dockerfiles/dnf-based.Dockerfile b/tests/wheels_test_dockerfiles/dnf-based.Dockerfile index 924c2e9b1..ec5323fc2 100644 --- a/tests/wheels_test_dockerfiles/dnf-based.Dockerfile +++ b/tests/wheels_test_dockerfiles/dnf-based.Dockerfile @@ -3,7 +3,7 @@ FROM fedora:latest WORKDIR /vizdoom # Install Python and pip -RUN dnf update -y && dnf clean all && dnf install -y python3-devel python3-pip +RUN dnf update -y && dnf clean all && dnf install -y python3-devel python3-pip openal-soft COPY . ./ CMD ["bash", "./scripts/install_and_test_wheel.sh"] From 7036ee8a53c279e69e5e52c562f583f21f850575 Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Mon, 11 Dec 2023 18:20:52 +0100 Subject: [PATCH 5/9] Update the docs --- docs/api/cpp/doomGame.md | 84 +++++-- src/lib_python/ViZDoomGamePython.cpp | 4 +- src/lib_python/ViZDoomMethodsDocstrings.h | 273 +++++++++++++++++----- 3 files changed, 277 insertions(+), 84 deletions(-) diff --git a/docs/api/cpp/doomGame.md b/docs/api/cpp/doomGame.md index 2a2993c14..b6a8a3581 100644 --- a/docs/api/cpp/doomGame.md +++ b/docs/api/cpp/doomGame.md @@ -57,10 +57,10 @@ Then the rest of the players must also call this method to start a new episode. Added in 1.1.0 -Replays a recorded episode from the given file using the perspective of the specified player. -Players are numbered from 1, `player` equal to 0 results in replaying the demo using the perspective of the default player in the recording file. +Replays the recorded episode from the given file using the perspective of the specified player. +Players are numbered from 1, If `player` is equal to 0, the episode will be replayed using the perspective of the default player in the recording file. After calling this method, the first state from the replay will be available. -All rewards, variables, and states are available during the replaying episode. +All rewards, variables, and states are available when replaying the episode. See also: - [examples/python/record_episodes.py](https://github.com/Farama-Foundation/ViZDoom/tree/master/examples/python/record_episodes.py) @@ -74,7 +74,7 @@ See also: | :-- | :-- | | Python | `is_running() -> bool` | -Checks if the ViZDoom game instance is running. +Checks if the controlled game instance is running. --- @@ -110,7 +110,7 @@ Checks if the game is in recording mode. Added in 1.1.5 -Checks if the game is in replaying mode. +Checks if the game is in replay mode. --- @@ -121,7 +121,7 @@ Checks if the game is in replaying mode. | Python | `set_action(actions: list | tuple | ndarray [float]) -> None` | Sets the player's action for the next tics. -Each value corresponds to a button specified with [`addAvailableButton`](#addavailablebutton) method +Each value corresponds to a button previosuly specified with [`addAvailableButton`](#addavailablebutton), or [`setAvailableButtons`](#setavailablebuttons) methods, or in the configuration file (in order of appearance). @@ -132,7 +132,7 @@ or in the configuration file (in order of appearance). | :-- | :-- | | Python | `advance_action(tics: int = 1, updateState: bool = True) -> None` | -Processes a specified number of tics. If `updateState` is set, +Processes the specified number of tics. If `updateState` is set, the state will be updated after the last processed tic and a new reward will be calculated. To get the new state, use `getState` and to get the new reward use `getLastReward`. If `updateState` is not set, the state will not be updated. @@ -145,8 +145,8 @@ If `updateState` is not set, the state will not be updated. | :-- | :-- | | Python | `make_action(actions: list | tuple | ndarray [float], tics: int = 1) -> float` | -Method combining usability of [`setAction`](#setaction), [`advanceAction`](#advanceaction) and [`getLastReward`](#getlastreward). -Sets the player's action for the next tics, processes a specified number of tics, +This method combines functionality of [`setAction`](#setaction), [`advanceAction`](#advanceaction) and [`getLastReward`](#getlastreward). +Sets the player's action for the next tics, processes the specified number of tics, updates the state and calculates a new reward, which is returned. @@ -314,10 +314,12 @@ See also: | C++ | `void setAvailableButtons(std::vector