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 ] ++ lib.optionals (pythonOlder "3.10") [ importlib-metadata ];
66
67 pythonImportsCheck = [ "gym" ];
68
69 nativeCheckInputs = [
70 moviepy
71 opencv-python
72 pybox2d
73 pygame
74 pytestCheckHook
75 ];
76
77 disabledTests =
78 [
79 # TypeError: Converting from sequence to b2Vec2, expected int/float arguments index 0
80 "test_box_actions_out_of_bound"
81 "test_env_determinism_rollout"
82 "test_envs_pass_env_checker"
83 "test_frame_stack"
84 "test_make_autoreset_true"
85 "test_passive_checker_wrapper_warnings"
86 "test_pickle_env"
87 "test_render_modes"
88
89 # TypeError: in method 'b2RevoluteJoint___SetMotorSpeed', argument 2 of type 'float32'
90 "test_box_actions_out_of_bound"
91
92 # TypeError: exceptions must be derived from Warning, not <class 'NoneType'>
93 "test_dict_init"
94
95 # ValueError: setting an array element with a sequence.
96 # The requested array has an inhomogeneous shape after 1 dimensions.
97 # The detected shape was (2,) + inhomogeneous part
98 "test_sample_contains"
99 ]
100 ++ lib.optionals stdenv.hostPlatform.isDarwin [
101 # Fatal Python error: Aborted
102 # gym/envs/classic_control/cartpole.py", line 227 in render
103 "test_autoclose"
104 "test_call_async_vector_env"
105 "test_call_sync_vector_env"
106 "test_human_rendering"
107 "test_make_render_mode"
108 "test_order_enforcing"
109 "test_record_simple"
110 "test_record_video_reset"
111 "test_record_video_step_trigger"
112 "test_record_video_using_default_trigger"
113 "test_record_video_within_vecto"
114 "test_text_envs"
115 ];
116
117 disabledTestPaths = lib.optionals stdenv.hostPlatform.isDarwin [
118 # Fatal Python error: Aborted
119 # gym/utils/play.py", line 62 in __init__
120 "tests/utils/test_play.py"
121 ];
122
123 meta = {
124 description = "Toolkit for developing and comparing your reinforcement learning agents";
125 homepage = "https://www.gymlibrary.dev/";
126 license = lib.licenses.mit;
127 maintainers = with lib.maintainers; [ GaetanLepage ];
128 };
129}