Skip to content

Commit

Permalink
Datamodel attr caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mkundu1 committed Apr 5, 2023
1 parent 0645893 commit e4c498d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,11 @@ def version_info() -> str:

pydoc.text.docother = fldoc.docother.__get__(pydoc.text, pydoc.TextDoc)

# Whether to use datamodel state caching
DATAMODEL_USE_STATE_CACHE = True

# Whether to use datamodel attribute caching
DATAMODEL_USE_ATTR_CACHE = True

# Whether stream and cache commands state
DATAMODEL_USE_NOCOMMANDS_DIFF_STATE = True
13 changes: 6 additions & 7 deletions src/ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ def __init__(self, service: DatamodelService, rules: str, path: Path = None):
else:
self.path = path
self.cached_attrs = {}
self.event_subscriptions = []

docstring = None

Expand Down Expand Up @@ -390,11 +389,9 @@ def _get_cached_attr(self, attrib: str) -> Any:
if cached_val is None:
cached_val = self._get_remote_attr(attrib)
self.cached_attrs[attrib] = cached_val
self.event_subscriptions.append(
self.add_on_attribute_changed(
attrib,
functools.partial(dict.__setitem__, self.cached_attrs, attrib),
)
self.add_on_attribute_changed(
attrib,
functools.partial(dict.__setitem__, self.cached_attrs, attrib),
)
return cached_val

Expand All @@ -411,7 +408,9 @@ def get_attr(self, attrib: str) -> Any:
Any
Value of the attribute.
"""
if pyfluent.DATAMODEL_USE_ATTR_CACHE:
if pyfluent.DATAMODEL_USE_ATTR_CACHE and hasattr(
DataModelProtoModule, "SubscribeEventsRequest"
):
return self._get_cached_attr(attrib)
return self._get_remote_attr(attrib)

Expand Down
5 changes: 2 additions & 3 deletions src/ansys/fluent/core/session_pure_meshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ def __init__(self, fluent_connection: FluentConnection):
for rules in self.__class__.rules:
request = datamodel_se_pb2.DataModelRequest()
request.rules = rules
request.diffstate = (
datamodel_se_pb2.DIFFSTATE_NOCOMMANDS
) # DIFFSTATE_FULL?
if pyfluent.DATAMODEL_USE_NOCOMMANDS_DIFF_STATE:
request.diffstate = datamodel_se_pb2.DIFFSTATE_NOCOMMANDS
streaming = StreamingService(
stub=datamodel_service_se._stub,
request=request,
Expand Down

0 comments on commit e4c498d

Please sign in to comment.