Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/5920.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
circuit configuration
12 changes: 12 additions & 0 deletions src/ansys/aedt/core/application/analysis_nexxim.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import warnings

from ansys.aedt.core.application.analysis import Analysis
from ansys.aedt.core.generic.configurations import ConfigurationsNexxim
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
from ansys.aedt.core.generic.settings import settings
from ansys.aedt.core.modeler.circuits.object_3d_circuit import CircuitComponent
Expand Down Expand Up @@ -91,10 +92,21 @@ def __init__(
self._post = None
self._internal_excitations = None
self._internal_sources = None
self._configurations = ConfigurationsNexxim(self)
if not settings.lazy_load:
self._modeler = self.modeler
self._post = self.post

@property
def configurations(self):
"""Property to import and export configuration files.

Returns
-------
:class:`ansys.aedt.core.generic.configurations.Configurations`
"""
return self._configurations

@pyaedt_function_handler(setupname="name")
def delete_setup(self, name):
"""Delete a setup.
Expand Down
221 changes: 221 additions & 0 deletions src/ansys/aedt/core/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from collections import defaultdict
import copy
from datetime import datetime
import json
Expand Down Expand Up @@ -2166,3 +2167,223 @@
native_dict["Instances"],
)
return True


class ConfigurationsNexxim(Configurations):
"""Enables export and import configuration options to be applied to a new or existing Nexxim design."""

@pyaedt_function_handler()
def export_config(self, config_file=None, overwrite=False):
"""Export current design properties to a JSON or TOML file.

Parameters
----------
config_file : str, optional
Full path to json file. If ``None``, then the config file will be saved in working directory.
overwrite : bool, optional
If ``True`` the json file will be overwritten if already existing.
If ``False`` and the version is compatible, the data in the existing file will be updated.
Default is ``False``.

Returns
-------
str
Exported config file.
"""

if not config_file:
config_file = os.path.join(
self._app.working_directory, generate_unique_name(self._app.design_name) + ".json"
)
# dict_out = {}
# self._export_general(dict_out)
pin_mapping = defaultdict(list)
data_refdes = {}
data_models = {}
pin_nets = {}
skip_list = [
"LabelID",
"ADD_NOISE",
"DTEMP",
"ModelName",
"CosimDefinition",
"CoSimulator",
"InstanceName",
"NexximNetlist",
"Name",
"COMPONENT",
"EyeMeasurementFunctions",
"ACMAG",
]
for comp in list(self._app.modeler.schematic.components.values()):
properties = {}
num_terminals = None
refdes = comp.refdes
position = comp.location
angle = comp.angle
parameters = comp.parameters
if not comp.component_info:
continue

Check warning on line 2226 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2219-L2226

Added lines #L2219 - L2226 were not covered by tests
else:
component = comp.component_info["Component"]
path = comp.component_path
if not path:
component_type = "Nexxim Component"
path = ""
for param, value in parameters.items():
if param in skip_list:
continue
elif value and value[-1] == "'" and value[1] == "'":
value = value[-1:1]
properties[param] = value
elif path[-4:] == ".ibs":
if "AMI_Version" in parameters:
component_type = "ami"

Check warning on line 2241 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2228-L2241

Added lines #L2228 - L2241 were not covered by tests
else:
component_type = "ibis"
for prop, value in parameters.items():
if value and value[-1] == '"' and value[0] == '"':
value = value[1:-1]
properties[prop] = value
elif path[-4:] in [".LIB", ".lib"] or path[-3:] == ".sp":
component_type = "spice"
elif path[-1:] == "p" and path[-2:-1].isdigit():
component_type = "touchstone"
elif path[-4:] == ".sss":
component_type = "nexxim state space"
num_terminals = comp.model_data.props["numberofports"]

Check warning on line 2254 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2243-L2254

Added lines #L2243 - L2254 were not covered by tests

for pin in comp.pins:
if pin.net == "0":
net = "gnd"

Check warning on line 2258 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2256-L2258

Added lines #L2256 - L2258 were not covered by tests
else:
net = pin.net
temp_dict = {pin: net}
pin_nets.update(temp_dict)

Check warning on line 2262 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2260-L2262

Added lines #L2260 - L2262 were not covered by tests

temp_dict2 = {

Check warning on line 2264 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2264

Added line #L2264 was not covered by tests
refdes: {"component": component, "properties": properties, "position": position, "angle": angle}
}
data_refdes.update(temp_dict2)
if num_terminals:
model = {

Check warning on line 2269 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2267-L2269

Added lines #L2267 - L2269 were not covered by tests
component: {"component_type": component_type, "file_path": path, "num_terminals": num_terminals}
}
num_terminals = None

Check warning on line 2272 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2272

Added line #L2272 was not covered by tests
else:
model = {component: {"component_type": component_type, "file_path": path}}
data_models.update(model)

Check warning on line 2275 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2274-L2275

Added lines #L2274 - L2275 were not covered by tests

for k, v in pin_nets.items():
pin_mapping[v].append(k)

Check warning on line 2278 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2278

Added line #L2278 was not covered by tests

if "" in pin_mapping:
del pin_mapping[""]

Check warning on line 2281 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2281

Added line #L2281 was not covered by tests
for k, l in pin_mapping.items():
temp_dict3 = {}
for i in l:
temp_dict3.update({i._circuit_comp.refdes: i.name})
pin_mapping[k] = temp_dict3

Check warning on line 2286 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2283-L2286

Added lines #L2283 - L2286 were not covered by tests

dict_out = {
"models": data_models,
"refdes": data_refdes,
"pin_mapping": pin_mapping,
} # Call private export method to update dict_out.

# update the json if it exists already

if os.path.exists(config_file) and not overwrite:
dict_in = read_configuration_file(config_file)
try: # TODO: Allow import of config created with other versions of pyaedt.
if dict_in["general"]["pyaedt_version"] == __version__:
for k, v in dict_in.items():
if k not in dict_out:
dict_out[k] = v
elif isinstance(v, dict):
for i, j in v.items():
if i not in dict_out[k]:
dict_out[k][i] = j
except KeyError as e:
self._app.logger.error(str(e))

Check warning on line 2308 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2297-L2308

Added lines #L2297 - L2308 were not covered by tests

# write the updated dict to file
if write_configuration_file(dict_out, config_file):
self._app.logger.info(f"Json file {config_file} created correctly.")
return config_file
self._app.logger.error(f"Error creating json file {config_file}.")
return False

Check warning on line 2315 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2314-L2315

Added lines #L2314 - L2315 were not covered by tests

@pyaedt_function_handler()
def import_config(self, config_file, *args):
"""Import configuration settings from a JSON or TOML file and apply it to the current design.


Parameters
----------
config_file : str
Full path to json file.

Returns
-------
dict, bool
Config dictionary.
"""
if len(args) > 0: # pragma: no cover
raise TypeError("import_config expected at most 1 arguments, got %d" % (len(args) + 1))
self.results._reset_results()

data = read_configuration_file(config_file)
for i, j in data["refdes"].items():
for k, l in data["models"].items():
if k == j["component"]:
component_type = l["component_type"]
if component_type == "Nexxim Component":
new_comp = self._app.modeler.components.create_component(

Check warning on line 2342 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2338-L2342

Added lines #L2338 - L2342 were not covered by tests
name=i,
component_library="",
component_name=j["component"],
location=j["position"],
angle=j["angle"],
)
elif component_type in ["ibis", "ami"]:
if component_type == "ami":
ami = True

Check warning on line 2351 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2349-L2351

Added lines #L2349 - L2351 were not covered by tests
else:
ami = False
comp_set = self._app.get_ibis_model_from_file(l["file_path"], ami).components.values()
for comp in comp_set:
for pin in comp.pins.values():
if pin.buffer_name == k:
new_comp = pin.insert(j["position"][0], j["position"][1])
elif component_type == "touchstone":
new_comp = self._app.modeler.schematic.create_touchstone_component(

Check warning on line 2360 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2353-L2360

Added lines #L2353 - L2360 were not covered by tests
l["file_path"], location=j["position"], angle=j["angle"]
)
elif component_type == "spice":
new_comp = self._app.modeler.schematic.create_component_from_spicemodel(

Check warning on line 2364 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2363-L2364

Added lines #L2363 - L2364 were not covered by tests
input_file=l["file_path"], location=j["position"]
)
elif component_type == "nexxim state space":
new_comp = self._app.modeler.schematic.create_nexxim_state_space_component(

Check warning on line 2368 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2367-L2368

Added lines #L2367 - L2368 were not covered by tests
l["file_path"], l["num_terminals"], location=j["position"], angle=j["angle"]
)
for name, parameter in j["properties"].items():
new_comp.parameters[name] = parameter

Check warning on line 2372 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2371-L2372

Added lines #L2371 - L2372 were not covered by tests

for i, j in data["pin_mapping"].items():
pins = []
for k, l in j.items():
for comp in list(self._app.modeler.schematic.components.values()):
if not comp.refdes:
continue
elif comp.refdes == k:
for pin in comp.pins:
if pin.name == l:
pins.append(pin)
if i == "gnd":
for gnd_pin in pins:
self._app.modeler.schematic.create_gnd(gnd_pin.location, gnd_pin.angle, page=i)

Check warning on line 2386 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2375-L2386

Added lines #L2375 - L2386 were not covered by tests
else:
pins[0].connect_to_component(pins[1:], page_name=i)

Check warning on line 2388 in src/ansys/aedt/core/generic/configurations.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/generic/configurations.py#L2388

Added line #L2388 was not covered by tests
return data
Loading