Python Error: Application file not generated? - python

I want to simulate a OpenModelica Model in Python with the help of OMPython. The following is my code:
import matplotlib.pyplot as plt
import OMPython
from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem
omc = OMCSessionZMQ()
mod = ModelicaSystem("Li_ionBattery.mo", "Li_ionBattery.TestBench.VaryingCurrent")
Li_simulation = mod.getSimulationOptions()
mod.setSimulationOptions(["stopTime=2000", "stepSize=50"])
variables_vary = mod.getQuantities()
Parameters_vary = mod.getParameters()
continous_vary = mod.getContinuous()
mod.setParameters(["nMC_Data.Q_nom=11", "nMC_Data.Rs=0.0003"])
mod.simulate()
And I am getting the following error:
Notification: Li_ionBattery requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Error: Class Li_ionBattery.TestBench.VaryingCurrent not found in scope <top>.
Error: Class Li_ionBattery.TestBench.VaryingCurrent not found in scope <TOP>.
stopTime !is not a simulation-option variable
Traceback (most recent call last):
raise Exception("Error: application file not generated yet")
Exception: Error: application file not generated yet

The error is at line,
mod = ModelicaSystem("Li_ionBattery.mo", "Li_ionBattery.TestBench.VaryingCurrent")
as it reports,
Error: Class Li_ionBattery.TestBench.VaryingCurrent not found in scope <top>.
Make sure the class Li_ionBattery.TestBench.VaryingCurrent exists in Li_ionBattery.mo.

Related

kochat in use RuntimeError: main thread is not in main loop

kochat is a Korean chatbot, and I ran into a problem while practicing it.
github imformation : https://github.com/hyunwoongko/kochat
It is environment setting
python3.8
pip install kochat
JPype is reinstalled ues JPype1-1.2.0-cp38-cp38-win_amd64.whl <-download
pytorch is same ver with cuda 11.1
start code
### from kochat.proc import DistanceClassifier ###
from kochat.data import Dataset
from kochat.proc import GensimEmbedder, DistanceClassifier
from kochat.model import intent, embed
from kochat.loss import CenterLoss
dataset = Dataset(ood=True)
emb = GensimEmbedder(model=embed.Word2Vec())
# 프로세서 생성
clf = DistanceClassifier(
model=intent.CNN(dataset.intent_dict),
loss=CenterLoss(dataset.intent_dict)
)
# 되도록이면 DistanceClassifier는 Margin 기반의 Loss 함수를 이용해주세요
# 현재는 CenterLoss, COCOLoss, Cosface, GausianMixture 등의
# 거리기반 Metric Learning 전용 Loss함수를 지원합니다.
# 모델 학습
clf.fit(dataset.load_intent(emb))
# 모델 추론 (인텐트 분류)
clf.predict(dataset.load_predict("오늘 서울 날씨 어떨까", emb))
error message
C:\projectkyc\kochat3.8\Scripts\python.exe "C:/projectkyc/kochat3.8/test3.8/!from kochat.proc import DistanceClassifier.py"`enter code here`
Exception ignored in: <function Image.__del__ at 0x000001E7E1566D30>
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\tkinter\__init__.py", line 4014, in __del__
Exception ignored in: <function Variable.__del__ at 0x000001E7E154B430>
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\tkinter\__init__.py", line 351, in __del__
if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Exception ignored in: <function Image.__del__ at 0x000001E7E1566D30>
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\tkinter\__init__.py", line 4014, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (os_windows_x86.cpp:144), pid=11208, tid=0x00000000000037f4
# guarantee(result == EXCEPTION_CONTINUE_EXECUTION) failed: Unexpected result from topLevelExceptionFilter
#
# JRE version: Java(TM) SE Runtime Environment (8.0_281-b09) (build 1.8.0_281-b09)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.281-b09 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\projectkyc\kochat3.8\test3.8\hs_err_pid11208.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Exception ignored in: <function Image.__del__ at 0x000001E7E1566D30>
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\tkinter\__init__.py", line 4014, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread
Process finished with exit code 1
If I haven't posted it or if I have the information I need, I will add it immediately upon confirmation if requested.
This is such an annoying issue and to me setting matplotlib.use('Agg') does not cut it. I dont want to comprise on this.
The only thing that seems to do it somewhat consistently is having to close the figure before creating a new plot via plt.close(). This is annoying and if i forget it does this.
this error
Matplotlib - Tcl_AsyncDelete: async handler deleted by the wrong thread?
same Question But did not know where to apply
The places to apply are kochat\utils\visualizer.py and kochat\proc\utils\visualizer.py
to be. In the
from matplotlib import pyplot as plt
part of these two places,
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
The problem is solved.

Freshman AttributeError: No attribute in a module

just new to python, and I believe this is not a big deal but because I am a freshman.
Basically, this is a simple program plotting a FM signal in time domain. I write a module by myself.
def FreqMod (fc,fm,t_domain)
pi=py.pi
if fc>fm:
delta=fc-fm
else:
delta=fm-fc
return py.cos(2*pi*fc*t_domain+ (delta/fm)*py.sin(2*pi*fm*t_domain))
def AmpMod(fc,fm,t_domain):
pi=py.pi
return py.cos(2*pi*fc*t_domain)*py.cos(2*pi*fm*t_domain)
And import it in another program
import numpy as py
import mylib
import matplotlib.pyplot as plt
pi=py.pi
y=mylib.FreqMod(5,1000,t=py.arange(0,2*pi,pi/4000))
plt.plot(y)
The lib file is located as the same directory as the program. But I Got this later:
Traceback (most recent call last):
File "...(The directory)...", line 14, in <module>
y=mylib.FreqMod(5,1000,t=py.arange(0,2*pi,pi/4000))
AttributeError: module 'mylib' has no attribute 'FreqMod'
It seems like I didn't import the module successfully. I have compared it with examples in how to write and import a module, but yet can't figure out why. This really confuse me as a beginner in python.

Python wont allow me to import .py files from same directory

So I'm just starting to learn Python, and I am learning classes and imports, but for some reason even when I follow the same code as my book say to do, I get a traceback error.
Traceback (most recent call last):
File "C:/Users/Programming/Desktop/Programs/EX40/main.py", line 1, in <module>
import objects.py
ModuleNotFoundError: No module named 'objects.py'; 'objects' is not a package
Here is both my Python files in which I'm trying to link:
main.py
import objects.py
print(MyStuff.tangerine)
objects.py
class MyStuff(object):
def __init__(self, arm):
self.tangerine = 'And now a thousand years between'
self.arm = arm
def apple(self):
print('I AM CLASSY APPLES!')
Try using
import objects
Because it takes py as a module in the objects file which does not exist
import objects.py is not a valid import
https://docs.python.org/3/reference/import.html
Try
from objects import MyStuff
Instantiating the class:
mystuff = MyStuff("arm value")
print(mystuff.tangerine)

'NoneType' object is not callable error when using couchbase with git, logbook module

I'd experienced weird result when testing couchbase python SDK.
below is the source code and result:
# xxx.py
from gcouchbase.bucket import Bucket
dsn = 'couchbase://[url-of-couchbase]/[bucket-name]'
db = Bucket(dsn)
# yyy.py
import logbook
import git
from xxx import db
# python yyy.py
Traceback (most recent call last):
File "/home/username/env/local/lib/python2.7/site-packages/gcouchbase/iops_gevent10.py", line 88, in timer_event_factory
return GEventTimer()
TypeError: 'NoneType' object is not callable
[1] 8546 abort (core dumped) python yyy.py
The weird thing is, when I remove import git or import logbook from yyy.py, the error doesn't happen.
Is there any reason for this error? should any resource for couchdb be disposed?
An asynchronous event seems to arrive after the Bucket object has been removed. If you call bucket._close() explicitly, the script would not be crashed. Anyways, it looks like a bug of gcouchbase.

name 'OSPF_Link' is not defined

I have a python script like this:
#!/usr/bin/env python
from scapy.all import *
from ospf import *
def ourSend(packet):
sendp(packet,iface='eth1')
host1='10.0.3.2'
advr_routers='10.0.8.7'
host2='10.0.2.2'
sequence=0x80000918
link2host1 = OSPF_Link(id=host1,data='10.0.3.1',type=2,metric=1)
link2host2 = OSPF_Link(id=host2,data='10.0.2.2',type=2,metric=1)
link2victim = OSPF_Link(id="192.168.200.20",data="255.255.255.255",type=3,metric=1)
IPlayer=IP(src='10.0.1.2',dst='224.0.0.5')
OSPFHdr=OSPF_Hdr(src='10.0.6.1')
rogueLsa=Ether()/IPlayer/OSPFHdr/OSPF_LSUpd(lsacount=1,lsalist=[OSPF_Router_LSA(options=0x22,id='10.0.3.1',adrouter=advr_routers,seq=sequence,\
linkcount=3,linklist=[link2victim,link2host1,link2host2])])
ourSend(rogueLsa)
When I run it it has an scapy error.. So I resolved it with git pyrt...
now when I want to run the python script I have other error:
$ python scipt.py
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
File "s.py", line 19, in <module>
link2host1 = OSPF_Link(id=host1,data='10.0.3.1',type=2,metric=1)
NameError: name 'OSPF_Link' is not defined
Thank you
I Should separately get ospf.py again and run my script.
This is what I tried and worked...
When you git pyrt The module OSPF_Link can't be added. SO I used the ospf.py again and problem is solved now....

Categories