Skip to content

Commit

Permalink
Merge pull request #6 from ansys-internal/fb-ROCKY-20273-better-pyroc…
Browse files Browse the repository at this point in the history
…ky-numpy-serializ

Register Numpy serializer for Pyro client
  • Loading branch information
igortg authored Nov 16, 2023
2 parents 3bb4908 + f71cd27 commit aac6932
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/ansys/rocky/prepost/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ def __init__(self, pyro_api, pool_id):
self._pool_id = pool_id
self._pyro_api = pyro_api

def GetNumpyCurve(self, curve_name, unit=None):
api = self._pyro_api
serpent_dicts = api.SendToApiElement(
self._pool_id, "GetNumpyCurve", curve_name, unit
)
numpy_data = [serpent.tobytes(d) for d in serpent_dicts]
return tuple(pickle.loads(b) for b in numpy_data)

def __getattr__(self, attr_name: str) -> object:
def CallProxy(*args, **kwargs):
return self._pyro_api.SendToApiElement(
Expand All @@ -67,8 +59,14 @@ def deserialize_api_error(classname, serialized):
return RockyApiError(serialized["message"])


def deserialize_numpy(classname, serialized):
bytes = serpent.tobytes(serialized["bytes"])
return pickle.loads(bytes)


Pyro5.api.register_dict_to_class("ApiElementProxy", _ApiElementProxy.deserialize)
Pyro5.api.register_dict_to_class("RockyApiError", deserialize_api_error)
Pyro5.api.register_dict_to_class("ndarray", deserialize_numpy)

Pyro5.api.register_class_to_dict(_ApiElementProxy, _ApiElementProxy.serialize)

Expand Down

0 comments on commit aac6932

Please sign in to comment.