Multiclass-interface 1.19__tar.gz → 1.21__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {multiclass_interface-1.19 → multiclass_interface-1.21}/.gitlab-ci.yml +3 -3
- {multiclass_interface-1.19 → multiclass_interface-1.21/Multiclass_interface.egg-info}/PKG-INFO +1 -1
- multiclass_interface-1.21/Multiclass_interface.egg-info/scm_version.json +8 -0
- {multiclass_interface-1.19/Multiclass_interface.egg-info → multiclass_interface-1.21}/PKG-INFO +1 -1
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/mpi_interface.py +60 -31
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/tests/my_test_cls.py +0 -1
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/tests/test_mpi.py +64 -39
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/version.py +3 -3
- multiclass_interface-1.19/Multiclass_interface.egg-info/scm_version.json +0 -8
- {multiclass_interface-1.19 → multiclass_interface-1.21}/.gitignore +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/LICENSE +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/Multiclass_interface.egg-info/SOURCES.txt +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/Multiclass_interface.egg-info/dependency_links.txt +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/Multiclass_interface.egg-info/requires.txt +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/Multiclass_interface.egg-info/scm_file_list.json +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/Multiclass_interface.egg-info/top_level.txt +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/README.md +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/__init__.py +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/multi_object_list.py +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/multiprocess_interface.py +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/tests/__init__.py +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/tests/test_multiclass_list.py +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/tests/test_multiprocessinterface.py +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/pyproject.toml +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/sequence_diagrams.md +0 -0
- {multiclass_interface-1.19 → multiclass_interface-1.21}/setup.cfg +0 -0
|
@@ -15,7 +15,7 @@ test_mpitest_openmpi:
|
|
|
15
15
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
16
16
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
17
17
|
tags:
|
|
18
|
-
-
|
|
18
|
+
- docker,ubuntu,linux,shared
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
# ===== Check code style =====
|
|
@@ -26,7 +26,7 @@ check_code_style: # name the job what we like
|
|
|
26
26
|
- pip install -e . --user
|
|
27
27
|
- pycodestyle --ignore=E501,W504,E741 multiclass_interface
|
|
28
28
|
tags: # only runners with this tag can do the job [3]
|
|
29
|
-
-
|
|
29
|
+
- docker,ubuntu,linux,shared
|
|
30
30
|
rules:
|
|
31
31
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
32
32
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
@@ -52,4 +52,4 @@ pypi_linux:
|
|
|
52
52
|
allow_failure: true
|
|
53
53
|
- when: never
|
|
54
54
|
tags:
|
|
55
|
-
-
|
|
55
|
+
- docker,ubuntu,linux,shared
|
{multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/mpi_interface.py
RENAMED
|
@@ -7,6 +7,7 @@ import shutil
|
|
|
7
7
|
import sys
|
|
8
8
|
import traceback
|
|
9
9
|
from contextlib import contextmanager
|
|
10
|
+
import contextlib
|
|
10
11
|
|
|
11
12
|
comm = None
|
|
12
13
|
size = 1
|
|
@@ -50,15 +51,17 @@ COLLECTIVE_MPI = True # rank0 acts as a single point of contact (scatters comma
|
|
|
50
51
|
def main_run(f, *args, **kwargs):
|
|
51
52
|
if main:
|
|
52
53
|
r = f(*args, **kwargs)
|
|
53
|
-
if COLLECTIVE_MPI:
|
|
54
|
-
|
|
54
|
+
if mpi and COLLECTIVE_MPI:
|
|
55
|
+
r = r[0]
|
|
55
56
|
else:
|
|
56
57
|
try:
|
|
57
|
-
f(*args, **kwargs)
|
|
58
|
-
except
|
|
58
|
+
f(*args, **kwargs) # needed if main_run calls another main_run function
|
|
59
|
+
except Exception:
|
|
59
60
|
pass
|
|
60
61
|
r = None
|
|
61
|
-
|
|
62
|
+
if mpi and not COLLECTIVE_MPI:
|
|
63
|
+
r = comm.bcast(r)
|
|
64
|
+
return r
|
|
62
65
|
|
|
63
66
|
|
|
64
67
|
class MPIClassInterface():
|
|
@@ -241,26 +244,51 @@ class SubsetMPIClassInterface(MPIClassInterface):
|
|
|
241
244
|
raise Exception('Cannot close SubsetMPIClassInterface. Please close all instances at once')
|
|
242
245
|
|
|
243
246
|
|
|
244
|
-
def barrier_print(s):
|
|
245
|
-
from mpi4py import MPI
|
|
246
|
-
|
|
247
|
-
newData = comm.gather(rank, root=0)
|
|
248
|
-
newData = comm.gather(rank, root=0)
|
|
249
|
-
import sys
|
|
247
|
+
def barrier_print(s, exit=1):
|
|
250
248
|
sys.stdout.flush()
|
|
249
|
+
if mpi:
|
|
250
|
+
N = 3
|
|
251
|
+
N_lst = np.arange(1, N + 1)
|
|
252
|
+
err_lst = []
|
|
253
|
+
|
|
254
|
+
# check bcast not behind
|
|
255
|
+
for i in N_lst:
|
|
256
|
+
r = comm.bcast(123 + i)
|
|
257
|
+
if r != 123 + N:
|
|
258
|
+
err_lst.append(f"Rank {rank} is {122 + N - r} bcast behind")
|
|
259
|
+
|
|
260
|
+
c = comm.gather(r)
|
|
261
|
+
|
|
262
|
+
if rank == 0:
|
|
263
|
+
c = np.array(c)
|
|
264
|
+
i = np.where(c != 123 + N)[0]
|
|
265
|
+
if len(i):
|
|
266
|
+
c[:] = 0
|
|
267
|
+
else:
|
|
268
|
+
c = 0
|
|
269
|
+
|
|
270
|
+
r = comm.scatter(c)
|
|
271
|
+
|
|
272
|
+
if r < (123 + N):
|
|
273
|
+
if exit == 'error':
|
|
274
|
+
raise Exception("\n".join(err_lst))
|
|
275
|
+
else:
|
|
276
|
+
if len(err_lst):
|
|
277
|
+
print("########", "\n".join(err_lst), flush=True)
|
|
278
|
+
sys.exit(exit)
|
|
279
|
+
|
|
251
280
|
if rank == 0:
|
|
252
|
-
print("
|
|
281
|
+
print("########", s, flush=True)
|
|
253
282
|
|
|
254
283
|
|
|
255
|
-
def
|
|
256
|
-
# Decorator to broadcast the return value of a function as a
|
|
257
|
-
# collect the return value from each mpiworker and broadcast the full list with wt as first dimension to all workers
|
|
284
|
+
def bcast_function_result_all2all(f):
|
|
285
|
+
# Decorator to broadcast the return value of a function as a list, [rank0_result, rank1_result, ...],
|
|
258
286
|
def wrapper(*args, **kwargs):
|
|
259
287
|
if mpi:
|
|
260
288
|
try:
|
|
261
289
|
v = f(*args, **kwargs)
|
|
262
|
-
if not isinstance(v, list):
|
|
263
|
-
|
|
290
|
+
# if not isinstance(v, list):
|
|
291
|
+
# v = [v]
|
|
264
292
|
v = v[0]
|
|
265
293
|
except ChildProcessError:
|
|
266
294
|
v = None
|
|
@@ -277,6 +305,13 @@ def bcast_function_result(f):
|
|
|
277
305
|
return wrapper
|
|
278
306
|
|
|
279
307
|
|
|
308
|
+
def bcast_function_result_main2all(f):
|
|
309
|
+
# Decorator to broadcast the return value of a function run by rank=0 to all mpi workers
|
|
310
|
+
def wrapper(*args, **kwargs):
|
|
311
|
+
return main_run(f, *args, **kwargs)
|
|
312
|
+
return wrapper
|
|
313
|
+
|
|
314
|
+
|
|
280
315
|
def mpi_run_test(n, cwd='.', mpirun_cmd='mpirun'):
|
|
281
316
|
if callable(n):
|
|
282
317
|
return mpi_run_test(n=4)(n)
|
|
@@ -290,21 +325,15 @@ def mpi_run_test(n, cwd='.', mpirun_cmd='mpirun'):
|
|
|
290
325
|
name = test_function.__name__
|
|
291
326
|
|
|
292
327
|
def wrap(mpirun=False):
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if mpirun:
|
|
296
|
-
os.chdir(cwd)
|
|
328
|
+
if mpirun:
|
|
329
|
+
with contextlib.chdir(cwd):
|
|
297
330
|
return test_function()
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
assert os.system(cmd) == 0, name
|
|
305
|
-
|
|
306
|
-
finally:
|
|
307
|
-
os.chdir(cwd)
|
|
331
|
+
else:
|
|
332
|
+
import_path = Path(inspect.getsourcefile(test_function)).relative_to(os.getcwd()).as_posix()
|
|
333
|
+
import_path = import_path[:-3].replace('/', '.')
|
|
334
|
+
cmd = f'''{mpirun_cmd} -n {n} {sys.executable} -c "from {import_path} import {name}; {name}(mpirun=True)"'''
|
|
335
|
+
print(f"cd {os.getcwd()} && {cmd}", flush=True)
|
|
336
|
+
assert os.system(cmd) == 0, name
|
|
308
337
|
|
|
309
338
|
wrap.__name__ = name
|
|
310
339
|
return wrap
|
{multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/tests/test_mpi.py
RENAMED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
from contextlib import redirect_stdout
|
|
2
|
+
import io
|
|
3
|
+
from multiclass_interface import mpi_interface
|
|
4
|
+
from multiclass_interface.mpi_interface import MPIClassInterface, barrier_print
|
|
5
|
+
from multiclass_interface.mpi_interface import mpi_run_test
|
|
6
|
+
from multiclass_interface.multi_object_list import MultiClassInterface
|
|
7
|
+
from multiclass_interface.multiprocess_interface import ProcessClass
|
|
8
|
+
from multiclass_interface.tests.my_test_cls import MyTest
|
|
9
|
+
from numpy import testing as npt
|
|
10
|
+
import numpy as np
|
|
1
11
|
import os
|
|
12
|
+
import pytest
|
|
2
13
|
import sys
|
|
3
14
|
import time
|
|
4
15
|
import traceback
|
|
5
|
-
from numpy import testing as npt
|
|
6
|
-
import pytest
|
|
7
|
-
|
|
8
|
-
from multiclass_interface.mpi_interface import MPIClassInterface
|
|
9
|
-
from multiclass_interface.multiprocess_interface import ProcessClass
|
|
10
|
-
import numpy as np
|
|
11
|
-
from multiclass_interface.tests.my_test_cls import MyTest
|
|
12
|
-
from multiclass_interface import mpi_interface
|
|
13
|
-
from multiclass_interface.mpi_interface import mpi_run_test
|
|
14
|
-
from multiclass_interface.multi_object_list import MultiClassInterface
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
def mpirun(f):
|
|
@@ -119,11 +120,17 @@ def test_non_collective_mpi2():
|
|
|
119
120
|
N = 3
|
|
120
121
|
with MPIClassInterface(MyTest, [(i + 10,) for i in range(N)]) as m:
|
|
121
122
|
|
|
122
|
-
id_lst = mpi_interface.
|
|
123
|
+
id_lst = mpi_interface.bcast_function_result_all2all(lambda: m.get_id())()
|
|
123
124
|
assert id_lst == [10, 11, 12, None], id_lst
|
|
124
|
-
id_lst = mpi_interface.
|
|
125
|
+
id_lst = mpi_interface.bcast_function_result_main2all(lambda: m.get_id())()
|
|
126
|
+
assert id_lst == [10], id_lst
|
|
127
|
+
|
|
128
|
+
id_lst = mpi_interface.bcast_function_result_all2all(lambda: m.return_input(['a', 'b', 'c']))()
|
|
125
129
|
assert id_lst == ["10 got: ('a',) and {}", "11 got: ('b',) and {}", "12 got: ('c',) and {}", None], id_lst
|
|
126
130
|
|
|
131
|
+
id_lst = mpi_interface.bcast_function_result_main2all(lambda: m.return_input(['a', 'b', 'c']))()
|
|
132
|
+
assert id_lst == ["10 got: ('a',) and {}"], id_lst
|
|
133
|
+
|
|
127
134
|
mpi_interface.barrier_print('hello world')
|
|
128
135
|
try:
|
|
129
136
|
assert m.get_id()[0] == rank + 10, m.get_id()
|
|
@@ -149,36 +156,20 @@ def test_non_collective_mpi2():
|
|
|
149
156
|
def test_bcast_function_result_mci(N):
|
|
150
157
|
with MultiClassInterface(MyTest, [(i + 10,) for i in range(N)]) as m:
|
|
151
158
|
|
|
152
|
-
|
|
153
|
-
assert
|
|
154
|
-
id_lst = mpi_interface.bcast_function_result(lambda: m.return_input(['a', 'b', 'c'][:N]))()
|
|
155
|
-
assert id_lst == ["10 got: ('a',) and {}", "11 got: ('b',) and {}", "12 got: ('c',) and {}"][:N], id_lst
|
|
156
|
-
|
|
157
|
-
assert mpi_interface.bcast_function_result(lambda: 0)() == [0]
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
@mpi_run_test
|
|
161
|
-
def test_bcast_function_result_mpi1():
|
|
162
|
-
mpi_interface.activate_mpi(collective_mpi=False)
|
|
163
|
-
with MPIClassInterface(MyTest, [(i + 10,) for i in range(1)]) as m:
|
|
164
|
-
id_lst = mpi_interface.bcast_function_result(lambda: m.get_id())()
|
|
165
|
-
assert id_lst == [10, None, None, None], id_lst
|
|
166
|
-
id_lst = mpi_interface.bcast_function_result(lambda: m.return_input(['a']))()
|
|
167
|
-
assert id_lst == ["10 got: ('a',) and {}", None, None, None], id_lst
|
|
168
|
-
|
|
169
|
-
assert mpi_interface.bcast_function_result(lambda: mpi_interface.rank)() == [0, 1, 2, 3]
|
|
159
|
+
r_lst = mpi_interface.bcast_function_result_all2all(lambda: m.get_id())()
|
|
160
|
+
assert r_lst == [10, 11, 12][:N], r_lst
|
|
170
161
|
|
|
162
|
+
id_lst = mpi_interface.bcast_function_result_main2all(lambda: m.get_id())()
|
|
163
|
+
# collective (all collected by rank0)
|
|
164
|
+
assert id_lst == [10, 11, 12][:N], id_lst
|
|
171
165
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
id_lst = mpi_interface.bcast_function_result(lambda: m.get_id())()
|
|
177
|
-
assert id_lst == [10, 11, 12, None], id_lst
|
|
178
|
-
id_lst = mpi_interface.bcast_function_result(lambda: m.return_input(['a', 'b', 'c']))()
|
|
179
|
-
assert id_lst == ["10 got: ('a',) and {}", "11 got: ('b',) and {}", "12 got: ('c',) and {}", None], id_lst
|
|
166
|
+
r_lst = mpi_interface.bcast_function_result_all2all(lambda: m.return_input(['a', 'b', 'c'][:N]))()
|
|
167
|
+
assert r_lst == ["10 got: ('a',) and {}", "11 got: ('b',) and {}", "12 got: ('c',) and {}"][:N], r_lst
|
|
168
|
+
r_lst = mpi_interface.bcast_function_result_main2all(lambda: m.return_input(['a', 'b', 'c'][:N]))()
|
|
169
|
+
assert r_lst == ["10 got: ('a',) and {}", "11 got: ('b',) and {}", "12 got: ('c',) and {}"][:N], r_lst
|
|
180
170
|
|
|
181
|
-
assert mpi_interface.
|
|
171
|
+
assert mpi_interface.bcast_function_result_all2all(lambda: 0)() == [0]
|
|
172
|
+
assert mpi_interface.bcast_function_result_main2all(lambda: 0)() == 0
|
|
182
173
|
|
|
183
174
|
|
|
184
175
|
@mpi_run_test(4)
|
|
@@ -255,3 +246,37 @@ def test_multiprocessinterface_tests_diff_interface():
|
|
|
255
246
|
except ChildProcessError:
|
|
256
247
|
pass
|
|
257
248
|
sys.exit(0)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
@mpi_run_test(4)
|
|
252
|
+
def test_barrier_print_ok():
|
|
253
|
+
mpi_interface.activate_mpi(collective_mpi=False)
|
|
254
|
+
with redirect_stdout(io.StringIO()) as f:
|
|
255
|
+
barrier_print('Hello World')
|
|
256
|
+
s = f.getvalue().strip()
|
|
257
|
+
if mpi_interface.main:
|
|
258
|
+
assert s == '######## Hello World', s
|
|
259
|
+
else:
|
|
260
|
+
assert s == "", s
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
@mpi_run_test(4)
|
|
264
|
+
def test_barrier_print_bcast_missing_error():
|
|
265
|
+
mpi_interface.activate_mpi(collective_mpi=False)
|
|
266
|
+
if mpi_interface.rank in [0, 2, 3]:
|
|
267
|
+
b = mpi_interface.comm.bcast('hej')
|
|
268
|
+
try:
|
|
269
|
+
barrier_print('Hello World', exit='error')
|
|
270
|
+
except Exception as e:
|
|
271
|
+
assert str(e) == {1: 'Rank 1 is 0 bcast behind'}.get(mpi_interface.rank, ''), str(e)
|
|
272
|
+
pass
|
|
273
|
+
else:
|
|
274
|
+
raise Exception('Exception not raised')
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
@mpi_run_test(4)
|
|
278
|
+
def test_barrier_print_bcast_missing_exit():
|
|
279
|
+
mpi_interface.activate_mpi(collective_mpi=False)
|
|
280
|
+
if mpi_interface.rank in [0, 2, 3]:
|
|
281
|
+
b = mpi_interface.comm.bcast('hej')
|
|
282
|
+
barrier_print('Hello World', exit=0)
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '1.
|
|
22
|
-
__version_tuple__ = version_tuple = (1,
|
|
21
|
+
__version__ = version = '1.21'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 21)
|
|
23
23
|
|
|
24
|
-
__commit_id__ = commit_id = '
|
|
24
|
+
__commit_id__ = commit_id = 'g7ab17bd08'
|
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.19 → multiclass_interface-1.21}/Multiclass_interface.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.19 → multiclass_interface-1.21}/Multiclass_interface.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.19 → multiclass_interface-1.21}/Multiclass_interface.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/multi_object_list.py
RENAMED
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.19 → multiclass_interface-1.21}/multiclass_interface/tests/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|