summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/ale-py/default.nix
blob: 3cbf53d33cdfca1cf445b13eedcce68e727cab83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{
  lib,
  stdenv,
  buildPythonPackage,
  fetchFromGitHub,

  # build-system
  cmake,
  ninja,
  pybind11,
  setuptools,

  # buildInputs
  SDL2,
  opencv,
  zlib,

  # dependencies
  importlib-resources,
  numpy,
  typing-extensions,
  jax,

  # tests
  gymnasium,
  opencv-python,
  pytestCheckHook,

  # Whether to enable recently added vector environments:
  # https://github.com/Farama-Foundation/Arcade-Learning-Environment/blob/v0.11.0/docs/vector-environment.md
  # FIXME: Disabled by default as it mysteriously causes stable-baselines3's tests to hang indefinitely.
  withVectorEnv ? false,
}:

buildPythonPackage rec {
  pname = "ale-py";
  version = "0.11.2";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "Farama-Foundation";
    repo = "Arcade-Learning-Environment";
    tag = "v${version}";
    hash = "sha256-4IkjW8HX21uBEHFtb3qETxco6FfDMgLbG1BDHWwvn58=";
  };

  build-system = [
    cmake
    ninja
    pybind11
    setuptools
  ];

  buildInputs = [
    SDL2
    zlib
  ]
  ++ lib.optionals withVectorEnv [
    opencv
  ];

  dependencies = [
    gymnasium
    importlib-resources
    numpy
    typing-extensions
  ]
  ++ lib.optionals stdenv.hostPlatform.isLinux [
    jax
  ];

  postPatch =
    # Relax the pybind11 version
    ''
      substituteInPlace src/ale/python/CMakeLists.txt \
        --replace-fail \
          'find_package(pybind11 ''${PYBIND11_VER} QUIET)' \
          'find_package(pybind11 QUIET)'
    ''
    + lib.optionalString (!withVectorEnv) ''
      substituteInPlace setup.py \
        --replace-fail \
          "-DBUILD_VECTOR_LIB=ON" \
          "-DBUILD_VECTOR_LIB=OFF"
    '';

  dontUseCmakeConfigure = true;

  pythonImportsCheck = [ "ale_py" ];

  doCheck = false;

  nativeCheckInputs = [
    gymnasium
    pytestCheckHook
  ]
  + lib.optionals withVectorEnv [
    opencv-python
  ];

  disabledTests = [
    # Fatal Python error: Aborted
    # line 414 in test_display_screen
    "test_display_screen"

    # test_atari_env.py tests fail on the majority of the environments because the ROM are missing.
    # The user is expected to manually download the roms:
    # https://github.com/Farama-Foundation/Arcade-Learning-Environment/blob/v0.9.0/docs/faq.md#i-downloaded-ale-and-i-installed-it-successfully-but-i-cannot-find-any-rom-file-at-roms-do-i-have-to-get-them-somewhere-else
    "test_check_env"
    "test_reset_step_shapes"
    "test_rollout_consistency"
    "test_sound_obs"
  ];

  meta = {
    description = "Simple framework that allows researchers and hobbyists to develop AI agents for Atari 2600 games";
    mainProgram = "ale-import-roms";
    homepage = "https://github.com/mgbellemare/Arcade-Learning-Environment";
    changelog = "https://github.com/Farama-Foundation/Arcade-Learning-Environment/releases/tag/v${version}";
    license = lib.licenses.gpl2;
    maintainers = with lib.maintainers; [ billhuang ];
    badPlatforms = [
      # FAILED: src/ale/libale.a
      # /bin/sh: CMAKE_CXX_COMPILER_AR-NOTFOUND: command not found
      lib.systems.inspect.patterns.isDarwin
    ];
  };
}