Skip to content

Commit 01eeb65

Browse files
authored
Merge branch 'main' into test-sparse
2 parents bbac8d8 + 6c9605a commit 01eeb65

38 files changed

+447
-344
lines changed

.github/workflows/build-test-release.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
steps:
3434
- uses: actions/checkout@v5
3535

36-
- uses: actions/setup-python@v5
36+
- uses: actions/setup-python@v6
3737
with:
3838
python-version: "3.13"
3939

@@ -260,9 +260,15 @@ jobs:
260260
conda info
261261
conda list
262262
263-
- uses: ./.github/actions/enable-msvc
263+
- name: Enable MSVC
264+
uses: ./.github/actions/enable-msvc
264265
if: runner.os == 'Windows'
265266

267+
- name: Enable gcc/g++
268+
if: matrix.os == 'ubuntu'
269+
run: |
270+
conda install -y gcc_linux-64 gxx_linux-64
271+
266272
- name: Build and install cmake target for Windows
267273
if: matrix.os == 'windows'
268274
run: |
@@ -302,7 +308,7 @@ jobs:
302308
- uses: actions/checkout@v5
303309

304310
- name: Setup python
305-
uses: actions/setup-python@v5
311+
uses: actions/setup-python@v6
306312
with:
307313
python-version: '3.12'
308314
architecture: x64

.github/workflows/check-code-quality.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: actions/checkout@v5
2929

3030
- name: Set up Python
31-
uses: actions/setup-python@v5
31+
uses: actions/setup-python@v6
3232
with:
3333
python-version: '3.12'
3434

@@ -42,14 +42,14 @@ jobs:
4242
4343
- name: Install and run ruff
4444
run: |
45-
pip install ruff .
45+
pip install ruff
4646
ruff check .
4747
ruff format .
4848
git restore README.md
4949
5050
- name: Install and run clang-format
5151
run: |
52-
sudo apt-get update && sudo apt-get install -y clang-format-18
52+
sudo apt-get install -y clang-format-18
5353
find . -regex '.*\.\(h\|c\|cpp\|hpp\|cc\|cxx\)' -exec clang-format-18 -style=file -i {} \;
5454
5555
- name: Install and run markdownlint
@@ -60,7 +60,6 @@ jobs:
6060
6161
- name: If needed raise error
6262
run: |
63-
6463
if [[ `git status --porcelain --untracked-files=no` ]]; then
6564
echo "Formatting not correct! See below the files which need to be reformatted!"
6665
git status --porcelain --untracked-files=no

.github/workflows/sonar.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ jobs:
4343
run: |
4444
brew install boost eigen nlohmann-json msgpack-cxx doctest
4545
- name: Set up Python
46-
uses: actions/setup-python@v5
46+
uses: actions/setup-python@v6
4747
with:
4848
python-version: "3.12"
4949
- name: Install build-wrapper
5050
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v5
5151

5252
- name: Python test and coverage
5353
run: |
54-
pip install -e .[dev]
54+
CC=clang CXX=clang++ pip install -e .[dev]
5555
pytest
5656
5757
- name: Run build-wrapper for C++

.readthedocs.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ sphinx:
1111
build:
1212
os: "ubuntu-24.04"
1313
tools:
14-
python: "3.11"
14+
python: "3.13"
1515
apt_packages:
1616
- graphviz
17+
- gcc-14
18+
- g++-14
1719
jobs:
1820
post_install:
1921
# Build package with doc requirements from pyproject.optional-dependencies
20-
- pip install --verbose --editable .[doc]
22+
- CC=gcc-14 CXX=g++-14 pip install --verbose --editable .[doc]
2123

2224
# remove API DLL define in header
2325
- find power_grid_model_c/power_grid_model_c/include -name *.h -exec sed -i -r "s/#define PGM.*//g" {} \;

power_grid_model_c/power_grid_model/include/power_grid_model/common/calculation_info.hpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
#pragma once
66

7-
#include "logging_impl.hpp"
7+
#include "multi_threaded_logging.hpp"
88

99
#include <map>
1010

1111
namespace power_grid_model {
1212
namespace common::logging {
13-
class CalculationInfo final : public Logger {
13+
class CalculationInfo : public Logger {
1414
using Data = std::map<LogEvent, double>;
1515

1616
public:
@@ -85,8 +85,28 @@ class CalculationInfo final : public Logger {
8585
public:
8686
Report report() const { return data_; }
8787
void clear() { data_.clear(); }
88+
89+
template <std::derived_from<Logger> T> T& merge_into(T& destination) const {
90+
if (&destination == this) {
91+
return destination; // nothing to do
92+
}
93+
for (const auto& [tag, value] : report()) {
94+
destination.log(tag, value);
95+
}
96+
return destination;
97+
}
98+
};
99+
100+
class MultiThreadedCalculationInfo : public MultiThreadedLoggerImpl<CalculationInfo> {
101+
public:
102+
using MultiThreadedLoggerImpl<CalculationInfo>::MultiThreadedLoggerImpl;
103+
using Report = CalculationInfo::Report;
104+
105+
Report report() const { return get().report(); }
106+
void clear() { get().clear(); }
88107
};
89108
} // namespace common::logging
90109

91110
using common::logging::CalculationInfo;
111+
using common::logging::MultiThreadedCalculationInfo;
92112
} // namespace power_grid_model

power_grid_model_c/power_grid_model/include/power_grid_model/common/common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <cmath>
88
#include <complex>
9+
#include <concepts>
910
#include <cstddef>
1011
#include <cstdint>
1112
#include <limits>

power_grid_model_c/power_grid_model/include/power_grid_model/common/logging_impl.hpp renamed to power_grid_model_c/power_grid_model/include/power_grid_model/common/dummy_logging.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class NoLogger : public Logger {
2424
void log(LogEvent /*tag*/, Idx /*value*/) override {
2525
// no logging
2626
}
27+
28+
template <std::derived_from<Logger> T> T& merge_into(T& destination) const { return destination; }
2729
};
2830

2931
} // namespace power_grid_model::common::logging

power_grid_model_c/power_grid_model/include/power_grid_model/common/logging.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class Logger {
6060
Logger& operator=(Logger const&) = default;
6161
};
6262

63+
struct MultiThreadedLogger : public Logger {
64+
virtual std::unique_ptr<Logger> create_child() = 0;
65+
};
66+
6367
} // namespace common::logging
6468

6569
using common::logging::LogEvent;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
//
3+
// SPDX-License-Identifier: MPL-2.0
4+
5+
#pragma once
6+
7+
#include "dummy_logging.hpp"
8+
9+
#include <cassert>
10+
#include <mutex>
11+
12+
namespace power_grid_model::common::logging {
13+
14+
template <std::derived_from<Logger> LoggerType>
15+
requires requires(LoggerType& destination, LoggerType const& source) {
16+
{ source.merge_into(destination) };
17+
}
18+
class MultiThreadedLoggerImpl : public MultiThreadedLogger {
19+
public:
20+
class ThreadLogger : public LoggerType {
21+
public:
22+
ThreadLogger(MultiThreadedLoggerImpl& parent) : parent_{&parent} {}
23+
ThreadLogger(ThreadLogger const&) = default;
24+
ThreadLogger& operator=(ThreadLogger const&) = default;
25+
ThreadLogger(ThreadLogger&&) noexcept = default;
26+
ThreadLogger& operator=(ThreadLogger&&) noexcept = default;
27+
~ThreadLogger() override { sync(); }
28+
void sync() const { parent_->sync(*this); }
29+
30+
private:
31+
MultiThreadedLoggerImpl* parent_;
32+
};
33+
34+
std::unique_ptr<Logger> create_child() override { return std::make_unique<ThreadLogger>(*this); }
35+
LoggerType& get() { return log_; }
36+
LoggerType const& get() const { return log_; }
37+
38+
void log(LogEvent tag) override { log_.log(tag); }
39+
void log(LogEvent tag, std::string_view message) override { log_.log(tag, message); }
40+
void log(LogEvent tag, double value) override { log_.log(tag, value); }
41+
void log(LogEvent tag, Idx value) override { log_.log(tag, value); }
42+
43+
private:
44+
friend class ThreadLogger;
45+
46+
LoggerType log_;
47+
std::mutex mutex_;
48+
49+
void sync(ThreadLogger const& logger) {
50+
assert(&logger != &log_);
51+
52+
std::lock_guard const lock{mutex_};
53+
logger.merge_into(log_);
54+
}
55+
};
56+
57+
using NoMultiThreadedLogger = MultiThreadedLoggerImpl<NoLogger>;
58+
59+
} // namespace power_grid_model::common::logging

power_grid_model_c/power_grid_model/include/power_grid_model/common/timer.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ using Duration = std::chrono::duration<double>;
1717

1818
class Timer {
1919
private:
20-
Logger* info_;
20+
Logger* log_;
2121
LogEvent code_;
2222
Clock::time_point start_;
2323

2424
public:
25-
Timer() : info_{nullptr}, code_{LogEvent::unknown} {};
26-
Timer(Logger& info, LogEvent code) : info_{&info}, code_{code}, start_{Clock::now()} {}
25+
Timer() : log_{nullptr}, code_{LogEvent::unknown} {};
26+
Timer(Logger& log, LogEvent code) : log_{&log}, code_{code}, start_{Clock::now()} {}
2727

2828
Timer(Timer const&) = delete;
2929
Timer(Timer&&) = default;
@@ -34,29 +34,29 @@ class Timer {
3434
stop();
3535

3636
// Copy/move members
37-
info_ = timer.info_;
37+
log_ = timer.log_;
3838
code_ = timer.code_;
3939
start_ = timer.start_;
4040

4141
// Disable original timer
42-
timer.info_ = nullptr;
42+
timer.log_ = nullptr;
4343

4444
// Return reference
4545
return *this;
4646
}
4747

4848
~Timer() {
49-
if (info_ != nullptr) {
49+
if (log_ != nullptr) {
5050
stop();
5151
}
5252
}
5353

5454
void stop() {
55-
if (info_ != nullptr) {
55+
if (log_ != nullptr) {
5656
auto const now = Clock::now();
5757
auto const duration = Duration(now - start_);
58-
info_->log(code_, duration.count());
59-
info_ = nullptr;
58+
log_->log(code_, duration.count());
59+
log_ = nullptr;
6060
}
6161
}
6262
};

0 commit comments

Comments
 (0)