2021年10月29日 星期五

利用desktopproxy中斷.aedt模擬

我們可以用指令執行aedt模擬,比如說

set path=C:\Program Files\AnsysEM\v221\Win64;%path%

start ansysedt.exe -ng -BatchSolve .\package.aedt

上述案例執行時間4分17秒。 

接下來我們用ansysedt指令執行,2分鐘後以desktopproxy -abort中斷模擬。

set path=C:\Program Files\AnsysEM\v221\Win64;%path%

start ansysedt.exe -ng -BatchSolve .\package.aedt

PING localhost -n 120 >NUL

desktopproxy -abort .\package.aedt

中斷之後,再重啟模擬到模擬結束共2分22秒

set path=C:\Program Files\AnsysEM\v221\Win64;%path%

start ansysedt.exe -ng -BatchSolve .\package.aedt

總共花了4分22秒,比一次完成執行僅僅多了約5秒。代表中斷之後重啟模擬是延續之前中斷之前的狀態,而非重新開始。

Steamlit手動排序項目


import time
import streamlit as st


def submit_up(n):
if n > 0:
x = st.session_state.waiting_list[n]
y = st.session_state.waiting_list[n - 1]
st.session_state.waiting_list[n - 1] = x
st.session_state.waiting_list[n] = y


def submit_down(n):
if n < len(st.session_state.waiting_list) - 1:
x = st.session_state.waiting_list[n]
y = st.session_state.waiting_list[n + 1]
st.session_state.waiting_list[n + 1] = x
st.session_state.waiting_list[n] = y


def submit_top(n):
st.session_state.waiting_list = [st.session_state.waiting_list.pop(n)] + st.session_state.waiting_list


def submit_bottom(n):
st.session_state.waiting_list = st.session_state.waiting_list + [st.session_state.waiting_list.pop(n)]


def delete(n):
st.session_state.waiting_list.pop(n)


if 'waiting_list' not in st.session_state:
st.session_state.waiting_list = ['A1', 'B2', 'C3', 'D4']

for n, i in enumerate(st.session_state.waiting_list):
with st.expander(i):
c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 = st.columns(10)
with c1:
st.button('▲', key=f'move up_{i}', on_click=submit_up, args=(n,))
with c2:
st.button('▼', key=f'move down_{i}', on_click=submit_down, args=(n,))
with c3:
st.button('Top', key=f'move up_{i}', on_click=submit_top, args=(n,))
with c4:
st.button('Bottom', key=f'move down_{i}', on_click=submit_bottom, args=(n,))
with c8:
st.button('Delete', key=f'delete_{i}', on_click=delete, args=(n,))
(圖一)手動排序選單


如何用程式碼更改AEDT選項設定

AEDT當中所有的設定都存放在XML檔案當中:C:\Users\<UserName>\Documents\Ansoft\<AnsysProductNameversion>\config\<PC_NAME>_user.XML,比方HPC的設定等等。可以透過指令修改,比方:oDesktop.SetRegistryString('Desktop\Settings\ProjectOptions\HPCLicenseType' , 'Pool')。

處理機碼的指令包含如下:

  • DeleteRegistryEntry
  • DoesRegistryValueExist
  • GetRegistryInt
  • GetRegistryString
  • SetRegistryFromFile
  • SetRegistryInt
  • SetRegistryString

其他像是AEDT Option當中的選項設定也可以透過上述的函式來讀取或修改。

(圖一)AEDT選項設定視窗


2021年10月25日 星期一

不同資料結構對應之表格


import pandas as pd
import streamlit as st
from streamlit_autorefresh import st_autorefresh
import json
count = st_autorefresh(interval=1000)

x = {'name':['a','b','c'], 'Year':[4,5,6]}
st.table(pd.DataFrame(x))

y = [{'name':'a', 'Year':4}, {'name':'b', 'Year':5}, {'name':'c', 'Year':6}]
st.table(pd.DataFrame(y))

z = {'John':{'name':'a', 'Year':'4'}, 'Mark':{'name':'b', 'Year':'5'}, 'Eddy':{'name':'c', 'Year':'6'}}
st.table(pd.DataFrame(z))

w = {'John':{'name':'a', 'Year':4}, 'Mark':{'name':'b', 'Year':5}, 'Eddy':{'name':'c', 'Year':6}}
st.table(pd.DataFrame(w).T)
st.dataframe(pd.DataFrame(w).T)




2021年10月20日 星期三

透過頁面監視檔案夾

 

(圖一)頁面監看檔案夾

import streamlit as st
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from streamlit_autorefresh import st_autorefresh

count = st_autorefresh(interval=1000)

class MyHandler(FileSystemEventHandler):
def on_created(self, event):
with open('state.log', 'a') as f:
f.writelines("on_created: {}\n".format(event.src_path))

def on_deleted(self, event):
with open('state.log', 'a') as f:
f.writelines("on_deleted: {}\n".format(event.src_path))

if 'event_handler' not in st.session_state:
st.session_state.event_handler = MyHandler()
st.session_state.observer = Observer()
st.session_state.observer.schedule(st.session_state.event_handler, path='d:/demo', recursive=True)
st.session_state.observer.start()

try:
with open('state.log') as f:
text = f.readlines()
st.text(''.join(text))
except:
pass

如何在SIwave匯出Pin Group的設定,並在另一個設計匯入

在SIwave匯出Pin Group的設定,並在另一個設計匯入。

(圖一) SIwave Pin Group設定

exportPG_v2.py

import os
import json
import logging

os.chdir(os.path.dirname(__file__))
logging.basicConfig(filename='simulation.log', encoding='utf-8', filemode='w', level=logging.DEBUG)

oDoc = oApp.GetActiveProject()
oDoc.ScrExportComponentFile('temp.cmp')
with open('temp.cmp') as f:
text = f.readlines()

pg = {}
for line in text:
if line.startswith('B_IC') or line.startswith('B_IO'):
_, refdes, part = line.split()

if line.startswith('B_PIN_GROUP '):
group_name = line.split()[1]
key = ','.join([part[1:-1], refdes[1:-1], group_name])
continue

if 'E_PIN_GROUP' in line:
if 'key' in locals():
del (key)
continue

if 'key' in locals():
pg[key] = line.split()

logging.info(pg)

with open('pg_info.json', 'w') as f:
json.dump(pg, f, indent=4)

importPG_v2.py

import os
import json
import logging

os.chdir(os.path.dirname(__file__))
logging.basicConfig(filename='simulation.log', encoding='utf-8', filemode='w', level=logging.DEBUG)

oDoc = oApp.GetActiveProject()
with open('pg_info.json') as f:
data = json.load(f)

logging.info(data)
for key, pins in data.items():
part_name, refdes_name, group_name = key.split(',')
oDoc.ScrCreatePinGroups(part_name, refdes_name, pins, group_name, False)

2021年10月16日 星期六

License Increment簡化

# -*- coding: utf-8 -*-
import streamlit as st

st.header("License Increment輸出工具")
st.markdown("**從自己的license檔案取得與客戶license相同的Increments建立新的license。注意:數量無法改變!**")
large_license = st.file_uploader("上傳自己的ansyslmd.lic")
small_license = st.file_uploader("上傳客戶的ansyslmd.lic")

if large_license and small_license:
header = []
license_items = {}

text = large_license.getvalue().decode("utf-8").splitlines()

for line in text:
if line.startswith('INCREMENT'):
feature = line.split()[1]
license_items[feature] = [line]
else:
try:
license_items[feature].append(line)
except:
header.append(line)

text = small_license.getvalue().decode("utf-8").splitlines()

extracted_features = []
for line in text:
if line.startswith('INCREMENT'):
feature = line.split()[1]
extracted_features.append(feature)

text = '\n'.join(header) + '\n'
for feature in extracted_features:
text += '\n'.join(license_items[feature]) + '\n'
st.subheader('{} Increments 輸出:'.format(len(extracted_features)))
st.write(',\n'.join(extracted_features))

st.download_button('下載檔案', file_name='new_ansyslmd.lic', data=text)