Multiclass-interface 1.20__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.20 → 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.20/Multiclass_interface.egg-info → multiclass_interface-1.21}/PKG-INFO +1 -1
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/mpi_interface.py +51 -17
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/tests/my_test_cls.py +0 -1
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/tests/test_mpi.py +64 -39
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/version.py +3 -3
- multiclass_interface-1.20/Multiclass_interface.egg-info/scm_version.json +0 -8
- {multiclass_interface-1.20 → multiclass_interface-1.21}/.gitignore +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/.gitlab-ci.yml +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/LICENSE +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/Multiclass_interface.egg-info/SOURCES.txt +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/Multiclass_interface.egg-info/dependency_links.txt +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/Multiclass_interface.egg-info/requires.txt +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/Multiclass_interface.egg-info/scm_file_list.json +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/Multiclass_interface.egg-info/top_level.txt +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/README.md +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/__init__.py +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/multi_object_list.py +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/multiprocess_interface.py +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/tests/__init__.py +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/tests/test_multiclass_list.py +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/tests/test_multiprocessinterface.py +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/pyproject.toml +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/sequence_diagrams.md +0 -0
- {multiclass_interface-1.20 → multiclass_interface-1.21}/setup.cfg +0 -0
{multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/mpi_interface.py
RENAMED
|
@@ -51,15 +51,17 @@ COLLECTIVE_MPI = True # rank0 acts as a single point of contact (scatters comma
|
|
|
51
51
|
def main_run(f, *args, **kwargs):
|
|
52
52
|
if main:
|
|
53
53
|
r = f(*args, **kwargs)
|
|
54
|
-
if COLLECTIVE_MPI:
|
|
55
|
-
|
|
54
|
+
if mpi and COLLECTIVE_MPI:
|
|
55
|
+
r = r[0]
|
|
56
56
|
else:
|
|
57
57
|
try:
|
|
58
|
-
f(*args, **kwargs)
|
|
59
|
-
except
|
|
58
|
+
f(*args, **kwargs) # needed if main_run calls another main_run function
|
|
59
|
+
except Exception:
|
|
60
60
|
pass
|
|
61
61
|
r = None
|
|
62
|
-
|
|
62
|
+
if mpi and not COLLECTIVE_MPI:
|
|
63
|
+
r = comm.bcast(r)
|
|
64
|
+
return r
|
|
63
65
|
|
|
64
66
|
|
|
65
67
|
class MPIClassInterface():
|
|
@@ -242,26 +244,51 @@ class SubsetMPIClassInterface(MPIClassInterface):
|
|
|
242
244
|
raise Exception('Cannot close SubsetMPIClassInterface. Please close all instances at once')
|
|
243
245
|
|
|
244
246
|
|
|
245
|
-
def barrier_print(s):
|
|
246
|
-
from mpi4py import MPI
|
|
247
|
-
|
|
248
|
-
newData = comm.gather(rank, root=0)
|
|
249
|
-
newData = comm.gather(rank, root=0)
|
|
250
|
-
import sys
|
|
247
|
+
def barrier_print(s, exit=1):
|
|
251
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
|
+
|
|
252
280
|
if rank == 0:
|
|
253
|
-
print("
|
|
281
|
+
print("########", s, flush=True)
|
|
254
282
|
|
|
255
283
|
|
|
256
|
-
def
|
|
257
|
-
# Decorator to broadcast the return value of a function as a
|
|
258
|
-
# 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, ...],
|
|
259
286
|
def wrapper(*args, **kwargs):
|
|
260
287
|
if mpi:
|
|
261
288
|
try:
|
|
262
289
|
v = f(*args, **kwargs)
|
|
263
|
-
if not isinstance(v, list):
|
|
264
|
-
|
|
290
|
+
# if not isinstance(v, list):
|
|
291
|
+
# v = [v]
|
|
265
292
|
v = v[0]
|
|
266
293
|
except ChildProcessError:
|
|
267
294
|
v = None
|
|
@@ -278,6 +305,13 @@ def bcast_function_result(f):
|
|
|
278
305
|
return wrapper
|
|
279
306
|
|
|
280
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
|
+
|
|
281
315
|
def mpi_run_test(n, cwd='.', mpirun_cmd='mpirun'):
|
|
282
316
|
if callable(n):
|
|
283
317
|
return mpi_run_test(n=4)(n)
|
{multiclass_interface-1.20 → 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
|
|
File without changes
|
{multiclass_interface-1.20 → multiclass_interface-1.21}/Multiclass_interface.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.20 → multiclass_interface-1.21}/Multiclass_interface.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.20 → multiclass_interface-1.21}/Multiclass_interface.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.20 → multiclass_interface-1.21}/multiclass_interface/multi_object_list.py
RENAMED
|
File without changes
|
|
File without changes
|
{multiclass_interface-1.20 → 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
|