1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 setuptools,
9
10 # dependencies
11 cloudpickle,
12 numpy,
13 gym-notices,
14 importlib-metadata,
15 pythonOlder,
16
17 # tests
18 moviepy,
19 pybox2d,
20 pygame,
21 pytestCheckHook,
22 opencv-python,
23}:
24
25buildPythonPackage rec {
26 pname = "gym";
27 version = "0.26.2";
28 pyproject = true;
29
30 src = fetchFromGitHub {
31 owner = "openai";
32 repo = "gym";
33 tag = version;
34 hash = "sha256-uJgm8l1SxIRC5PV6BIH/ht/1ucGT5UaUhkFMdusejgA=";
35 };
36
37 # Fix numpy2 compatibility
38 postPatch = ''
39 substituteInPlace gym/envs/classic_control/acrobot.py \
40 --replace-fail "np.float_" "np.float64"
41
42 substituteInPlace gym/utils/passive_env_checker.py \
43 --replace-fail "np.bool8" "np.bool"
44
45 substituteInPlace tests/envs/test_action_dim_check.py \
46 --replace-fail "np.cast[dtype](OOB_VALUE)" "np.asarray(OOB_VALUE, dtype=dtype)" \
47 --replace-fail "np.alltrue" "np.all"
48
49 substituteInPlace tests/spaces/test_box.py \
50 --replace-fail "np.bool8" "np.bool" \
51 --replace-fail "np.complex_" "np.complex128"
52
53 substituteInPlace tests/wrappers/test_record_episode_statistics.py \
54 --replace-fail "np.alltrue" "np.all"
55 '';
56
57 build-system = [
58 setuptools
59 ];
60
61 dependencies = [
62 cloudpickle
63 numpy
64 gym-notices
65 ]
66 ++ lib.optionals (pythonOlder "3.10") [ importlib-metadata ];
67
68 pythonImportsCheck = [ "gym" ];
69
70 nativeCheckInputs = [
71 moviepy
72 opencv-python
73 pybox2d
74 pygame
75 pytestCheckHook
76 ];
77
78 preCheck = ''
79 export SDL_VIDEODRIVER=dummy
80 '';
81
82 disabledTests = [
83 # TypeError: Converting from sequence to b2Vec2, expected int/float arguments index 0
84 "test_box_actions_out_of_bound"
85 "test_env_determinism_rollout"
86 "test_envs_pass_env_checker"
87 "test_frame_stack"
88 "test_make_autoreset_true"
89 "test_passive_checker_wrapper_warnings"
90 "test_pickle_env"
91 "test_render_modes"
92
93 # TypeError: in method 'b2RevoluteJoint___SetMotorSpeed', argument 2 of type 'float32'
94 "test_box_actions_out_of_bound"
95
96 # TypeError: exceptions must be derived from Warning, not <class 'NoneType'>
97 "test_dict_init"
98
99 # ValueError: setting an array element with a sequence.
100 # The requested array has an inhomogeneous shape after 1 dimensions.
101 # The detected shape was (2,) + inhomogeneous part
102 "test_sample_contains"
103 ]
104 ++ lib.optionals stdenv.hostPlatform.isDarwin [
105 # Fatal Python error: Aborted
106 # gym/envs/classic_control/cartpole.py", line 227 in render
107 "test_autoclose"
108 "test_call_async_vector_env"
109 "test_call_sync_vector_env"
110 "test_human_rendering"
111 "test_make_render_mode"
112 "test_order_enforcing"
113 "test_record_simple"
114 "test_record_video_reset"
115 "test_record_video_step_trigger"
116 "test_record_video_using_default_trigger"
117 "test_record_video_within_vecto"
118 "test_text_envs"
119 ];
120
121 disabledTestPaths = lib.optionals stdenv.hostPlatform.isDarwin [
122 # Fatal Python error: Aborted
123 # gym/utils/play.py", line 62 in __init__
124 "tests/utils/test_play.py"
125 ];
126
127 meta = {
128 description = "Toolkit for developing and comparing your reinforcement learning agents";
129 homepage = "https://www.gymlibrary.dev/";
130 license = lib.licenses.mit;
131 maintainers = with lib.maintainers; [ GaetanLepage ];
132 };
133}