Skip to content

Commit cc7ea20

Browse files
authored
Merge pull request #433 from pyiron/hostname_localhost
Automatically set hostname_localhost
2 parents bdeed77 + 4d16c36 commit cc7ea20

11 files changed

+56
-64
lines changed

executorlib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__(
103103
flux_executor=None,
104104
flux_executor_pmi_mode: Optional[str] = None,
105105
flux_executor_nesting: bool = False,
106-
hostname_localhost: bool = False,
106+
hostname_localhost: Optional[bool] = None,
107107
block_allocation: bool = True,
108108
init_function: Optional[callable] = None,
109109
disable_dependencies: bool = False,
@@ -127,7 +127,7 @@ def __new__(
127127
flux_executor=None,
128128
flux_executor_pmi_mode: Optional[str] = None,
129129
flux_executor_nesting: bool = False,
130-
hostname_localhost: bool = False,
130+
hostname_localhost: Optional[bool] = None,
131131
block_allocation: bool = True,
132132
init_function: Optional[callable] = None,
133133
disable_dependencies: bool = False,

executorlib/interactive/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def create_executor(
4040
flux_executor=None,
4141
flux_executor_pmi_mode: Optional[str] = None,
4242
flux_executor_nesting: bool = False,
43-
hostname_localhost: bool = False,
43+
hostname_localhost: Optional[bool] = None,
4444
block_allocation: bool = False,
4545
init_function: Optional[callable] = None,
4646
):

executorlib/shared/communication.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import sys
12
from socket import gethostname
3+
from typing import Optional
24

35
import cloudpickle
46
import zmq
@@ -119,7 +121,7 @@ def __del__(self):
119121
def interface_bootup(
120122
command_lst: list[str],
121123
connections,
122-
hostname_localhost: bool = False,
124+
hostname_localhost: Optional[bool] = None,
123125
):
124126
"""
125127
Start interface for ZMQ communication
@@ -139,6 +141,10 @@ def interface_bootup(
139141
Returns:
140142
executorlib.shared.communication.SocketInterface: socket interface for zmq communication
141143
"""
144+
if hostname_localhost is None and sys.platform == "darwin":
145+
hostname_localhost = True
146+
elif hostname_localhost is None:
147+
hostname_localhost = False
142148
if not hostname_localhost:
143149
command_lst += [
144150
"--host",

executorlib/shared/executor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def execute_parallel_tasks(
302302
future_queue: queue.Queue,
303303
cores: int = 1,
304304
spawner: BaseSpawner = MpiExecSpawner,
305-
hostname_localhost: bool = False,
305+
hostname_localhost: Optional[bool] = None,
306306
init_function: Optional[Callable] = None,
307307
**kwargs,
308308
) -> None:
@@ -358,7 +358,7 @@ def execute_separate_tasks(
358358
future_queue: queue.Queue,
359359
spawner: BaseSpawner = MpiExecSpawner,
360360
max_cores: int = 1,
361-
hostname_localhost: bool = False,
361+
hostname_localhost: Optional[bool] = None,
362362
**kwargs,
363363
):
364364
"""
@@ -605,7 +605,7 @@ def _submit_function_to_separate_process(
605605
spawner: BaseSpawner,
606606
executor_kwargs: dict,
607607
max_cores: int = 1,
608-
hostname_localhost: bool = False,
608+
hostname_localhost: Optional[bool] = None,
609609
):
610610
"""
611611
Submit function to be executed in separate Python process

notebooks/examples.ipynb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
" flux_executor=flux_exe,\n",
222222
" flux_executor_pmi_mode=None,\n",
223223
" flux_executor_nesting=False,\n",
224-
" hostname_localhost=False, # only required on MacOS\n",
224+
" hostname_localhost=None, # only required on MacOS\n",
225225
" block_allocation=False, # reuse existing processes with fixed resources\n",
226226
" init_function=None, # only available with block_allocation=True\n",
227227
" disable_dependencies=False, # disable dependency check for faster execution\n",
@@ -243,7 +243,7 @@
243243
" \"flux_executor\": flux_exe,\n",
244244
" \"flux_executor_pmi_mode\": None,\n",
245245
" \"flux_executor_nesting\": False,\n",
246-
" \"hostname_localhost\": False, # only required on MacOS\n",
246+
" \"hostname_localhost\": None, # only required on MacOS\n",
247247
" },\n",
248248
" )\n",
249249
" print(future_obj.result())"
@@ -749,8 +749,16 @@
749749
"Workstations, especially workstations with MacOs can have rather strict firewall settings. This includes limiting the\n",
750750
"look up of hostnames and communicating with itself via their own hostname. To directly connect to `localhost` rather\n",
751751
"than using the hostname which is the default for distributed systems, the `hostname_localhost=True` parameter is \n",
752-
"introduced. "
752+
"introduced."
753753
]
754+
},
755+
{
756+
"metadata": {},
757+
"cell_type": "code",
758+
"outputs": [],
759+
"execution_count": null,
760+
"source": "",
761+
"id": "601852447d3839c4"
754762
}
755763
],
756764
"metadata": {

tests/test_dependencies_executor.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def merge(lst):
4141

4242
class TestExecutorWithDependencies(unittest.TestCase):
4343
def test_executor(self):
44-
with Executor(max_cores=1, backend="local", hostname_localhost=True) as exe:
44+
with Executor(max_cores=1, backend="local") as exe:
4545
cloudpickle_register(ind=1)
4646
future_1 = exe.submit(add_function, 1, parameter_2=2)
4747
future_2 = exe.submit(add_function, 1, parameter_2=future_1)
@@ -55,7 +55,6 @@ def test_executor_dependency_plot(self):
5555
with Executor(
5656
max_cores=1,
5757
backend="local",
58-
hostname_localhost=True,
5958
plot_dependency_graph=True,
6059
) as exe:
6160
cloudpickle_register(ind=1)
@@ -105,7 +104,6 @@ def test_dependency_steps(self):
105104
gpus_per_worker=0,
106105
openmpi_oversubscribe=False,
107106
backend="local",
108-
hostname_localhost=True,
109107
)
110108
process = RaisingThread(
111109
target=execute_tasks_with_dependencies,
@@ -127,7 +125,7 @@ def test_dependency_steps(self):
127125
def test_many_to_one(self):
128126
length = 5
129127
parameter = 1
130-
with Executor(max_cores=2, backend="local", hostname_localhost=True) as exe:
128+
with Executor(max_cores=2, backend="local") as exe:
131129
cloudpickle_register(ind=1)
132130
future_lst = exe.submit(
133131
generate_tasks,
@@ -162,7 +160,6 @@ def test_many_to_one_plot(self):
162160
with Executor(
163161
max_cores=2,
164162
backend="local",
165-
hostname_localhost=True,
166163
plot_dependency_graph=True,
167164
) as exe:
168165
cloudpickle_register(ind=1)

tests/test_executor_backend_mpi.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ def mpi_funct(i):
2222

2323
class TestExecutorBackend(unittest.TestCase):
2424
def test_meta_executor_serial(self):
25-
with Executor(
26-
max_cores=2, hostname_localhost=True, backend="local", block_allocation=True
27-
) as exe:
25+
with Executor(max_cores=2, backend="local", block_allocation=True) as exe:
2826
cloudpickle_register(ind=1)
2927
fs_1 = exe.submit(calc, 1)
3028
fs_2 = exe.submit(calc, 2)
@@ -34,9 +32,7 @@ def test_meta_executor_serial(self):
3432
self.assertTrue(fs_2.done())
3533

3634
def test_meta_executor_single(self):
37-
with Executor(
38-
max_cores=1, hostname_localhost=True, backend="local", block_allocation=True
39-
) as exe:
35+
with Executor(max_cores=1, backend="local", block_allocation=True) as exe:
4036
cloudpickle_register(ind=1)
4137
fs_1 = exe.submit(calc, 1)
4238
fs_2 = exe.submit(calc, 2)
@@ -52,7 +48,6 @@ def test_meta_executor_parallel(self):
5248
with Executor(
5349
max_workers=2,
5450
cores_per_worker=2,
55-
hostname_localhost=True,
5651
backend="local",
5752
block_allocation=True,
5853
) as exe:
@@ -67,14 +62,12 @@ def test_errors(self):
6762
max_cores=1,
6863
cores_per_worker=1,
6964
threads_per_core=2,
70-
hostname_localhost=True,
7165
backend="local",
7266
)
7367
with self.assertRaises(TypeError):
7468
Executor(
7569
max_cores=1,
7670
cores_per_worker=1,
7771
gpus_per_worker=1,
78-
hostname_localhost=True,
7972
backend="local",
8073
)

tests/test_executor_backend_mpi_noblock.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class TestExecutorBackend(unittest.TestCase):
1616
def test_meta_executor_serial(self):
1717
with Executor(
1818
max_cores=2,
19-
hostname_localhost=True,
2019
backend="local",
2120
block_allocation=False,
2221
) as exe:
@@ -31,7 +30,6 @@ def test_meta_executor_serial(self):
3130
def test_meta_executor_single(self):
3231
with Executor(
3332
max_cores=1,
34-
hostname_localhost=True,
3533
backend="local",
3634
block_allocation=False,
3735
) as exe:
@@ -49,29 +47,25 @@ def test_errors(self):
4947
max_cores=1,
5048
cores_per_worker=1,
5149
threads_per_core=2,
52-
hostname_localhost=True,
5350
backend="local",
5451
)
5552
with self.assertRaises(TypeError):
5653
Executor(
5754
max_cores=1,
5855
cores_per_worker=1,
5956
gpus_per_worker=1,
60-
hostname_localhost=True,
6157
backend="local",
6258
)
6359
with self.assertRaises(ValueError):
6460
with Executor(
6561
max_cores=1,
66-
hostname_localhost=True,
6762
backend="local",
6863
block_allocation=False,
6964
) as exe:
7065
exe.submit(resource_dict, resource_dict={})
7166
with self.assertRaises(ValueError):
7267
with Executor(
7368
max_cores=1,
74-
hostname_localhost=True,
7569
backend="local",
7670
block_allocation=True,
7771
) as exe:

tests/test_integration_pyiron_workflow.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def slowly_returns_dynamic(dynamic_arg):
7474
return dynamic_arg
7575

7676
dynamic_dynamic = slowly_returns_dynamic()
77-
executor = Executor(hostname_localhost=True, block_allocation=True)
77+
executor = Executor(block_allocation=True)
7878
cloudpickle_register(ind=1)
7979
dynamic_object = does_nothing()
8080
fs = executor.submit(dynamic_dynamic.run, dynamic_object)
@@ -104,7 +104,7 @@ def slowly_returns_42():
104104
self.assertIsNone(
105105
dynamic_42.result, msg="Just a sanity check that the test is set up right"
106106
)
107-
executor = Executor(hostname_localhost=True, block_allocation=True)
107+
executor = Executor(block_allocation=True)
108108
cloudpickle_register(ind=1)
109109
fs = executor.submit(dynamic_42.run)
110110
fs.add_done_callback(dynamic_42.process_result)
@@ -135,7 +135,7 @@ def returns_42():
135135
dynamic_42.running,
136136
msg="Sanity check that the test starts in the expected condition",
137137
)
138-
executor = Executor(hostname_localhost=True, block_allocation=True)
138+
executor = Executor(block_allocation=True)
139139
cloudpickle_register(ind=1)
140140
fs = executor.submit(dynamic_42.run)
141141
fs.add_done_callback(dynamic_42.process_result)
@@ -159,7 +159,7 @@ def raise_error():
159159
raise RuntimeError
160160

161161
re = raise_error()
162-
executor = Executor(hostname_localhost=True, block_allocation=True)
162+
executor = Executor(block_allocation=True)
163163
cloudpickle_register(ind=1)
164164
fs = executor.submit(re.run)
165165
with self.assertRaises(
@@ -189,7 +189,7 @@ def slowly_returns_dynamic():
189189
return inside_variable
190190

191191
dynamic_dynamic = slowly_returns_dynamic()
192-
executor = Executor(hostname_localhost=True, block_allocation=True)
192+
executor = Executor(block_allocation=True)
193193
cloudpickle_register(ind=1)
194194
fs = executor.submit(dynamic_dynamic.run)
195195
self.assertIsInstance(
@@ -218,7 +218,7 @@ def slow():
218218
return fortytwo
219219

220220
f = slow()
221-
executor = Executor(hostname_localhost=True, block_allocation=True)
221+
executor = Executor(block_allocation=True)
222222
cloudpickle_register(ind=1)
223223
fs = executor.submit(f.run)
224224
self.assertEqual(

0 commit comments

Comments
 (0)