pythonfmu3 0.1.18__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pythonfmu3/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.18"
1
+ __version__ = "0.2.1"
@@ -26,10 +26,11 @@ target_include_directories(pythonfmu-export
26
26
  "${CMAKE_CURRENT_SOURCE_DIR}"
27
27
  )
28
28
 
29
- target_link_libraries(pythonfmu-export
30
- PRIVATE
31
- ${Python3_LIBRARIES}
32
- )
29
+ if (WIN32)
30
+ target_link_libraries(pythonfmu-export PRIVATE ${Python3_LIBRARIES})
31
+ elseif (APPLE)
32
+ set_target_properties(pythonfmu-export PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
33
+ endif ()
33
34
 
34
35
  if (WIN32)
35
36
  set_target_properties(pythonfmu-export
@@ -73,6 +73,7 @@ PySlaveInstance::PySlaveInstance(std::string instanceName, std::string resources
73
73
  std::string moduleName = getline(resources_ + "/slavemodule.txt");
74
74
  PyObject* pModule = PyImport_ImportModule(moduleName.c_str());
75
75
  if (pModule == nullptr) {
76
+ PyErr_Print();
76
77
  handle_py_exception("[ctor] PyImport_ImportModule", gilState);
77
78
  }
78
79
 
@@ -732,7 +733,7 @@ namespace
732
733
  }
733
734
  return TRUE;
734
735
  }
735
- #elif defined(__linux__)
736
+ #elif defined(__linux__) || defined(__APPLE__)
736
737
  __attribute__((destructor)) void onLibraryUnload()
737
738
  {
738
739
  finalizePythonInterpreter();
@@ -8,7 +8,7 @@ from xml.etree import ElementTree
8
8
 
9
9
  from pythonfmu3 import Fmi3Slave
10
10
  from pythonfmu3.enums import Fmi3Causality, Fmi3Initial, Fmi3Variability
11
- from pythonfmu3.variables import Boolean, Int32, UInt64, Float64, ModelVariable, String, Dimension
11
+ from pythonfmu3.variables import flatten, Boolean, Int32, UInt64, Float64, ModelVariable, String, Dimension
12
12
 
13
13
  from .utils import PY2FMI, UInt64ValType
14
14
 
@@ -303,14 +303,33 @@ def test_String_to_xml(name, start):
303
303
  @pytest.mark.requirements("numpy")
304
304
  @pytest.mark.parametrize("name,start,dims", [
305
305
  ("array1", [1.,2.,3.,4.], [4]),
306
- ("array2", [1.,2.,3.,4.], [2, 2]),
306
+ ("array2", [1.,2.,3.,4.], [2, 2])
307
307
  ])
308
308
  def test_array_to_xml(name, start, dims):
309
309
  r = Float64(name, start, dimensions=[Dimension(start=val) for val in dims])
310
310
  xml = r.to_xml()
311
311
  if start is not None:
312
- assert xml.attrib['start'] == " ".join([f"{val:.16g}" for val in start])
312
+ assert xml.attrib['start'] == " ".join([f"{val:.16g}" for val in flatten(start)])
313
313
  if dims is not None:
314
314
  xml_dims = xml.findall('.//Dimension')
315
315
  assert len(xml_dims) == len(dims)
316
316
  assert [xml_dim.attrib['start'] for xml_dim in xml_dims] == dims
317
+
318
+
319
+ @pytest.mark.requirements("numpy")
320
+ @pytest.mark.parametrize("name,start,dims", [
321
+ ("array1", [1.,2.,3.,4.], [4]),
322
+ ("array2", [1.,2.,3.,4.], [2, 2])
323
+ ])
324
+ def test_array_output_to_xml(name, start, dims):
325
+ import numpy as np
326
+ start = np.reshape(start, newshape=dims)
327
+ r = Float64(name, start, dimensions=[Dimension(start=val) for val in dims], causality=Fmi3Causality.output)
328
+ xml = r.to_xml()
329
+ print(xml, start)
330
+ if start is not None:
331
+ assert xml.attrib['start'] == " ".join([f"{val:.16g}" for val in flatten(start)])
332
+ if dims is not None:
333
+ xml_dims = xml.findall('.//Dimension')
334
+ assert len(xml_dims) == len(dims)
335
+ assert [xml_dim.attrib['start'] for xml_dim in xml_dims] == dims
pythonfmu3/variables.py CHANGED
@@ -4,11 +4,19 @@ from enum import Enum
4
4
  import importlib
5
5
  from typing import Any, Optional, List
6
6
  from xml.etree.ElementTree import Element, SubElement
7
+ from collections.abc import Iterable
7
8
  from collections import ChainMap
8
9
  from functools import reduce
9
10
 
10
11
  from .enums import Fmi3Causality, Fmi3Initial, Fmi3Variability
11
12
 
13
+ def flatten(lst):
14
+ for item in lst:
15
+ if isinstance(item, Iterable) and not isinstance(item, (str, bytes)):
16
+ yield from flatten(item)
17
+ else:
18
+ yield item
19
+
12
20
  def check_numpy():
13
21
  try:
14
22
  importlib.import_module('numpy')
@@ -210,7 +218,7 @@ class Float64(ModelVariable):
210
218
  # stored on an XML file with at least 16 significant digits
211
219
  output = ""
212
220
  if len(self.dimensions) > 0:
213
- output = " ".join([f"{val:.16g}" for val in value])
221
+ output = " ".join([f"{val:.16g}" for val in flatten(value)])
214
222
  else:
215
223
  output = f"{value:.16g}"
216
224
  attrib[key] = output
@@ -2,6 +2,7 @@ MIT License
2
2
 
3
3
  Copyright (c) 2019-2020 NTNU - Department of Ocean Operations and Civil Engineering
4
4
  Copyright (c) 2019-2020 Safran SA
5
+ Copyright (c) 2023 Stephen Smith
5
6
 
6
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
8
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pythonfmu3
3
- Version: 0.1.18
3
+ Version: 0.2.1
4
4
  Summary: A lightweight framework that enables the packaging of Python3.x code as co-simulation FMUs.
5
5
  Home-page: https://github.com/stephensmith25/PythonFMU3
6
6
  Author: Stephen Smith
@@ -1,6 +1,6 @@
1
1
  pythonfmu3/__init__.py,sha256=oN-2oXyCFwq0gvL2IEf5QvwIXBXZgsSBwAJw7LZ9vzc,424
2
2
  pythonfmu3/__main__.py,sha256=gC1T8x2d02hhqshyNQGSS70SyCk-3I3t8zPqoRo2Xd8,1543
3
- pythonfmu3/_version.py,sha256=6BiuMUkhwQp6bzUZSF8np8F1NwCltEtK0sPBF__tepU,23
3
+ pythonfmu3/_version.py,sha256=HfjVOrpTnmZ-xVFCYSVmX50EXaBQeJteUHG-PD6iQs8,22
4
4
  pythonfmu3/builder.py,sha256=d_nTRWKohZrZsMbTmxiYJzszzVBp-CRisV_y_OVyW6U,9779
5
5
  pythonfmu3/default_experiment.py,sha256=FJ0l0FpU7pT4Pox2RiA2y-Cb_e7DE2XlbWKySRYQaVk,293
6
6
  pythonfmu3/deploy.py,sha256=eqFWVxZUkJCLvmq1-GuMNjn2j0VCGoaXPhRWrCk2Vxg,3741
@@ -10,12 +10,12 @@ pythonfmu3/logmsg.py,sha256=0wn11GLwq0LLWqyC2ktLRjQFWlpj07wWliZ8rUHx1gg,359
10
10
  pythonfmu3/osutil.py,sha256=1qN6qudN4zCupZwc15pzp52WObkqi6jGy9a-MehNt9Q,656
11
11
  pythonfmu3/unit.py,sha256=SjOaywb5lVQbAO_iLjc_7Ly3nYrmAvIW2_hAGt12UFU,1475
12
12
  pythonfmu3/variable_types.py,sha256=Q0D4wlGi3i3zE5UsmGJEpNh7SV_W8mn_8p_WIkwrLQA,2881
13
- pythonfmu3/variables.py,sha256=hwYT6AfaSQIa1egVJrOxnDi5NEj1bk_VkQd9-hsoDII,11905
13
+ pythonfmu3/variables.py,sha256=6el55sAn8miVqPeUY-Q3GEw_pt6c46p7obg6G2UjyeA,12143
14
14
  pythonfmu3/pythonfmu-export/.clang-format,sha256=ApbsHWYwilCXJ1iBux4nqOjLkaqgbGLsVrc_U3hX7WI,944
15
15
  pythonfmu3/pythonfmu-export/CMakeLists.txt,sha256=p0-4Xh_sAaOI9AVb8lsUsMxJPc6bg9b_6CF6NJt5FHE,1847
16
16
  pythonfmu3/pythonfmu-export/build_unix.sh,sha256=I5RrF2O6y0hRG_SN4ExKN_CCFYaa2l-ngKzqmBXnHmA,73
17
17
  pythonfmu3/pythonfmu-export/build_win.sh,sha256=UzmAcWqFmwBu6mvYne2Dx3UK8iPwTtP4HpjICsjUaJA,97
18
- pythonfmu3/pythonfmu-export/src/CMakeLists.txt,sha256=RyjGhUUDhG_HEieCdt5WMfTR1snofOqigEKc83_zvfE,1104
18
+ pythonfmu3/pythonfmu-export/src/CMakeLists.txt,sha256=fOVlV7hy9c0wx_Qp4K51tQaQ5xy9lL4qtyGl15ZXfGs,1208
19
19
  pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_common.hpp,sha256=cgrlZa5L-bbjZeVi0pmy4JKE5UJ2GszzuyOqTdRcBRQ,4353
20
20
  pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_cs.cpp,sha256=EsUIevwmCzX9hsui3i8x1crSnSOG8dEK15Zm1ZIavYQ,3843
21
21
  pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_cs.hpp,sha256=UmqAVAVE1KHNHMC8mIh8gIHRJ_aQk0Ma139TU6Kvv4o,6264
@@ -24,11 +24,11 @@ pythonfmu3/pythonfmu-export/src/fmi/fmi3FunctionTypes.h,sha256=Tk1WY0nAYBGiOAQ8z
24
24
  pythonfmu3/pythonfmu-export/src/fmi/fmi3Functions.h,sha256=NsHuclp20wcuUInYf-91UXZbljTeu2cPXENqNEORdgU,16262
25
25
  pythonfmu3/pythonfmu-export/src/fmi/fmi3PlatformTypes.h,sha256=ZCQLJgSbRGrMsBiQ4auaYCY4J3Hck6g3t1iZp5NEguw,4251
26
26
  pythonfmu3/pythonfmu-export/src/pythonfmu/IPyState.hpp,sha256=GLiOjhKLDVEICersnqVwezwEshbxfdh_cyMxBJGFbu8,456
27
- pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.cpp,sha256=MpEUUcxPwoJlM_mW-9qxj4ezgKQd-CkDc2ud0mM7HbQ,25362
27
+ pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.cpp,sha256=WShZMdZExWWG86kFPh89mATYK4tVn38JdHV6c-fZ0_A,25411
28
28
  pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.hpp,sha256=T-epGp68SjhDv-JupxUe2ZgnV8unU4htc-PUBokjWm4,4239
29
29
  pythonfmu3/pythonfmu-export/src/pythonfmu/PyState.hpp,sha256=CjFEIrZu8b1jxQAIgfI_o36hyItW_SdQ5VSkImf7JNs,2977
30
- pythonfmu3/resources/binaries/x86_64-linux/libpythonfmu-export.so,sha256=LLTlb6TDjJ24xuy7zhO5Sbj39nVzQSODkkXMXGl8Y7s,365224
31
- pythonfmu3/resources/binaries/x86_64-windows/pythonfmu-export.dll,sha256=wi2jjGlTgRz5Gi8YNZsi4xoEzrxKO4UE7xVT0nBZViY,430592
30
+ pythonfmu3/resources/binaries/x86_64-linux/libpythonfmu-export.so,sha256=H-9BRLDmS-TfSGi6lOYvMIYEI3_tTcsBBuMMUYWt-IA,365288
31
+ pythonfmu3/resources/binaries/x86_64-windows/pythonfmu-export.dll,sha256=IFUevR81xjzf5silpT0Qbz4ybMCtktIOu9Z3jBGTpoE,431104
32
32
  pythonfmu3/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
33
  pythonfmu3/tests/conftest.py,sha256=B6XxTnBdeF_tEJ3w2DlfPKUfvlk-oULgIhQtXkgOJIc,171
34
34
  pythonfmu3/tests/test_builder.py,sha256=GrD4ziin3RLOe_36rBQCMnKrSkhc3IqnxE1a6kCFPok,6842
@@ -37,7 +37,7 @@ pythonfmu3/tests/test_fmi3slave.py,sha256=1uwTdfiFZNmU0yzIdC30kAuu95xsZSTMA9CGk_
37
37
  pythonfmu3/tests/test_integration.py,sha256=zA3iJ4rI2cKEE8mDsAmcVuwNWlJzhonV8Wxz92hzEac,10387
38
38
  pythonfmu3/tests/test_logger.py,sha256=OcHQhxUtNBPH-0zdmheC4I9OWz1yu48W8MYDshNVkf8,5765
39
39
  pythonfmu3/tests/test_multiple_fmus.py,sha256=-sthCm2YUZiRkdfvpLQNgquPBForUKQ7HGqfFBdrRas,3942
40
- pythonfmu3/tests/test_variables.py,sha256=t4r2TBruf58uYwjkp3r-RcZS5TrsOaVT_mDuoiUTQtg,9598
40
+ pythonfmu3/tests/test_variables.py,sha256=avy1mzVOBmoVPrxLOLZy5stgKy415CPtTxrLdbSkyHU,10352
41
41
  pythonfmu3/tests/utils.py,sha256=WusWSUGoBPenZL-FAKQlzaHN2aYXiznZM2fwCjoldwY,301
42
42
  pythonfmu3/tests/data/csvdemo.csv,sha256=TiTUyzHyjQNXM4eXI33oJipc7w9_PJ8aMejRmwc52Xw,256
43
43
  pythonfmu3/tests/data/hello.txt,sha256=wFNeS-K3n_2TKRMFQ2v4iTFOSj-uwF7P_Lt98xrZ5Ro,12
@@ -46,9 +46,9 @@ pythonfmu3/tests/slaves/localmodule.py,sha256=-q5Lmh2I88MG7nLTscms0n5xhHLkUDed1I
46
46
  pythonfmu3/tests/slaves/pythonslave.py,sha256=uzrTQmfk0QBalxNTviGMZNph_YgVmcbxPqKgX5rSvXg,2172
47
47
  pythonfmu3/tests/slaves/pythonslave_read_file.py,sha256=t2sDaZSr2veD91gdqCO9W9CN-AN3TyXABXXfV9Rt0Xs,791
48
48
  pythonfmu3/tests/slaves/slavewithdep.py,sha256=hHDFB0dw8wkHiGzxeAVbz9O5LR6ghsFeONgRFdiK_t0,812
49
- pythonfmu3-0.1.18.dist-info/LICENSE,sha256=24Cw_MPouLK-G_t8Hgjm59IS9BnPoL6SKkyuZ0xesXY,1155
50
- pythonfmu3-0.1.18.dist-info/METADATA,sha256=FKgLxqU6YXlmXZaZSKkQVd7zxxMP-Dz86QJND8BehKA,7586
51
- pythonfmu3-0.1.18.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
52
- pythonfmu3-0.1.18.dist-info/entry_points.txt,sha256=GgkWYs0DKGHLcijMEYZGkhkHOK2RVUpjGwvl1fwyDwQ,60
53
- pythonfmu3-0.1.18.dist-info/top_level.txt,sha256=6ne7bh_cME1hepxCx1BG8N5QVhVAufrp7LLok6vq7nE,11
54
- pythonfmu3-0.1.18.dist-info/RECORD,,
49
+ pythonfmu3-0.2.1.dist-info/LICENSE,sha256=RL2018BU2DKcTi8Eb4ODF-XF3wnr7SDKvMP5S49x4rQ,1188
50
+ pythonfmu3-0.2.1.dist-info/METADATA,sha256=zH3gg6qM81thMX4mmzFqVxCoAnRuDLtj1-wZwoFTuqA,7585
51
+ pythonfmu3-0.2.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
52
+ pythonfmu3-0.2.1.dist-info/entry_points.txt,sha256=GgkWYs0DKGHLcijMEYZGkhkHOK2RVUpjGwvl1fwyDwQ,60
53
+ pythonfmu3-0.2.1.dist-info/top_level.txt,sha256=6ne7bh_cME1hepxCx1BG8N5QVhVAufrp7LLok6vq7nE,11
54
+ pythonfmu3-0.2.1.dist-info/RECORD,,