Skip to content

Commit 7fa8450

Browse files
committed
Merge branch 'master' of https://github.com/pyansys/DPF-Core
2 parents 87c0f68 + 97328db commit 7fa8450

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

ansys/dpf/core/_version.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@
66
__version__ = ".".join(map(str, version_info))
77
__ansys_version__ = "221"
88
min_server_version = "2.0"
9+
10+
server_to_ansys_grpc_dpf_version = {
11+
"1.0": "0.2.2",
12+
"2.0": "0.3.0",
13+
"3.0": "0.4.0",
14+
}
15+
16+
server_to_ansys_version = {
17+
"1.0": "2021R1",
18+
"2.0": "2021R2",
19+
"3.0": "2022R1",
20+
}

ansys/dpf/core/server.py

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@
2020
from ansys.dpf.core.misc import find_ansys, is_ubuntu
2121
from ansys.dpf.core import errors
2222

23-
from ansys.dpf.core._version import __ansys_version__
23+
from ansys.dpf.core._version import (
24+
__ansys_version__,
25+
server_to_ansys_version,
26+
server_to_ansys_grpc_dpf_version
27+
)
2428
from ansys.dpf.core import session
29+
import ansys.grpc.dpf
2530

2631
MAX_PORT = 65535
2732

@@ -326,6 +331,7 @@ def __init__(
326331
docker_name=None,
327332
):
328333
"""Start the DPF server."""
334+
329335
# check valid ip and port
330336
check_valid_ip(ip)
331337
if not isinstance(port, int):
@@ -338,35 +344,23 @@ def __init__(
338344

339345
self.channel = grpc.insecure_channel("%s:%d" % (ip, port))
340346

341-
if launch_server is False:
342-
state = grpc.channel_ready_future(self.channel)
343-
# verify connection has matured
344-
tstart = time.time()
345-
while ((time.time() - tstart) < timeout) and not state._matured:
346-
time.sleep(0.001)
347-
348-
if not state._matured:
349-
raise TimeoutError(
350-
f"Failed to connect to {ip}:{port} in {timeout} seconds"
351-
)
352-
353-
LOG.debug("Established connection to DPF gRPC")
354-
355347
# assign to global channel when requested
356348
if as_global:
357349
dpf.core.SERVER = self
358350

359351
# TODO: add to PIDs ...
360352

361353
# store port and ip for later reference
362-
self.live = True
363-
self.ansys_path = ansys_path
364354
self._input_ip = ip
365355
self._input_port = port
356+
self.live = True
357+
self.ansys_path = ansys_path
366358
self._own_process = launch_server
367359
self._base_service_instance = None
368360
self._session_instance = None
369361

362+
check_ansys_grpc_dpf_version(self, timeout)
363+
370364
@property
371365
def _base_service(self):
372366
if not self._base_service_instance:
@@ -654,3 +648,30 @@ def read_stderr():
654648

655649
if len(docker_id) > 0:
656650
return docker_id[0]
651+
652+
653+
def check_ansys_grpc_dpf_version(server, timeout):
654+
state = grpc.channel_ready_future(server.channel)
655+
# verify connection has matured
656+
tstart = time.time()
657+
while ((time.time() - tstart) < timeout) and not state._matured:
658+
time.sleep(0.001)
659+
660+
if not state._matured:
661+
raise TimeoutError(
662+
f"Failed to connect to {server._input_ip}:{server._input_port} in {timeout} seconds"
663+
)
664+
665+
LOG.debug("Established connection to DPF gRPC")
666+
grpc_module_version = ansys.grpc.dpf.__version__
667+
server_version = server.version
668+
right_grpc_module_version = server_to_ansys_grpc_dpf_version.get(server_version, None)
669+
if right_grpc_module_version and right_grpc_module_version != grpc_module_version:
670+
raise ImportWarning(f"2022R1 Ansys unified install is available. "
671+
f"To use DPF server from Ansys "
672+
f"{server_to_ansys_version.get(server_version, 'Unknown')}"
673+
f" (dpf.SERVER.version=='{server_version}'), "
674+
f"install version {right_grpc_module_version} of ansys-grpc-dpf"
675+
f" with the command: \n"
676+
f" pip install ansys-grpc-dpf=={right_grpc_module_version}"
677+
)

0 commit comments

Comments
 (0)