Skip to content

Commit

Permalink
Merge branch 'release/v0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer committed Jul 21, 2021
2 parents 439e0ea + 4706d05 commit 69ec438
Show file tree
Hide file tree
Showing 48 changed files with 2,720 additions and 2,102 deletions.
7 changes: 6 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
variables:
- name: create_environment
value: conda create --yes --quiet --name py37 -c conda-forge python=3.7 dask ipython=7 lark-parser lxml matplotlib notebook numpy plotly pyqt pyqtgraph pytest-cov requests scipy
value: conda create --yes --quiet --name py37 -c conda-forge python=3.7 attrs dask ipython=7 lark-parser lxml matplotlib notebook numpy plotly pyqt pyqtgraph pytest-cov requests scipy

jobs:

Expand All @@ -25,6 +25,11 @@ jobs:
python build_fmucontainer.py
displayName: Build FMU Container
- bash: |
source activate py37
python build_remoting.py
displayName: Build remoting binaries
- bash: |
source activate py37
python setup.py bdist_wheel --universal
Expand Down
182 changes: 109 additions & 73 deletions build_remoting.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,115 @@
from fmpy import sharedLibraryExtension, extract
from fmpy.util import download_file
import os
import tarfile
import shutil
from subprocess import check_call
from fmpy.util import download_file


url = 'https://github.com/rpclib/rpclib/archive/refs/tags/v2.3.0.tar.gz'
checksum = 'eb9e6fa65e1a79b37097397f60599b93cb443d304fbc0447c50851bc3452fdef'

# build configuration
config = 'Release'

download_file(url, checksum)

filename = os.path.basename(url)

basedir = os.path.abspath(os.path.dirname(__file__))

source_dir = 'rpclib-2.3.0'

rpclib_dir = os.path.join(basedir, source_dir).replace('\\', '/')

# clean up
for p in ['rpclib-2.2.1', 'remoting/client/build', 'remoting/server/build']:
if os.path.exists(p):
shutil.rmtree(p)

for f in ['fmpy/remoting/client.dll', 'fmpy/remoting/server.exe']:
if os.path.exists(f):
os.remove(f)

rpclib_url = 'https://github.com/rpclib/rpclib/archive/v2.2.1.zip'
rpclib_checksum = '70f10b59f0eb303ccee4a9dda32e6ed898783be9a539d32b43e6fcb4430dce0c'
rpclib_filename = os.path.basename(rpclib_url)

download_file(rpclib_url, rpclib_checksum)

extract(rpclib_filename, '.')

# root = os.path.dirname(__file__)

# build RPCLIB for win32
check_call([
'cmake',
'-DCMAKE_INSTALL_PREFIX=rpclib-2.2.1/win32/install',
'-DRPCLIB_MSVC_STATIC_RUNTIME=ON',
'-G', 'Visual Studio 15 2017',
'-S', 'rpclib-2.2.1',
'-B', 'rpclib-2.2.1/win32'
])

check_call(['cmake', '--build', 'rpclib-2.2.1/win32', '--target', 'install', '--config', 'Release'])

# build RPCLIB for win64
check_call([
'cmake',
'-DCMAKE_INSTALL_PREFIX=rpclib-2.2.1/win64/install',
'-DRPCLIB_MSVC_STATIC_RUNTIME=ON',
'-G', 'Visual Studio 15 2017 Win64',
'-S', 'rpclib-2.2.1',
'-B', 'rpclib-2.2.1/win64'
])

check_call(['cmake', '--build', 'rpclib-2.2.1/win64', '--target', 'install', '--config', 'Release'])

print('####' + str([
'cmake',
'-DRPCLIB=' + os.path.abspath('rpclib-2.2.1/win32/install').replace('\\', '/'),
'-G', 'Visual Studio 15 2017',
'-S', 'remoting/server',
'-B', 'remoting/server/build'
]))

# build server.exe
check_call([
'cmake',
'-DRPCLIB=' + os.path.abspath('rpclib-2.2.1/win32/install').replace('\\', '/'),
'-G', 'Visual Studio 15 2017',
'-S', 'remoting/server',
'-B', 'remoting/server/build'
])

check_call(['cmake', '--build', 'remoting/server/build', '--config', 'Release'])

# build client.exe
check_call([
'cmake',
'-DRPCLIB=' + os.path.abspath('rpclib-2.2.1/win64/install').replace('\\', '/'),
'-G', 'Visual Studio 15 2017 Win64',
'-S', 'remoting/client',
'-B', 'remoting/client/build'
])

check_call(['cmake', '--build', 'remoting/client/build', '--config', 'Release'])
shutil.rmtree(source_dir, ignore_errors=True)

print("Extracting %s" % filename)
with tarfile.open(filename, 'r:gz') as tar:
tar.extractall()

if os.name == 'nt':

# patch the CMake project to link static against the MSVC runtime
with open(os.path.join(source_dir, 'CMakeLists.txt'), 'a') as file:
# Append 'hello' at the end of file
file.write('''
message(${CMAKE_CXX_FLAGS_RELEASE})
message(${CMAKE_CXX_FLAGS_DEBUG})
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
message(${CMAKE_CXX_FLAGS_RELEASE})
message(${CMAKE_CXX_FLAGS_DEBUG})
''')

for bitness, generator in [('win32', 'Visual Studio 15 2017'), ('win64', 'Visual Studio 15 2017 Win64')]:

# clean up
shutil.rmtree(os.path.join(basedir, 'remoting', bitness), ignore_errors=True)

print("Building rpclib...")

check_call(args=[
'cmake',
'-B', source_dir + '/' + bitness,
'-D', 'RPCLIB_MSVC_STATIC_RUNTIME=ON',
'-D', 'CMAKE_INSTALL_PREFIX=' + source_dir + '/' + bitness + '/install',
'-G', generator,
source_dir
])

check_call(args=['cmake', '--build', source_dir + '/' + bitness, '--target', 'install', '--config', config])

print("Building remoting binaries...")

check_call(args=[
'cmake',
'-B', 'remoting/' + bitness,
'-G', generator,
'-D', 'RPCLIB=' + rpclib_dir + '/' + bitness + '/install',
'-B', 'remoting/' + bitness, 'remoting'
])

check_call(['cmake', '--build', 'remoting/' + bitness, '--config', config])

else:

# clean up
shutil.rmtree(os.path.join(basedir, 'remoting', 'linux64'), ignore_errors=True)

print("Building rpclib...")

check_call(args=[
'cmake',
'-B', source_dir + '/linux64',
'-D', 'CMAKE_INSTALL_PREFIX=' + source_dir + '/linux64' + '/install',
'-D', 'CMAKE_POSITION_INDEPENDENT_CODE=ON',
'-G', 'Unix Makefiles',
source_dir
])

check_call(args=['cmake', '--build', source_dir + '/linux64', '--target', 'install', '--config', config])

print("Building remoting binaries...")

check_call(args=[
'cmake',
'-B', 'remoting/' + 'linux64',
'-G', 'Unix Makefiles',
'-D', 'RPCLIB=' + rpclib_dir + '/linux64/install',
'-B', 'remoting/linux64', 'remoting'
])

check_call(['cmake', '--build', 'remoting/linux64', '--config', config])
25 changes: 25 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
## v0.3.1 (2021-07-21)

### Bug fixes

- Fix type hint for parameter "input" in "simulate_fmu()" (#286)
- Set output arguments in fmi3.intermediateUpdate() (#273)
- Allow fixed and tunable structural parameters (#268)
- Fix model structure of Container FMU (#267)
- Add missing parameter "nValues" to getString() and getBinary() and decode byte strings (#263)
- Set stop time and handle negative start time in (#261)

### Enhancements

- Update FMI 3.0 API to v3.0-beta.2
- Offer to open generated Jupyter notebook in GUI (#262)
- Add arguments of fmu_info() to dump() enhancement (#285)
- Improve Plotly plots of discrete signals (#284)
- Define variables of Container FMU independent of inner FMUs (#265)
- Validate that initial is not set for input and independent variables (#280)
- Return filename from fmpy.util.download_file() (#267)
- Add win64 on linux64 remoting w/ wine and linux64 on win64 remoting w/ WSL (experimental)
- Assert mandatory independent variable in FMI 3.0 (#272)
- Define model description classes with @attrs (#275)
- Detect drive letter in fmuResourceLocation on Windows

## v0.3.0 (2021-04-20)

This release drops Python 2.7 support. The minimum required version is now Python 3.5.
Expand Down
12 changes: 7 additions & 5 deletions fmpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import os
from ctypes import *
import _ctypes
from typing import Union, IO, List

__version__ = '0.3.0'
__version__ = '0.3.1'

# experimental
plot_library = 'matplotlib' # 'plotly'
Expand Down Expand Up @@ -61,7 +62,7 @@
platform_tuple = architecture + '-' + system


def supported_platforms(filename):
def supported_platforms(filename: Union[str, IO]):
""" Get the platforms supported by the FMU without extracting it
Parameters:
Expand Down Expand Up @@ -206,15 +207,16 @@ def extract(filename, unzipdir=None, include=None):
return unzipdir


def dump(filename):
def dump(filename: Union[str, IO], causalities: List[str] = ['input', 'output']):
""" Print the model information and variables of an FMU
Parameters:
filename filename of the FMU
filename filename of the FMU
causalities the causalities of the variables to include
"""

from .util import fmu_info
print(fmu_info(filename))
print(fmu_info(filename=filename, causalities=causalities))


# make the functions available in the fmpy module
Expand Down
12 changes: 8 additions & 4 deletions fmpy/c-code/fmi3FunctionTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "fmi3PlatformTypes.h"

/*
This header file defines the data and function types of FMI 3.0-beta.1.
This header file defines the data and function types of FMI 3.0-beta.2.
It must be used when compiling an FMU or an FMI importer.
Copyright (C) 2011 MODELISAR consortium,
Expand Down Expand Up @@ -127,7 +127,7 @@ typedef fmi3Status fmi3SetDebugLoggingTYPE(fmi3Instance instance,
typedef fmi3Instance fmi3InstantiateModelExchangeTYPE(
fmi3String instanceName,
fmi3String instantiationToken,
fmi3String resourceLocation,
fmi3String resourcePath,
fmi3Boolean visible,
fmi3Boolean loggingOn,
fmi3InstanceEnvironment instanceEnvironment,
Expand All @@ -136,7 +136,7 @@ typedef fmi3Instance fmi3InstantiateModelExchangeTYPE(
typedef fmi3Instance fmi3InstantiateCoSimulationTYPE(
fmi3String instanceName,
fmi3String instantiationToken,
fmi3String resourceLocation,
fmi3String resourcePath,
fmi3Boolean visible,
fmi3Boolean loggingOn,
fmi3Boolean eventModeUsed,
Expand All @@ -150,7 +150,7 @@ typedef fmi3Instance fmi3InstantiateCoSimulationTYPE(
typedef fmi3Instance fmi3InstantiateScheduledExecutionTYPE(
fmi3String instanceName,
fmi3String instantiationToken,
fmi3String resourceLocation,
fmi3String resourcePath,
fmi3Boolean visible,
fmi3Boolean loggingOn,
const fmi3ValueReference requiredIntermediateVariables[],
Expand Down Expand Up @@ -514,6 +514,10 @@ typedef fmi3Status fmi3SetIntervalFractionTYPE(fmi3Instance instance,
size_t nIntervals);
/* end::SetIntervalFraction[] */

/* tag::EvaluateDiscreteStates[] */
typedef fmi3Status fmi3EvaluateDiscreteStatesTYPE(fmi3Instance instance);
/* end::EvaluateDiscreteStates[] */

/* tag::UpdateDiscreteStates[] */
typedef fmi3Status fmi3UpdateDiscreteStatesTYPE(fmi3Instance instance,
fmi3Boolean* discreteStatesNeedUpdate,
Expand Down
Loading

0 comments on commit 69ec438

Please sign in to comment.