summaryrefslogtreecommitdiffstats
path: root/pkgs/development/python-modules/ale-py/default.nix
blob: 0711d50e8663b511471de12465918478490ab4f2 (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
{
  lib,
  stdenv,
  config,
  buildPythonPackage,
  fetchFromGitHub,

  # build-system
  cmake,
  ninja,
  nanobind,
  scikit-build-core,
  # linux-only
  jax,

  # buildInputs
  SDL2,
  opencv,
  zlib,

  # nativeBuildInputs
  cudaPackages,

  # dependencies
  numpy,

  # tests
  chex,
  gymnasium,
  pytestCheckHook,
}:

buildPythonPackage (finalAttrs: {
  pname = "ale-py";
  version = "0.12.1";
  pyproject = true;
  __structuredAttrs = true;

  src = fetchFromGitHub {
    owner = "Farama-Foundation";
    repo = "Arcade-Learning-Environment";
    tag = "v${finalAttrs.version}";
    hash = "sha256-1oIF45+GZFWuRzXR5Hqh60yc1DZYAlXpsGgf3WiouQE=";
  };

  # disable lto on darwin, cmake cannot find llvm-ar
  postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
    substituteInPlace src/ale/CMakeLists.txt \
      --replace-fail \
        'set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)' \
        'set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)'
  '';

  build-system = [
    cmake
    ninja
    scikit-build-core
    nanobind
  ]
  ++ lib.optionals stdenv.hostPlatform.isLinux [
    jax
  ];

  nativeBuildInputs = lib.optionals config.cudaSupport [
    # Required by opencv's cmake
    cudaPackages.cuda_nvcc
  ];

  dontUseCmakeConfigure = true;

  buildInputs = [
    SDL2
    zlib
    opencv
  ];

  dependencies = [
    numpy
  ];

  pythonImportsCheck = [ "ale_py" ];

  nativeCheckInputs = [
    chex
    gymnasium
    pytestCheckHook
  ];

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

    # Most Atari tests fail 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
    "TestVectorEnv"
    "test_check_env"
    "test_clone_pickle_restore_new_env"
    "test_clone_restore"
    "test_continuous_actions"
    "test_determinism"
    "test_gym_keys_to_action"
    "test_jit"
    "test_obs_params"
    "test_reset_step_shapes"
    "test_rollout_consistency"
    "test_seeding"
    "test_sound_obs"
    "test_state_serialize_roundtrip"
  ];

  disabledTestPaths = [
    "tests/python/test_atari_vector_xla.py"
  ];

  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/${finalAttrs.src.tag}";
    license = lib.licenses.gpl2;
    maintainers = with lib.maintainers; [ billhuang ];
  };
})