Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/common/algorithm_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_result(self):
pass

@classmethod
def get_default_options(self):
def get_default_options(cls):
pass

class ResultBase(object):
Expand Down
6 changes: 2 additions & 4 deletions src/common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def unzip_unit(archive, path='.'):

# extract all into temp_dir
archive.extractall(path=tmpdir)
archive.close()

return tmpdir

Expand Down Expand Up @@ -458,10 +459,7 @@ def list_to_string(item_list):
item_list = [1, 2, 3]
return value: '1;2;3'
"""
ret_str = ''
for l in item_list:
ret_str =ret_str+str(l)+os.pathsep
return ret_str
return os.pathsep.join(str(l) for l in item_list)

class Trajectory:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/common/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def setup_diagnostics_variables(model, start_time, options, solver_options):
if (rtol is None) or (atol is None):
rtol, atol = model.get_tolerances()

# is atol is scalar, convert to list
# if atol is scalar, convert to list
if isinstance(atol, numbers.Number):
atol = [atol]*len(states_list)
# atol is "pseudoscalar", array/list with single entry;
Expand Down
148 changes: 78 additions & 70 deletions src/common/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,28 +401,32 @@ def __init__(self, filename, delimiter=";"):
fid = filename
fid.seek(0, 0) # need to start reading from beginning

if delimiter == ";":
name = fid.readline().strip().split(delimiter)
elif delimiter == ",":
name = [s[1:-1] for s in re.findall('".+?"', fid.readline().strip())]
else:
raise JIOError('Unsupported separator.')
self._name = name
try:
if delimiter == ";":
name = fid.readline().strip().split(delimiter)
elif delimiter == ",":
name = [s[1:-1] for s in re.findall('".+?"', fid.readline().strip())]
else:
raise JIOError('Unsupported separator.')
self._name = name

self.data_matrix = {}
for i,n in enumerate(name):
self.data_matrix[n] = i
self.data_matrix = {}
for i,n in enumerate(name):
self.data_matrix[n] = i

data = []
while True:
row = fid.readline().strip().split(delimiter)
data = []
while True:
row = fid.readline().strip().split(delimiter)

if row[-1] == "" or row[-1] == "\n":
break
if row[-1] == "" or row[-1] == "\n":
break

data.append([float(d) for d in row])
data.append([float(d) for d in row])

self.data = np.array(data)
self.data = np.array(data)
finally:
if isinstance(filename, (str, Path)):
fid.close()

def get_variable_names(self) -> list[str]:
return list(self.data_matrix.keys())
Expand Down Expand Up @@ -543,6 +547,7 @@ def write_header(self, file_name='', parameters=None):
# Open file
f = codecs.open(file_name,'w','utf-8')
self._file_open = True
self._file = f

# Write header
f.write('#1\n')
Expand Down Expand Up @@ -789,7 +794,6 @@ def write_header(self, file_name='', parameters=None):

# f.write('%s,%d)\n' % (' '*14, self._nvariables))

self._file = f
self._data_order = valueref_of_continuous_states

def write_point(self, data=None, parameter_data=[]):
Expand Down Expand Up @@ -1010,71 +1014,75 @@ def __init__(self,fname):
fid = fname
fid.seek(0,0) # Needs to start from beginning of file

# Read Aclass section
nLines = self._find_phrase(fid, 'char Aclass')
try:
# Read Aclass section
nLines = self._find_phrase(fid, 'char Aclass')

nLines = int(nLines[0])
self.Aclass = [fid.readline().strip() for i in range(nLines)]
nLines = int(nLines[0])
self.Aclass = [fid.readline().strip() for i in range(nLines)]

# Read name section
nLines = self._find_phrase(fid, 'char name')
# Read name section
nLines = self._find_phrase(fid, 'char name')

nLines = int(nLines[0])
self._name = [fid.readline().strip().replace(" ","") for i in range(nLines)]
self.name_lookup = {key:ind for ind,key in enumerate(self._name)}
nLines = int(nLines[0])
self._name = [fid.readline().strip().replace(" ","") for i in range(nLines)]
self.name_lookup = {key:ind for ind,key in enumerate(self._name)}

# Read description section
nLines = self._find_phrase(fid, 'char description')
# Read description section
nLines = self._find_phrase(fid, 'char description')

nLines = int(nLines[0])
self.description = [fid.readline().strip() for i in range(nLines)]
nLines = int(nLines[0])
self.description = [fid.readline().strip() for i in range(nLines)]

# Read dataInfo section
nLines = self._find_phrase(fid, 'int dataInfo')
# Read dataInfo section
nLines = self._find_phrase(fid, 'int dataInfo')

nCols = nLines[2].partition(')')
nLines = int(nLines[0])
nCols = int(nCols[0])
nCols = nLines[2].partition(')')
nLines = int(nLines[0])
nCols = int(nCols[0])

self.dataInfo = np.array([list(map(int,fid.readline().split()[0:nCols])) for i in range(nLines)])
self.dataInfo = np.array([list(map(int,fid.readline().split()[0:nCols])) for i in range(nLines)])

# Find out how many data matrices there are
if len(self._name) == 1: # Only time
nData = 2
else:
nData = max(self.dataInfo[:,0])
# Find out how many data matrices there are
if len(self._name) == 1: # Only time
nData = 2
else:
nData = max(self.dataInfo[:,0])

self.data = []
for i in range(0,nData):
line = fid.readline()
tmp = line.partition(' ')
while tmp[0]!='float' and tmp[0]!='double' and line!='':
self.data = []
for i in range(0,nData):
line = fid.readline()
tmp = line.partition(' ')
if line=='':
raise JIOError('The result does not seem to be of a supported format.')
tmp = tmp[2].partition('(')
nLines = tmp[2].partition(',')
nCols = nLines[2].partition(')')
nLines = int(nLines[0])
nCols = int(nCols[0])
data = []
for i in range(0,nLines):
info = []
while len(info) < nCols and line != '':
while tmp[0]!='float' and tmp[0]!='double' and line!='':
line = fid.readline()
info.extend(line.split())
try:
data.append(list(map(float,info[0:nCols])))
except ValueError: # Handle 1.#INF's and such
data.append(list(map(robust_float,info[0:nCols])))
if len(info) == 0 and i < nLines-1:
raise JIOError("Inconsistent number of lines in the result data.")
del(info)
self.data.append(np.array(data))

if len(self.data) == 0:
raise JIOError('Could not find any variable data in the result file.')
tmp = line.partition(' ')
if line=='':
raise JIOError('The result does not seem to be of a supported format.')
tmp = tmp[2].partition('(')
nLines = tmp[2].partition(',')
nCols = nLines[2].partition(')')
nLines = int(nLines[0])
nCols = int(nCols[0])
data = []
for i in range(0,nLines):
info = []
while len(info) < nCols and line != '':
line = fid.readline()
info.extend(line.split())
try:
data.append(list(map(float,info[0:nCols])))
except ValueError: # Handle 1.#INF's and such
data.append(list(map(robust_float,info[0:nCols])))
if len(info) == 0 and i < nLines-1:
raise JIOError("Inconsistent number of lines in the result data.")
del(info)
self.data.append(np.array(data))

if len(self.data) == 0:
raise JIOError('Could not find any variable data in the result file.')
finally:
if isinstance(fname, (str, Path)):
fid.close()

def _find_phrase(self,fid, phrase):
line = fid.readline()
Expand Down
2 changes: 1 addition & 1 deletion src/common/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
The log analysis toolkit.
"""

from pyfmi.common.log.parser import parse_xml_log, parse_xml_log, extract_xml_log, parse_fmu_xml_log
from pyfmi.common.log.parser import parse_xml_log, extract_xml_log, parse_fmu_xml_log
from pyfmi.common.log.prettyprinter import prettyprint_to_file

__all__=['parser', 'tree', 'prettyprinter']
2 changes: 1 addition & 1 deletion src/common/plotting/plot_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ def DrawRectZoom(self, drawNew=True):

if y1 > y0:
y0, y1 = y1, y0
if x1 < y0:
if x1 < x0:
x0, x1 = x1, x0

w = x1 - x0
Expand Down
4 changes: 0 additions & 4 deletions src/pyfmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def check_packages():

error_packages=[]
warning_packages=[]
fp = None
for package in packages:
try:
vers="--"
Expand All @@ -113,9 +112,6 @@ def check_packages():
sys.stdout.write("%s %s %s " % (package.ljust(le,'.'), vers.ljust(le_short), "Package missing - Error issued, see details below.".ljust(le_short)))
error_packages.append(package)
pass
finally:
if fp:
fp.close()
sys.stdout.write("\n")
sys.stdout.flush()
time.sleep(0.25)
Expand Down
1 change: 1 addition & 0 deletions src/pyfmi/examples/fmi_bouncing_ball_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def run_demo(with_plots=True):

#Get new nominal values.
if eInfo.stateValueReferencesChanged:
rtol = 1e-6
atol = 0.01*rtol*bouncing_fmu.nominal_continuous_states

#Check for new time event
Expand Down
Loading
Loading