Skip to content

Commit

Permalink
Emit license session (#3856)
Browse files Browse the repository at this point in the history
* Add new license_session object to EMIT revision, and a test

* Uncomment tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Change revision.license_session from a function to a property

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update _unittest_solvers/test_26_emit.py version format

Co-authored-by: Kathy Pippert <[email protected]>

* Update _unittest_solvers/test_26_emit.py grammar

Co-authored-by: Kathy Pippert <[email protected]>

* Update pyaedt/emit_core/results/revision.py grammar

Co-authored-by: Kathy Pippert <[email protected]>

* Update pyaedt/emit_core/results/revision.py grammar

Co-authored-by: Kathy Pippert <[email protected]>

* Update pyaedt/emit_core/results/revision.py grammar

Co-authored-by: Kathy Pippert <[email protected]>

* Change license_session property to get_license_session function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix comment style

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: jsalant22 <[email protected]>
Co-authored-by: Kathy Pippert <[email protected]>
Co-authored-by: Alberto Di Maria <[email protected]>
Co-authored-by: Matthew Young <[email protected]>
  • Loading branch information
6 people authored Dec 1, 2023
1 parent dc75b24 commit 0521483
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
90 changes: 90 additions & 0 deletions _unittest_solvers/test_26_emit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Import required modules
import os
import sys
import time

from _unittest_solvers.conftest import config
import pytest
Expand Down Expand Up @@ -1170,3 +1171,92 @@ def test_result_categories(self, add_app):
with pytest.raises(RuntimeError) as e:
instance.get_largest_emi_problem_type()
assert "An EMI value is not available so the largest EMI problem type is undefined." in str(e)

@pytest.mark.skipif(
config["desktopVersion"] < "2024.2", reason="Skipped on versions earlier than 2024 R2."
)
def test_license_session(self, add_app):
self.aedtapp = add_app(project_name="interference", application=Emit, subfolder=test_subfolder)

# Generate a revision
results = self.aedtapp.results
revision = self.aedtapp.results.analyze()

receivers = revision.get_receiver_names()
modeRx = TxRxMode.RX
modeTx = TxRxMode.TX
modeEmi = ResultType.EMI
self.aedtapp.set_units("Frequency", "GHz")

def get_best_rx_channel(results, receiver):
domain = results.interaction_domain()
rev = results.current_revision
# get interferers
interferers = rev.get_interferer_names()
best_emi = 300.0
best_band = None
best_freq = None

combinations_run = 0

domain.set_receiver(receiver)
interaction = rev.run(domain)

for interferer in interferers:
for tx_band in rev.get_band_names(interferer, modeTx):
for tx_freq in rev.get_active_frequencies(interferer, tx_band, modeTx):
domain.set_interferer(interferer, tx_band, tx_freq)
rx_band = rev.get_band_names(receiver, modeRx)[0]
for rx_freq in rev.get_active_frequencies(receiver, rx_band, modeRx):

domain.set_receiver(receiver, rx_band, rx_freq)

if best_band == None:
best_band = rx_band
if best_freq == None:
best_freq = rx_freq

try:
instance = interaction.get_instance(domain)
if instance.has_valid_values():
emi = instance.get_value(modeEmi)
if emi < best_emi:
best_emi = emi
best_band = rx_band
best_freq = rx_freq
else:
assert(f'No valid values found')
except:
assert("No results between " + interferer + ": " + tx_band +
": " + str(tx_freq) + " and " + receiver + ": " +
rx_band + ": " + str(rx_freq))

combinations_run += 1

if combinations_run >= 20:
return [best_band, best_freq]
return [best_band, best_freq]

# Warmup in case something isn't solved
best_case_rx_ch = {}
for rx in [receivers[0]]:
best_case_rx_ch[rx] = get_best_rx_channel(results, rx)

# Get the time without the license session
start = time.perf_counter()
best_case_rx_ch = {}
for rx in [receivers[0]]:
best_case_rx_ch[rx] = get_best_rx_channel(results, rx)
end = time.perf_counter()
noLicenseSessionTime = end - start

# Get the time using the license session
start = time.perf_counter()
best_case_rx_ch = {}
with revision.get_license_session():
for rx in [receivers[0]]:
best_case_rx_ch[rx] = get_best_rx_channel(results, rx)
end = time.perf_counter()
licenseSessionTime = end - start

assert (licenseSessionTime*2) < noLicenseSessionTime
19 changes: 19 additions & 0 deletions pyaedt/emit_core/results/revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,22 @@ def set_emi_category_filter_enabled(self, category: EmiCategoryFilter, enabled:
raise RuntimeError("This function is only supported in AEDT version 2024 R1 and later.")
engine = self.emit_project._emit_api.get_engine()
engine.set_emi_category_filter_enabled(category, enabled)

def get_license_session(self):
"""Get a license session.
A license session can be started with checkout(), and ended with checkin().
The `with` keyword can also be used, where checkout() is called on enter, and checkin() is called on exit.
Avoids having to wait for license checkin and checkout when doing many runs.
Examples
--------
with revision.get_license_session():
domain = aedtapp.interaction_domain()
revision.run(domain)
"""
if self.emit_project._aedt_version < "2024.2": # pragma: no cover
raise RuntimeError("This function is only supported in AEDT version 2024 R2 and later.")
engine = self.emit_project._emit_api.get_engine()
return engine.license_session()

0 comments on commit 0521483

Please sign in to comment.