Skip to content

Commit 193af0f

Browse files
committed
Add platform testing script.
TODO: fix pool support in future python versions (>3.7)
1 parent 72fb51a commit 193af0f

File tree

8 files changed

+61
-18
lines changed

8 files changed

+61
-18
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pipeline {
5252
sh 'pip install .'
5353
sh 'pip install ./test_lib/multiagent-particle-envs/'
5454
sh 'pip install "gym[atari, box2d, classic_control]"'
55-
sh 'pip install mock pytest==6.0.0 pytest-cov==2.10.0 allure-pytest==2.8.16 pytest-xvfb==2.0.0 pytest-html==1.22.1 pytest-repeat==0.8.0'
55+
sh 'pip install mock pytest==6.0.1 pytest-cov==2.10.0 allure-pytest==2.8.16 pytest-xvfb==2.0.0 pytest-html==1.22.1 pytest-repeat==0.8.0'
5656
// This line must be included, otherwise matplotlib will
5757
// segfault when it tries to build the font cache.
5858
sh "python3 -c 'import matplotlib.pyplot as plt'"

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,16 @@ conda activate some_env
140140
pip install machin
141141
```
142142

143-
**Note**: Currently only a fraction of all functions is supported on Windows, to test whether
144-
the code is running correctly, you can run the corresponding test script in the root directory:
143+
**Note**: Currently only a fraction of all functions is supported on platforms other than linux
144+
(mainly distributed algorithms), to test whether the code is running correctly, you can run the
145+
corresponding test script for your platform in the root directory:
145146
```
146147
run_win_test.bat
147-
run_lunux_test.sh
148+
run_linux_test.sh
149+
run_macos_test.sh
148150
```
151+
Some errors may occur due to incorrect setup of libraries, make sure you have installed `graphviz`
152+
etc.
149153

150154
### Contributing
151155
---

machin/parallel/pool.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import sys
3+
import warnings
24
import threading
35
import multiprocessing.pool as pool
46
from multiprocessing.pool import TERMINATE
@@ -8,6 +10,9 @@
810
from .pickle import dumps, loads
911
from .queue import SimpleQueue, MultiP2PQueue
1012

13+
# TODO: fix pool support pools in python 3.8 etc.
14+
# Since future implementations are different.
15+
1116

1217
def proxy_caller(*input_):
1318
"""
@@ -53,6 +58,10 @@ class Pool(pool.Pool):
5358
2. Ability to select the tensor serialize scheme.
5459
"""
5560

61+
def Process(self, *args, **kwds):
62+
# Prevent future versions of pool from changing this implementation.
63+
return self._ctx.Process(*args, **kwds)
64+
5665
def __init__(
5766
self,
5867
processes=None,
@@ -101,19 +110,27 @@ def __init__(
101110
processes = os.cpu_count() or 1
102111
if processes < 1:
103112
raise ValueError("Number of processes must be at least 1")
104-
self._processes = processes
105-
106-
self._is_recursive = is_recursive
107-
self._is_daemon = is_daemon
108-
self._is_copy_tensor = is_copy_tensor
109-
self._caller = proxy_caller
110113

111114
context = get_context("spawn")
112-
if not is_copy_tensor:
115+
if sys.platform.startswith("linux") and not is_copy_tensor:
113116
if share_method not in ("cpu", "cuda"):
114117
raise RuntimeError(f'Invalid share method: "{share_method}"')
115118
if share_method == "cpu":
116119
context = get_context("fork")
120+
else:
121+
warnings.warn(
122+
"Sharing but not copying a tensor is not supported "
123+
"on platforms other than linux."
124+
)
125+
is_copy_tensor = True
126+
127+
self._ctx = context
128+
self._processes = processes
129+
130+
self._is_recursive = is_recursive
131+
self._is_daemon = is_daemon
132+
self._is_copy_tensor = is_copy_tensor
133+
self._caller = proxy_caller
117134

118135
super().__init__(
119136
processes=processes,

run_linux_test.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash
2+
# if you are using any non-standard python 3 installation (>= 3.6)
3+
# please replace first three python with your absolute path
24
python --version
35
python -m pip install virtualenv
4-
virtualenv venv
6+
python -m virtualenv venv
57
source venv/bin/activate
68
pip install .
79
pip install ./test_lib/multiagent-particle-envs/
8-
pip install mock pytest==6.0.0 pytest-html==1.22.1 pytest-repeat==0.8.0
9-
python -m pytest -s --assert=plain -k "not full_train" --html=test_results/test_api.html --self-contained-html ./test/
10+
pip install mock pytest==6.0.1 pytest-html==1.22.1 pytest-repeat==0.8.0
11+
python -m pytest -s --assert=plain -k "not full_train" --html=test_api.html --self-contained-html ./test/

run_macos_test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# if you are using any non-standard python 3 installation (>= 3.6)
3+
# please replace first three python with your absolute path
4+
python --version
5+
python -m pip install virtualenv
6+
python -m virtualenv venv
7+
source venv/bin/activate
8+
pip install .
9+
pip install ./test_lib/multiagent-particle-envs/
10+
pip install mock pytest==6.0.1 pytest-html==1.22.1 pytest-repeat==0.8.0
11+
python -m pytest -s --assert=plain -k "not full_train" --html=test_api.html --self-contained-html ./test/

run_win_test.bat

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
@ECHO OFF
2+
REM if you are using any non-standard python 3 installation (>= 3.6)
3+
REM please replace first three python with your absolute path
4+
25
python --version
36
python -m pip install virtualenv
4-
virtualenv venv
5-
.\venv\Scripts\activate
7+
python -m virtualenv venv
8+
call .\venv\Scripts\activate
69
pip install .
710
pip install .\test_lib\multiagent-particle-envs\
8-
pip install mock pytest==6.0.0 pytest-html==1.22.1 pytest-repeat==0.8.0
9-
python -m pytest -s --assert=plain -k "not full_train" --html=test_results\test_api.html --self-contained-html .\test\
11+
pip install mock pytest==6.0.1 pytest-html==1.22.1 pytest-repeat==0.8.0
12+
python -m pytest -s --assert=plain -k "not full_train" --html=test_api.html --self-contained-html .\test\
13+
pause

test/parallel/test_pickle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from machin.parallel.process import Process
33
import torch as t
44
from multiprocessing import Pipe, get_context
5+
from test.util_platforms import linux_only
56

67

78
def subproc_test_dumps_copy_tensor(pipe):
@@ -25,6 +26,7 @@ def subproc_test_dumps_not_copy_tensor(pipe):
2526
pipe.send(dumps(tensor, copy_tensor=False))
2627

2728

29+
@linux_only
2830
def test_dumps_not_copy_tensor():
2931
pipe_0, pipe_1 = Pipe(duplex=True)
3032
ctx = get_context("fork")
@@ -49,6 +51,7 @@ def local_func():
4951
pipe.send(dumps(local_func, copy_tensor=False))
5052

5153

54+
@linux_only
5255
def test_dumps_local_func():
5356
pipe_0, pipe_1 = Pipe(duplex=True)
5457
ctx = get_context("fork")

test/parallel/test_pool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import torch as t
99

1010
from test.util_fixtures import *
11+
from test.util_fixtures import linux_only
1112

1213
# enable pool logging
1314
# log_to_stderr(DEBUG)
@@ -163,6 +164,7 @@ def test_starmap_async(self):
163164
# pool.join()
164165
# logger.info("Pool 2 joined.")
165166

167+
@linux_only
166168
def test_cpu_shared_tensor(self):
167169
x = [t.ones([10]) * i for i in range(5)]
168170
for xx in x:

0 commit comments

Comments
 (0)