Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing only one worker in pool #2656

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ansys/mapdl/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@
self._active = True # used by pool monitor

n_instances = int(n_instances)
if n_instances < 2:
raise ValueError("Must request at least 2 instances to create a pool.")
if n_instances < 1:
raise ValueError("Must request at least 1 instance to create a pool.")

Check warning on line 226 in src/ansys/mapdl/core/pool.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/pool.py#L225-L226

Added lines #L225 - L226 were not covered by tests

pbar = None
if wait and progress_bar:
if not _HAS_TQDM: # pragma: no cover
raise ModuleNotFoundError(
f"To use the keyword argument 'progress_bar', you need to have installed the 'tqdm' package. "
"To use the keyword argument 'progress_bar', you need to have installed the 'tqdm' package. "
"To avoid this message you can set 'progress_bar=False'."
)

Expand Down
25 changes: 25 additions & 0 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,28 @@ def myfun(i):
assert "Other_instance" in dirs_path_pool

pool.exit(block=True)


def test_num_instances():
with pytest.raises(ValueError, match="least 1 instance"):
pool = LocalMapdlPool(
0,
exec_file=EXEC_FILE,
nproc=NPROC,
additional_switches=QUICK_LAUNCH_SWITCHES,
)


@requires("local")
@skip_if_ignore_pool
def test_only_one_instance():
pool = LocalMapdlPool(
1,
exec_file=EXEC_FILE,
nproc=NPROC,
additional_switches=QUICK_LAUNCH_SWITCHES,
)
pool_sz = len(pool)
_ = pool.map(lambda mapdl: mapdl.prep7())
assert len(pool) == pool_sz
pool.exit()
Loading