Skip to content

Commit

Permalink
Merge branch 'master' into feature/ecco
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/cosim/osp_config_parser.cpp
  • Loading branch information
restenb committed Oct 17, 2023
2 parents 458119a + 9dff0ad commit 76d438c
Show file tree
Hide file tree
Showing 23 changed files with 476 additions and 205 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ jobs:
name: CMake
runs-on: ${{ matrix.os }}
env:
CC: gcc-${{ matrix.compiler_version }}
CC: gcc-${{ matrix.compiler_version }}
CXX: g++-${{ matrix.compiler_version }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04]
os: [ubuntu-20.04]
build_type: [Debug, Release]
compiler_version: [7]
compiler_version: [9]
shared_libs: [ON, OFF]
timeout-minutes: 35

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install prerequisites
run: |
sudo apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
cmake --build build --target install
cmake --build build --target install-doc
- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: libcosim-${{ runner.os }}-${{ matrix.build_type }}-gcc${{ matrix.compiler_version }}
path: install
Expand All @@ -79,11 +79,11 @@ jobs:
timeout-minutes: 35

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install prerequisites
run: |
pip3 install --upgrade setuptools pip
pip3 install conan
pip3 install conan==1.59
choco install doxygen.install
conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force
conan install . -s build_type=${{ matrix.build_type }} -o shared=${{ matrix.shared }} -g deploy
Expand All @@ -110,7 +110,7 @@ jobs:
cmake --build build --config ${{ matrix.build_type }} --target install
cmake --build build --config ${{ matrix.build_type }} --target install-doc
- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: libcosim-${{ runner.os }}-${{ matrix.build_type }}
path: install
8 changes: 4 additions & 4 deletions .github/workflows/ci-conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
fail-fast: false
matrix:
build_type: [Debug, Release]
compiler_version: [7, 8, 9]
compiler_version: [9]
compiler_libcxx: [libstdc++11]
option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False']
option_shared: ['shared=True', 'shared=False']
timeout-minutes: 35

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Generate Dockerfile
run: |
mkdir /tmp/osp-builder-docker
Expand Down Expand Up @@ -81,11 +81,11 @@ jobs:
timeout-minutes: 35

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install prerequisites
run: |
pip3 install --upgrade setuptools pip
pip3 install conan
pip3 install conan==1.59
- name: Configure Conan
run: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force
- name: Conan create
Expand Down
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ All notable changes to libcosim will be documented in this file. This includes n

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

### [v0.10.2] - 2023-02-08
##### Fixed
* Update to proxyfmu 0.3.1 due to a disconnection issue related to Thrift.

### [v0.10.1] - 2022-12-08
##### Changed
* Update to proxyfmu 0.3.0 due to downstream build issues related to Thrift.

### [v0.10.0] - 2022-12-02
##### Changed
* GCC7 and GCC8 artifact builds have been removed, and GCC9 artifact builds added. This is currently the only supported GCC version.
* The file observer is now programmatically configurable, and there is no longer a need for clients to create a separate `LogConfig.xml` file upfront to specify it's configuration.
* The file observer no longer outputs headers as `variable name [reference, type, causality].` Instead only the variable name is output, and the extra data about each variable and the model itself is output in a separate metadata file, in YAML format. This will have the same filename as the CSV file with the simulation data, including the timestamp, with `_metadata` at the end.
* Using `find_variable` no longer throws an exception, but rather returns an optional value, which may be empty if the variable could not be found.
* Update to proxyfmu 0.2.9.
##### Added
* An asynchronous version of `simulate_until` is now available through the `execution` interface. This accepts
an optional end time parameter and launches the execution in a new thread.
* Support has been added for optionally specifying simulation end time (where only start time was supported) in `OspSystemStructure.xml`. If specified, end time will also be parsed and made available in the simulation configuration.
##### Fixed

### [v0.9.0] – 2022-04-05
##### Changed
* Removed fibers to simplify code and increase simulation performance. Concurrency must now be implemented in the master
Expand Down Expand Up @@ -160,7 +181,7 @@ algorithm, and `fixed_step_algorithm` has been modified to use a thread pool. ([
* introducing`orchestration` interface for classes that resolve model URIs of one or more specific URI schemes ([PR#233](https://github.com/open-simulation-platform/cse-core/pull/233))
* logging configuration ([PR#247](https://github.com/open-simulation-platform/cse-core/pull/247))
* observers can observe string and boolean variables ([PR#257](https://github.com/open-simulation-platform/cse-core/pull/257))
* can set arbitraty real time factor ([PR#261](https://github.com/open-simulation-platform/cse-core/pull/261))
* can set arbitrary real time factor ([PR#261](https://github.com/open-simulation-platform/cse-core/pull/261))
* improved error reporting

##### Fixed
Expand Down Expand Up @@ -193,3 +214,6 @@ First OSP JIP partner release
[v0.8.2]: https://github.com/open-simulation-platform/cse-core/compare/v0.8.1...v0.8.2
[v0.8.3]: https://github.com/open-simulation-platform/cse-core/compare/v0.8.2...v0.8.3
[v0.9.0]: https://github.com/open-simulation-platform/cse-core/compare/v0.8.3...v0.9.0
[v0.10.0]: https://github.com/open-simulation-platform/cse-core/compare/v0.9.0...v0.10.0
[v0.10.1]: https://github.com/open-simulation-platform/cse-core/compare/v0.10.0...v0.10.1
[v0.10.2]: https://github.com/open-simulation-platform/cse-core/compare/v0.10.1...v0.10.2
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ set(LIBCOSIM_EXPORT_TARGET "${PROJECT_NAME}-targets")
# ==============================================================================

if(LIBCOSIM_USING_CONAN)

if(NOT LIBCOSIM_USING_CONAN_AUTO_CONFIG OR CONAN_EXPORTED)
# Opting for manual invocation of conan install prior to loading CMake
# or conan create has been invoked, setting CONAN_EXPORTED.
Expand Down Expand Up @@ -163,7 +162,6 @@ endif()
# ==============================================================================

add_subdirectory("src")
add_subdirectory("tools/osp-xsd-embedder")
if(LIBCOSIM_BUILD_TESTS)
enable_testing()
add_subdirectory("tests")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ in the section below or you can use conan. As libcosim is made available as a
conan package on https://osp.jfrog.io, you can include it in your application
following these steps:

* Install [Conan]
* Install [Conan] version 1.x
* Add the OSP Conan repository as a remote:

conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local
Expand All @@ -38,7 +38,7 @@ How to build
* Compilers: [Visual Studio] >= 16.0/2019 (Windows), GCC >= 7 (Linux)
* Build tool: [CMake]
* API documentation generator (optional): [Doxygen]
* Package manager (optional): [Conan]
* Package manager (optional): [Conan] 1.x

Throughout this guide, we will use Conan to manage dependencies. However, it
should be possible to use other package managers as well, such as [vcpkg], and
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def configure(self):

def requirements(self):
if self.options.proxyfmu:
self.requires("proxyfmu/0.2.7@osp/stable")
self.requires("proxyfmu/0.3.1@osp/stable")

def imports(self):
binDir = os.path.join("output", str(self.settings.build_type).lower(), "bin")
Expand Down
1 change: 1 addition & 0 deletions data/xsd/OspSystemStructure.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<xs:complexType>
<xs:sequence>
<xs:element name="StartTime" minOccurs="0" default="0.0" type="xs:double"/>
<xs:element name="EndTime" minOccurs="0" type="xs:double"/>
<xs:element name="BaseStepSize" minOccurs="0" type="xs:double"/>
<xs:element name="Algorithm" minOccurs="0" default="fixedStep" type="xs:string"/>
<xs:element name="Simulators" type="osp:simulators"/>
Expand Down
93 changes: 85 additions & 8 deletions include/cosim/observer/file_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <cosim/fs_portability.hpp>
#include <cosim/observer/observer.hpp>

#include <boost/property_tree/ptree.hpp>

#include <atomic>
#include <memory>
#include <unordered_map>
Expand All @@ -23,6 +21,86 @@
namespace cosim
{

class file_observer;

/**
* Configuration options for file_observer.
*/
class file_observer_config
{
public:
file_observer_config() = default;

/**
* Specify whether or not generated .csv files should be timestamped
*
* \param flag timestamped if true (default)
* \return self
*/
file_observer_config& set_timestamped_filenames(bool flag)
{
timeStampedFileNames_ = flag;
return *this;
}

/**
* Specify variables for a simulator to log
*
* \param simulatorName name of simulator to log
* \param variableNames a list of variable names to log (empty list means log all variables)
* \param decimationFactor optional decimation factor, where 1 (default) means log every step
* \return self
*/
file_observer_config& log_simulator_variables(
const std::string& simulatorName,
const std::vector<std::string>& variableNames,
std::optional<size_t> decimationFactor = std::nullopt)
{
variablesToLog_[simulatorName].first = decimationFactor.value_or(defaultDecimationFactor_);
for (const auto& variableName : variableNames) {
variablesToLog_[simulatorName].second.emplace_back(variableName);
}
return *this;
}

/**
* Specify that we want to log all variables for a given simulator
*
* \param simulatorName name of simulator to log
* \param variableNames a list of variable names to log (empty list means log all variables)
* \param decimationFactor optional decimation factor, where 1 (default) means log every step
* \return self
*/
file_observer_config& log_all_simulator_variables(
const std::string& simulatorName,
std::optional<size_t> decimationFactor = std::nullopt)
{
variablesToLog_[simulatorName].first = decimationFactor.value_or(defaultDecimationFactor_);
variablesToLog_[simulatorName].second = {}; // empty variable means log all
return *this;
}

/**
* Creates a file_observer_config from an xml configuration
*
* \param configPath the path to an xml file containing the logging configuration.
* \return a file_observer_config
*/
static file_observer_config parse(const filesystem::path& configPath);

private:
bool timeStampedFileNames_{true};
size_t defaultDecimationFactor_{1};
std::unordered_map<std::string, std::pair<size_t, std::vector<std::string>>> variablesToLog_;

[[nodiscard]] bool should_log_simulator(const std::string& name) const
{
return variablesToLog_.count(name);
}

friend class file_observer;
};


/**
* An observer implementation, for saving observed variable values to file in csv format.
Expand All @@ -36,8 +114,9 @@ class file_observer : public observer
* Creates an observer which logs all variable values to file in csv format.
*
* \param logDir the directory where log files will be created.
* \param config an optional logging configuration.
*/
file_observer(const cosim::filesystem::path& logDir);
explicit file_observer(const cosim::filesystem::path& logDir, std::optional<file_observer_config> config = std::nullopt);

/**
* Creates an observer which logs selected variable values to file in csv format.
Expand Down Expand Up @@ -108,14 +187,12 @@ class file_observer : public observer
class slave_value_writer;
std::unordered_map<simulator_index, std::unique_ptr<slave_value_writer>> valueWriters_;
std::unordered_map<simulator_index, observable*> simulators_;
boost::property_tree::ptree ptree_;
cosim::filesystem::path configPath_;
std::optional<file_observer_config> config_;
cosim::filesystem::path logDir_;
bool logFromConfig_ = false;
size_t defaultDecimationFactor_ = 1;
std::atomic<bool> recording_ = true;
};


} // namespace cosim
#endif // header guard

#endif // COSIM_OBSERVER_FILE_OBSERVER_HPP
3 changes: 3 additions & 0 deletions include/cosim/osp_config_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ struct osp_config
/// The default start time for a simulation
time_point start_time;

/// The optional end time for a simulation
std::optional<time_point> end_time = std::nullopt;

/// The default/recommended step size for a simulation
duration step_size;

Expand Down
17 changes: 7 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,13 @@ foreach(src IN LISTS generatedSources)
list(APPEND generatedFiles "${tgt}")
endforeach()

# Generate header file from OSP XSD
set(ospSystemStructureXSD "${CMAKE_SOURCE_DIR}/data/xsd/OspSystemStructure.xsd")
set(ospSystemStructureHeader "${generatedSourcesDir}/osp_system_structure_schema.hpp")
add_custom_command(
OUTPUT "${ospSystemStructureHeader}"
COMMAND osp-xsd-embedder "${ospSystemStructureXSD}" "${ospSystemStructureHeader}"
DEPENDS osp-xsd-embedder "${ospSystemStructureXSD}"
)
list(APPEND generatedFiles "${ospSystemStructureHeader}")
function(make_includable input_file output_file)
file(READ ${input_file} content)
set(content "const char* osp_xsd=R\"(${content})\";")
file(WRITE ${output_file} "${content}")
endfunction(make_includable)

make_includable("${CMAKE_SOURCE_DIR}/data/xsd/OspSystemStructure.xsd" "${generatedSourcesDir}/osp_system_structure_schema.hpp")

# ==============================================================================
# Target definition
Expand All @@ -159,7 +156,7 @@ endforeach()

add_library(cosim ${publicHeadersFull} ${privateHeaders} ${sources} ${generatedFiles})

target_compile_definitions(cosim PUBLIC "BOOST_ALL_NO_LIB=0" "BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE=1")
target_compile_definitions(cosim PUBLIC "BOOST_ALL_NO_LIB" "BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE=1")
if(NOT Boost_USE_STATIC_LIBS)
target_compile_definitions(cosim PUBLIC "BOOST_ALL_DYN_LINK=1")
endif()
Expand Down
Loading

0 comments on commit 76d438c

Please sign in to comment.