Skip to content

Commit 53e672d

Browse files
committed
FIX: Miscellaneous 25.2 fixes
1 parent 8efb15b commit 53e672d

File tree

11 files changed

+113
-44
lines changed

11 files changed

+113
-44
lines changed

src/ansys/edb/core/geometry/polygon_data.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from ansys.edb.core import session
1010
from ansys.edb.core.geometry.arc_data import ArcData
1111
from ansys.edb.core.inner import messages, parser
12+
from ansys.edb.core.inner.utils import client_stream_iterator
1213
from ansys.edb.core.utility import conversions
1314

1415

@@ -40,6 +41,17 @@ class IntersectionType(Enum):
4041
class PolygonData:
4142
"""Represents a polygon data object."""
4243

44+
@staticmethod
45+
def _polygon_data_request_iterator(polys):
46+
chunk_entry_creator = lambda poly: messages.polygon_data_message(poly)
47+
chunk_entries_getter = lambda chunk: chunk.polygons
48+
return client_stream_iterator(
49+
polys,
50+
polygon_data_pb2.PolygonDataListMessage,
51+
chunk_entry_creator,
52+
chunk_entries_getter,
53+
)
54+
4355
__stub: polygon_data_pb2_grpc.PolygonDataServiceStub = session.StubAccessor(
4456
session.StubType.polygon_data
4557
)
@@ -355,7 +367,7 @@ def bbox_of_polygons(cls, polygons):
355367
-------
356368
tuple[.PointData, .PointData]
357369
"""
358-
return cls.__stub.GetBBox(messages.polygon_data_list_message(polygons))
370+
return cls.__stub.GetStreamedBBox(PolygonData._polygon_data_request_iterator(polygons))
359371

360372
@parser.to_circle
361373
def bounding_circle(self):

src/ansys/edb/core/hierarchy/spice_model.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""SPICE Model."""
22
from ansys.edb.core.hierarchy.model import Model
3-
from ansys.edb.core.inner import messages
3+
from ansys.edb.core.inner import messages, parser
44
from ansys.edb.core.session import SpiceModelServiceStub, StubAccessor, StubType
55

66

@@ -78,3 +78,10 @@ def remove_terminal(self, terminal):
7878
Terminal name.
7979
"""
8080
self.__stub.RemoveTerminalPinPair(messages.string_property_message(self, terminal))
81+
82+
@property
83+
@parser.to_string_dict
84+
def terminal_pin_pairs(self):
85+
""":obj:`dict` of {:obj:`str` : :obj:`str`}: A dictionary showing the mapping of terminals in the layout to \
86+
pins in the spice model by name."""
87+
return self.__stub.GetTerminalPinPairs(self.msg)

src/ansys/edb/core/inner/factory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""This module allows for the creating of objects while avoid circular imports."""
22

33
from ansys.edb.core.edb_defs import LayoutObjType
4-
from ansys.edb.core.inner.conn_obj import ConnObj
54

65
_type_creator_params_dict = None
76
_primitive_type_creator_params_dict = None
@@ -20,6 +19,7 @@ def _initialize_type_creator_params_dict():
2019
from ansys.edb.core.hierarchy.cell_instance import CellInstance
2120
from ansys.edb.core.hierarchy.group import Group
2221
from ansys.edb.core.hierarchy.pin_group import PinGroup
22+
from ansys.edb.core.inner.conn_obj import ConnObj
2323
from ansys.edb.core.layout.voltage_regulator import VoltageRegulator
2424
from ansys.edb.core.net.differential_pair import DifferentialPair
2525
from ansys.edb.core.net.extended_net import ExtendedNet
@@ -43,6 +43,7 @@ def _initialize_type_creator_params_dict():
4343
LayoutObjType.EXTENDED_NET: _CreatorParams(ExtendedNet),
4444
LayoutObjType.DIFFERENTIAL_PAIR: _CreatorParams(DifferentialPair),
4545
LayoutObjType.NET: _CreatorParams(Net),
46+
LayoutObjType.INVALID_LAYOUT_OBJ: _CreatorParams(ConnObj),
4647
}
4748
return _type_creator_params_dict
4849

@@ -157,4 +158,4 @@ def create_conn_obj(msg):
157158
-------
158159
ansys.edb.core.inner.ConnObj
159160
"""
160-
return create_lyt_obj(msg, ConnObj(msg).obj_type)
161+
return create_lyt_obj(msg, create_lyt_obj(msg, LayoutObjType.INVALID_LAYOUT_OBJ).obj_type)

src/ansys/edb/core/inner/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@
120120
NetRefMessage,
121121
)
122122
from ansys.api.edb.v1.rlc_pb2 import RlcMessage
123+
from ansys.api.edb.v1.s_parameter_model_pb2 import SParameterModelMessage
123124
from ansys.api.edb.v1.simulation_setup_pb2 import MatrixConvergenceEntryMessage
124-
from ansys.api.edb.v1.sparameter_model_pb2 import SParameterModelMessage
125125
from ansys.api.edb.v1.spice_model_pb2 import SpiceModelMessage, SpiceModelNewTerminalPinMessage
126126
from ansys.api.edb.v1.structure_3d_pb2 import ClosureMessage, SetClosureMessage
127127
from ansys.api.edb.v1.term_inst_pb2 import TermInstCreationMessage

src/ansys/edb/core/inner/parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def to_mesh_op(fn):
9595
return _wraps(fn, _to_mesh_op)
9696

9797

98+
def to_string_dict(fn):
99+
"""Decorate a function that returns a message to return it as a ``dict[str, str]``."""
100+
return _wraps(fn, _to_string_dict)
101+
102+
98103
def _wraps(fn, wrapper_fn):
99104
if callable(fn):
100105

@@ -498,3 +503,8 @@ def _to_mesh_op(message):
498503
for nli in message.net_layer_info:
499504
mesh_op.net_layer_info.append((nli.net, nli.layer, nli.is_sheet))
500505
return mesh_op
506+
507+
508+
def _to_string_dict(message):
509+
"""Convert a message to a dictionary of strings."""
510+
return {key: value for (key, value) in message.string_map}

src/ansys/edb/core/inner/rpc_info.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ def invalidates_cache(self):
299299
"SetRelativePermitivityAtFrequency": _RpcInfo(buffer=True),
300300
"GetLossTangentAtFrequency": _RpcInfo(cache=True),
301301
"SetLossTangentAtFrequency": _RpcInfo(buffer=True),
302+
"GetHighFrequencyCorner": _RpcInfo(cache=True),
303+
"SetHighFrequencyCorner": _RpcInfo(buffer=True),
302304
"UseDCRelativePermitivity": _RpcInfo(cache=True),
303305
"SetUseDCRelativePermitivity": _RpcInfo(buffer=True),
304306
"GetDCRelativePermitivity": _RpcInfo(cache=True),
@@ -584,6 +586,7 @@ def invalidates_cache(self):
584586
},
585587
"ansys.api.edb.v1.LayoutInstanceService": {
586588
"QueryLayoutObjInstances": _RpcInfo(cache=True),
589+
"StreamLayoutObjInstancesQuery": _RpcInfo(read_no_cache=True),
587590
"GetLayoutObjInstanceInContext": _RpcInfo(cache=True),
588591
"GetConnectedObjects": _RpcInfo(read_no_cache=True),
589592
"StreamConnectedObjects": _RpcInfo(read_no_cache=True),
@@ -607,6 +610,7 @@ def invalidates_cache(self):
607610
},
608611
"ansys.api.edb.v1.LayoutObjInstanceService": {
609612
"GetLayers": _RpcInfo(cache=True),
613+
"StreamLayers": _RpcInfo(read_no_cache=True),
610614
"GetGeometries": _RpcInfo(cache=True),
611615
"GetContext": _RpcInfo(cache=True),
612616
"GetLayoutInstanceContext": _RpcInfo(cache=True),
@@ -863,6 +867,7 @@ def invalidates_cache(self):
863867
"GetArea": _RpcInfo(cache=True),
864868
"Transform": _RpcInfo(cache=True),
865869
"GetBBox": _RpcInfo(cache=True),
870+
"GetStreamedBBox": _RpcInfo(read_no_cache=True),
866871
"GetConvexHull": _RpcInfo(cache=True),
867872
"RemoveArcs": _RpcInfo(cache=True),
868873
"Defeature": _RpcInfo(cache=True),
@@ -1272,12 +1277,6 @@ def invalidates_cache(self):
12721277
"UsesSolderball": _RpcInfo(cache=True),
12731278
"Clone": _RpcInfo(buffer=True, returns_future=True, write_no_cache_invalidation=True),
12741279
},
1275-
"ansys.api.edb.v1.SParameterModelService": {
1276-
"Create": _RpcInfo(buffer=True, returns_future=True, write_no_cache_invalidation=True),
1277-
"GetProperties": _RpcInfo(cache=True),
1278-
"SetComponentModelName": _RpcInfo(buffer=True),
1279-
"SetReferenceNet": _RpcInfo(buffer=True),
1280-
},
12811280
"ansys.api.edb.v1.SpiceModelService": {
12821281
"Create": _RpcInfo(buffer=True, returns_future=True, write_no_cache_invalidation=True),
12831282
"GetProperties": _RpcInfo(cache=True),
@@ -1286,6 +1285,7 @@ def invalidates_cache(self):
12861285
"SetSubCkt": _RpcInfo(buffer=True),
12871286
"AddTerminalPinPair": _RpcInfo(buffer=True),
12881287
"RemoveTerminalPinPair": _RpcInfo(buffer=True),
1288+
"GetTerminalPinPairs": _RpcInfo(cache=True),
12891289
},
12901290
"ansys.api.edb.v1.StackupLayerService": {
12911291
"Create": _RpcInfo(buffer=True, returns_future=True, write_no_cache_invalidation=True),
@@ -1308,6 +1308,8 @@ def invalidates_cache(self):
13081308
"SetEtchFactorEnabled": _RpcInfo(buffer=True),
13091309
"SetEtchFactor": _RpcInfo(buffer=True),
13101310
"GetEtchFactor": _RpcInfo(cache=True),
1311+
"SetEtchNetClass": _RpcInfo(buffer=True),
1312+
"GetEtchNetClass": _RpcInfo(cache=True),
13111313
"GetUseSolverProperties": _RpcInfo(cache=True),
13121314
"SetUseSolverProperties": _RpcInfo(buffer=True),
13131315
"GetHFSSSolverProperties": _RpcInfo(cache=True),
@@ -1323,6 +1325,12 @@ def invalidates_cache(self):
13231325
"GetMeshClosureProp": _RpcInfo(cache=True),
13241326
"SetMeshClosureProp": _RpcInfo(buffer=True),
13251327
},
1328+
"ansys.api.edb.v1.SParameterModelService": {
1329+
"Create": _RpcInfo(buffer=True, returns_future=True, write_no_cache_invalidation=True),
1330+
"GetProperties": _RpcInfo(cache=True),
1331+
"SetComponentModelName": _RpcInfo(buffer=True),
1332+
"SetReferenceNet": _RpcInfo(buffer=True),
1333+
},
13261334
"ansys.api.edb.v1.TerminalService": {
13271335
"FindByName": _RpcInfo(buffer=True, returns_future=True),
13281336
"GetParams": _RpcInfo(cache=True),

src/ansys/edb/core/inner/utils.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from ansys.api.edb.v1.layout_obj_pb2 import LayoutObjTargetMessage
33

44
from ansys.edb.core.inner.factory import create_lyt_obj
5-
from ansys.edb.core.utility.io_manager import get_cache
65

76

87
def map_list(iterable_to_operate_on, operator=None):
@@ -23,6 +22,8 @@ def query_lyt_object_collection(
2322
):
2423
"""For the provided request, retrieve a collection of objects using the unary_rpc or unary_streaming_rpc methods \
2524
depending on whether caching is enabled."""
25+
from ansys.edb.core.utility.io_manager import get_cache
26+
2627
request = (
2728
LayoutObjTargetMessage(target=owner.msg, type=obj_type.value)
2829
if request_requires_type
@@ -53,3 +54,22 @@ def stream_items_from_server(parser, stream, chunk_items_att_name):
5354
for chunk in stream
5455
for chunk_entry in getattr(chunk, chunk_items_att_name)
5556
]
57+
58+
59+
def client_stream_iterator(
60+
data_to_stream,
61+
chunk_type,
62+
chunk_entry_creator,
63+
chunk_entries_getter,
64+
max_size=32000,
65+
starting_chunk=None,
66+
):
67+
"""Create an iterator of client side items to be used when streaming items to the server."""
68+
chunk = chunk_type() if starting_chunk is None else starting_chunk
69+
for data_entry in data_to_stream:
70+
chunk_entry = chunk_entry_creator(data_entry)
71+
if chunk.ByteSize() + chunk_entry.ByteSize() > max_size:
72+
yield chunk
73+
chunk = chunk_type()
74+
chunk_entries_getter(chunk).append(chunk_entry)
75+
yield chunk

src/ansys/edb/core/layout_instance/layout_instance.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ansys.api.edb.v1.layout_instance_pb2 as layout_instance_pb2
33

44
from ansys.edb.core.geometry.point_data import PointData
5+
from ansys.edb.core.geometry.polygon_data import PolygonData
56
from ansys.edb.core.inner import ObjBase, utils
67
from ansys.edb.core.inner.messages import (
78
layer_ref_message,
@@ -12,6 +13,7 @@
1213
)
1314
from ansys.edb.core.layout_instance import layout_obj_instance
1415
from ansys.edb.core.session import LayoutInstanceServiceStub, StubAccessor, StubType
16+
from ansys.edb.core.utility.io_manager import get_cache
1517

1618

1719
class LayoutInstance(ObjBase):
@@ -65,19 +67,30 @@ def to_msg_filter_list(client_filter, ref_msg_type):
6567
)
6668
msg_params[spatial_filter_field] = spatial_filter_msg
6769

68-
hits = self.__stub.QueryLayoutObjInstances(
69-
layout_instance_pb2.LayoutObjInstancesQueryMessage(**msg_params)
70-
)
71-
72-
if hits.HasField("full_partial_hits"):
73-
full_partial_hits = hits.full_partial_hits
74-
return utils.map_list(
75-
full_partial_hits.full.items, layout_obj_instance.LayoutObjInstance
76-
), utils.map_list(
77-
full_partial_hits.partial.items, layout_obj_instance.LayoutObjInstance
78-
)
70+
request = layout_instance_pb2.LayoutObjInstancesQueryMessage(**msg_params)
71+
all_hits = []
72+
if (cache := get_cache()) is not None:
73+
for hits_chunk in self.__stub.StreamLayoutObjInstancesQuery(request):
74+
all_hits.append(hits_chunk)
75+
else:
76+
all_hits.append(self.__stub.QueryLayoutObjInstances(request))
77+
78+
if isinstance(spatial_filter, PolygonData):
79+
full_hits = []
80+
partial_hits = []
81+
for hits in all_hits:
82+
full_partial_hits = hits.full_partial_hits
83+
for full_hit in full_partial_hits.full.items:
84+
full_hits.append(layout_obj_instance.LayoutObjInstance(full_hit))
85+
for partial_hit in full_partial_hits.partial.items:
86+
partial_hits.append(layout_obj_instance.LayoutObjInstance(partial_hit))
87+
return full_hits, partial_hits
7988
else:
80-
return utils.map_list(hits.hits.items, layout_obj_instance.LayoutObjInstance)
89+
return [
90+
layout_obj_instance.LayoutObjInstance(hit)
91+
for hits in all_hits
92+
for hit in hits.hits.items
93+
]
8194

8295
def get_layout_obj_instance_in_context(self, layout_obj, context):
8396
"""Get the layout object instance of the given :term:`connectable <Connectable>` in the provided context.

src/ansys/edb/core/primitive/primitive_instance_collection.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from ansys.edb.core.inner.layout_obj import LayoutObj
2020
import ansys.edb.core.inner.messages as messages
2121
from ansys.edb.core.inner.parser import msg_to_point_data, msg_to_polygon_data, to_polygon_data
22-
from ansys.edb.core.inner.utils import stream_items_from_server
22+
from ansys.edb.core.inner.utils import client_stream_iterator, stream_items_from_server
2323
from ansys.edb.core.session import StubAccessor, StubType
2424

2525

@@ -33,15 +33,16 @@ class PrimitiveInstanceCollection(LayoutObj):
3333

3434
@staticmethod
3535
def _point_request_iterator(points, starting_chunk):
36-
chunk = starting_chunk
37-
max_size = 8000
38-
for point in points:
39-
point_msg = messages.point_message(point)
40-
if chunk.ByteSize() + point_msg.ByteSize() > max_size:
41-
yield chunk
42-
chunk = PrimitiveInstanceCollectionDataMessage()
43-
chunk.points.points.append(point_msg)
44-
yield chunk
36+
chunk_entry_creator = lambda point: messages.point_message(point)
37+
chunk_entries_getter = lambda chunk: chunk.points.points
38+
return client_stream_iterator(
39+
points,
40+
PrimitiveInstanceCollectionDataMessage,
41+
chunk_entry_creator,
42+
chunk_entries_getter,
43+
8000,
44+
starting_chunk,
45+
)
4546

4647
@classmethod
4748
def create(

src/ansys/edb/core/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
)
127127
from ansys.api.edb.v1.rectangle_pb2_grpc import RectangleServiceStub
128128
from ansys.api.edb.v1.rlc_component_property_pb2_grpc import RLCComponentPropertyServiceStub
129+
from ansys.api.edb.v1.s_parameter_model_pb2_grpc import SParameterModelServiceStub
129130
from ansys.api.edb.v1.si_wave_dcir_simulation_settings_pb2_grpc import (
130131
SIWaveDCIRSimulationSettingsServiceStub,
131132
)
@@ -145,7 +146,6 @@
145146
)
146147
from ansys.api.edb.v1.simulation_setup_pb2_grpc import SimulationSetupServiceStub
147148
from ansys.api.edb.v1.solder_ball_property_pb2_grpc import SolderBallPropertyServiceStub
148-
from ansys.api.edb.v1.sparameter_model_pb2_grpc import SParameterModelServiceStub
149149
from ansys.api.edb.v1.spice_model_pb2_grpc import SpiceModelServiceStub
150150
from ansys.api.edb.v1.stackup_layer_pb2_grpc import StackupLayerServiceStub
151151
from ansys.api.edb.v1.structure_3d_pb2_grpc import Structure3DServiceStub

src/ansys/edb/core/utility/io_manager.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from google.protobuf.empty_pb2 import Empty
1414

1515
from ansys.edb.core.inner.rpc_info_utils import get_rpc_info
16+
from ansys.edb.core.inner.utils import client_stream_iterator
1617

1718
# The cache module singleton
1819
MOD = modules[__name__]
@@ -196,15 +197,11 @@ def _hijack_request(self, service_name, rpc_name, request):
196197

197198
@staticmethod
198199
def _buffer_request_iterator(buffer):
199-
max_size = 32000
200-
msg = BufferMessage()
201-
for buffer_entry in buffer:
202-
buffer_entry_msg = buffer_entry.msg()
203-
if msg.ByteSize() + buffer_entry_msg.ByteSize() > max_size:
204-
yield msg
205-
msg = BufferMessage()
206-
msg.buffer.append(buffer_entry_msg)
207-
yield msg
200+
chunk_entry_creator = lambda buffer_entry: buffer_entry.msg()
201+
chunk_entries_getter = lambda chunk: chunk.buffer
202+
return client_stream_iterator(
203+
buffer, BufferMessage, chunk_entry_creator, chunk_entries_getter
204+
)
208205

209206
def flush(self):
210207
if not self._buffer:

0 commit comments

Comments
 (0)