Skip to content

Commit e3c6c82

Browse files
authored
Deps rcmtool (#25)
* feat: add generic read_env with optional type * fix(mc): remove conflict pool_type and MC::pool_type * feat(prng): add uniform distribution * feat(udf): clean udf loader with reduced conditional build, final warning with the use of get_config * feat(wip): try sort SoA, not working yet * fix(serde): correct scalar init w and w/o gas * feat(cma): wip changes but fully working with cmtool rust implem * refractor(worker): clean signal handling and callback * wip: opti mpi * feat(cma): clean all unsued and better rust integration * feat(params): remove recursive flag for cma load not needed with rust impl * fix(mpi): ensure to_wait=false when no comm * feat(simulation): checkScalar to ensure positive concentrations * refactor: clean up previously added code * fix(api): udf namespace + Python raise runtimeerror * chore: remove wrap for cmtool * fix(udf): same namespace for forward declartion w/o udf features * chore: update dockerfile for rust deps * chore: rmctool wrapfile from git * chore: remove cmtool clone from ci * ci: token * ci: token * ci: token * ci: token * ci: token * ci: token * ci: token * ci: token * ci: token * ci: token * ci: token * fix(docker): cargo install * fix: typo * fix(test): updated test and cma_case * chore: clean up code
1 parent 99a4209 commit e3c6c82

File tree

105 files changed

+1640
-2163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1640
-2163
lines changed

.github/workflows/container.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,9 @@ jobs:
2525
tag: biocma_omp_base:latest
2626
output: /tmp/biocma_omp_base.tar
2727
steps:
28+
2829
- name: Checkout code
2930
uses: actions/checkout@v4
30-
#with:
31-
#token: '${{ secrets.PAT_TOKEN }}'
32-
#
33-
- name: Clone GitLab submodule
34-
run: |
35-
git config --global credential.helper '!f() { echo "username=${{ secrets.USER_GITLAB }}"; echo "password=${{ secrets.PAT_GITLAB }}"; }; f'
36-
#git submodule update --init --recursive
3731

3832
- name: Set up Docker Buildx
3933
uses: docker/setup-buildx-action@v2
@@ -56,15 +50,12 @@ jobs:
5650
runs-on: ubuntu-latest
5751
needs: build-docker-base-images
5852
steps:
59-
- name: Checkout code
60-
uses: actions/checkout@v4
61-
#with:
62-
#token: '${{ secrets.PAT_TOKEN }}'
63-
#
64-
- name: Clone GitLab submodule
53+
54+
- uses: actions/checkout@v1
55+
56+
- name: Clone RMCTool
6557
run: |
66-
git config --global credential.helper '!f() { echo "username=${{ secrets.USER_GITLAB }}"; echo "password=${{ secrets.PAT_GITLAB }}"; }; f'
67-
git clone https://gitlab.com/codes_tim/compartment-modelling-tool.git subprojects/cmtool
58+
git clone --branch v1.3 https://${{ secrets.RCMTTOKEN }}@github.com/Benncs/rcmtool.git subprojects/rcmtool
6859
6960
- name: Set up Docker Buildx
7061
uses: docker/setup-buildx-action@v2

.github/workflows/main.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ jobs:
1717
steps:
1818
- name: Checkout code
1919
uses: actions/checkout@v4
20-
with:
21-
token: '${{ secrets.PAT_TOKEN }}'
22-
- name: Add token GitLab
23-
run: >
24-
git config --global credential.helper '!f() { echo "username=${{
25-
secrets.USER_GITLAB }}"; echo "password=${{ secrets.PAT_GITLAB }}"; };
26-
f'
20+
2721
run: |
2822
sudo sh devutils/install_dep.sh
2923
- name: Configure project

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ compile_commands.json
88
# Env
99
.bmc_info
1010
results/
11+
results
1112
cma_data/
1213
*.h5
1314
#Benchs

apps/api/includes/udf_handle.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __UDF_HANDLE_HPP__
2+
#define __UDF_HANDLE_HPP__
3+
4+
#include <common/results.hpp>
5+
#include <memory>
6+
#ifdef USE_UDF
7+
# include <udf_includes.hpp>
8+
#endif
9+
10+
#ifndef USE_UDF
11+
struct DynamicLibrary;
12+
#endif
13+
14+
namespace Unsafe
15+
{
16+
Result<std::shared_ptr<DynamicLibrary>, std::string>
17+
load_udf(std::string_view model_name);
18+
} // namespace Unsafe
19+
#endif

apps/api/meson.build

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ src_dir = './src'
22

33
name = f'@project_name@_api'
44

5-
api_source = files(f'@src_dir@/api.cpp')
5+
api_source = files(f'@src_dir@/api.cpp', f'@src_dir@/udf_handle.cpp')
66

7-
includes = include_directories('./includes', 'public')
7+
includes = [include_directories('./includes', 'public'), ext_include]
88

9+
exe_link_args=[flto_flag]
10+
if not use_cuda and build_udf
11+
exe_link_args=[exe_link_args,'-rdynamic']
12+
endif
913

1014
lib_api_shared = static_library(
1115
f'@name@_shared',
@@ -14,6 +18,7 @@ lib_api_shared = static_library(
1418
dependencies: [core_shared_dependency],
1519
# cpp_args: ['-DNO_MPI'],
1620
install_rpath: project_name,
21+
link_args:exe_link_args
1722
)
1823

1924
lib_api_distributed = static_library(
@@ -23,18 +28,21 @@ lib_api_distributed = static_library(
2328
dependencies: [core_distributed_dependency_static, mpi_wrap_dependency],
2429
# cpp_args: ['-DNO_MPI'],
2530
install_rpath: project_name,
31+
link_args:exe_link_args
2632
)
2733

2834
lib_api_shared_dep = declare_dependency(
2935
link_with: lib_api_shared,
3036
include_directories: includes,
3137
dependencies: [core_shared_dependency, kokkos],
38+
link_args:exe_link_args
3239
)
3340

3441
lib_api_distributed_dep = declare_dependency(
3542
link_with: lib_api_distributed,
3643
include_directories: includes,
3744
dependencies: [core_distributed_dependency_static],
45+
link_args:exe_link_args
3846
)
3947

4048
build_python = get_option('build_python_api')
@@ -106,4 +114,4 @@ endif
106114

107115
if build_test
108116
subdir('tests')
109-
endif
117+
endif

apps/api/public/api/api.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ namespace Api
136136
* @param recursive Flag indicating if recursive registration is required.
137137
* @return True if the path was successfully registered; false otherwise.
138138
*/
139-
bool register_cma_path(std::string_view path, bool recursive = false);
139+
bool register_cma_path(std::string_view path);
140140

141141
/**
142142
* @brief Register a serialization/deserialization (serde) path.

apps/api/public/api/api_raw.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ typedef struct Opaque* Handle; // NOLINT //In C we only need ptr type so Opaque
5151

5252
/* REGISTER */
5353
int register_result_path(Handle handle, const char* c);
54-
int register_cma_path_recursive(Handle handle, const char* c);
5554
int register_cma_path(Handle handle, const char* c);
5655
int register_serde(Handle handle, const char* c);
5756
int register_model_name(Handle handle, const char* c);
@@ -67,7 +66,6 @@ typedef struct Opaque* Handle; // NOLINT //In C we only need ptr type so Opaque
6766
uint64_t number_particle; ///< Number of particles in the simulation.
6867
int32_t n_thread; ///< Number of threads to use for simulation.
6968
uint32_t number_exported_result; ///< Number of results to be exported.
70-
int recursive; ///< Flag to enable recursive processing.
7169
int force_override; ///< Flag to allow overwriting of existing results.
7270
int load_serde;
7371
int save_serde;

apps/api/python/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def init_simulation(
3535
simulation_name: str,
3636
cma_path: str,
3737
params,
38-
is_recursive: bool = False,
3938
_id: Optional[int] = None,
4039
):
4140
sim_id = 0
@@ -58,7 +57,7 @@ def init_simulation(
5857
handle_module.register_result_path(handle, f"{full_out_dir}/{simulation_name}")
5958

6059
# Register the CMA path
61-
handle_module.register_cma_path(handle, cma_path, is_recursive)
60+
handle_module.register_cma_path(handle, cma_path)
6261

6362
return handle
6463

@@ -83,7 +82,6 @@ def fast_run(
8382
n_compartment: int,
8483
s_feed: float,
8584
liquid_flow_rate: float = 0.0,
86-
is_recursive: bool = False,
8785
is_serde: bool = False,
8886
f_init=None,
8987
serde_path=None,
@@ -93,7 +91,7 @@ def fast_run(
9391
# Prepare parameters
9492
params = handle_module.make_params(**params)
9593
handle = handle_module.init_simulation(
96-
outfolder, name, cma_path, params, is_recursive
94+
outfolder, name, cma_path, params
9795
)
9896

9997
# Liquid feed configuration

apps/api/src/api.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "simulation/mass_transfer.hpp"
12
#include <Kokkos_Core.hpp>
23
#include <api/api.hpp>
34
#include <api/results.hpp>
@@ -20,8 +21,10 @@
2021
#include <span>
2122
#include <stdexcept>
2223
#include <string>
24+
#include <udf_handle.hpp>
2325
#include <utility>
2426
#include <vector>
27+
static std::shared_ptr<DynamicLibrary> udf_handle = nullptr;
2528
constexpr int ID_VERIF = 2025;
2629

2730
#define CHECK_OR_RETURN(cond, msg) \
@@ -65,6 +68,7 @@ namespace Api
6568

6669
void finalise()
6770
{
71+
6872
if (!Kokkos::is_finalized() && Kokkos::is_initialized())
6973
{
7074
Kokkos::finalize();
@@ -131,14 +135,15 @@ namespace Api
131135
std::optional<std::size_t> run_id)
132136
: id(ID_VERIF)
133137
{
138+
134139
_data.exec_info = Core::runtime_init(argc, argv, run_id);
135140
std::atexit(Api::finalise);
136141
}
137142

138143
SimulationInstance::~SimulationInstance()
139144
{
140-
141145
_data = Core::CaseData(); // Explicity delete everything before
146+
udf_handle.reset();
142147
}
143148

144149
std::optional<std::unique_ptr<SimulationInstance>> SimulationInstance::init(
@@ -156,10 +161,12 @@ namespace Api
156161

157162
ApiResult SimulationInstance::exec() noexcept
158163
{
164+
159165
if (loaded || (registered && applied))
160166
{
161167
try
162168
{
169+
163170
if (logger)
164171
{
165172
logger->print(
@@ -174,6 +181,10 @@ namespace Api
174181
}
175182
catch (std::exception& e)
176183
{
184+
if (logger)
185+
{
186+
logger->alert("EXEC", e.what());
187+
}
177188
return ApiResult(e.what());
178189
}
179190
}
@@ -218,6 +229,7 @@ namespace Api
218229
Core::GlobalInitialiser global_initializer(_data.exec_info, params, logger);
219230

220231
auto transitionner = global_initializer.init_transitionner();
232+
221233
CHECK_OR_RETURN(!transitionner, "Error when apply: transitionner");
222234

223235
CHECK_OR_RETURN(!global_initializer.init_feed(feed),
@@ -243,6 +255,8 @@ namespace Api
243255

244256
mtr_type = Simulation::MassTransfer::Type::FixedKla{kla};
245257

258+
// mtr_type = Simulation::MassTransfer::Type::FlowmapTurbulence{};
259+
246260
if (mtr_type)
247261
{
248262
simulation->setMtrModel(std::move(*mtr_type));
@@ -268,6 +282,11 @@ namespace Api
268282

269283
ApiResult SimulationInstance::apply(bool to_load) noexcept
270284
{
285+
auto opt_udf = Unsafe::load_udf(params.model_name);
286+
if (opt_udf.valid())
287+
{
288+
udf_handle = opt_udf.gets();
289+
}
271290
if (to_load)
272291
{
273292
return apply_load();
@@ -299,8 +318,7 @@ namespace Api
299318
return ApiResult(); // TODO
300319
}
301320

302-
bool SimulationInstance::register_cma_path(std::string_view path,
303-
bool recursive)
321+
bool SimulationInstance::register_cma_path(std::string_view path)
304322
{
305323

306324
std::filesystem::path p(path);
@@ -316,7 +334,6 @@ namespace Api
316334
normalized += std::filesystem::path::preferred_separator;
317335
}
318336

319-
this->params.recursive = recursive;
320337
this->params.cma_case_path = normalized;
321338

322339
return true;

apps/api/src/api_python.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <core/scalar_factory.hpp>
55
#include <cstddef>
66
#include <cstdlib>
7+
#include <exception>
78
#include <memory>
89
#include <pybind11/cast.h>
910
#include <pybind11/detail/common.h>
@@ -52,9 +53,12 @@ namespace PythonBindings
5253
auto exec(std::shared_ptr<Api::SimulationInstance>& handle)
5354
{
5455
pybind11::gil_scoped_release release; // TODO check if really usefull ?
55-
handle->exec();
56+
const auto ret = handle->exec();
5657
pybind11::gil_scoped_acquire acquire;
57-
return 0;
58+
if (ret.invalid())
59+
{
60+
throw std::runtime_error(ret.get());
61+
}
5862
}
5963

6064
auto apply(std::shared_ptr<Api::SimulationInstance>& handle, bool to_load)
@@ -66,13 +70,10 @@ namespace PythonBindings
6670
}
6771

6872
auto register_cma_path(std::shared_ptr<Api::SimulationInstance>& handle,
69-
const std::string& cma_path,
70-
bool recursive)
73+
const std::string& cma_path)
7174
{
7275

73-
return (recursive)
74-
? register_cma_path_recursive(handle.get(), cma_path.data())
75-
: ::register_cma_path(handle.get(), cma_path.data());
76+
return ::register_cma_path(handle.get(), cma_path.data());
7677
}
7778

7879
auto
@@ -109,7 +110,6 @@ namespace PythonBindings
109110
.def_readwrite("force_override", &wrap_c_param_t::force_override)
110111
.def_readwrite("n_thread", &wrap_c_param_t::n_thread)
111112
.def_readwrite("number_exported_result", &wrap_c_param_t::number_exported_result)
112-
.def_readwrite("recursive", &wrap_c_param_t::recursive)
113113
.def_readwrite("biomass_initial_concentration",
114114
&wrap_c_param_t::biomass_initial_concentration)
115115
.def_readwrite("number_particle", &wrap_c_param_t::number_particle)
@@ -128,13 +128,12 @@ namespace PythonBindings
128128
p.force_override,
129129
p.n_thread,
130130
p.number_exported_result,
131-
p.recursive,
132131
p.biomass_initial_concentration,
133132
p.number_particle,
134133
p.save_serde);
135134
},
136135
[](const py::tuple& t) { // __setstate__
137-
constexpr std::size_t n_attributes = 9;
136+
constexpr std::size_t n_attributes = 8;
138137
if (t.size() != n_attributes)
139138
{
140139
throw std::runtime_error("Pickle param invalid state, "
@@ -151,10 +150,9 @@ namespace PythonBindings
151150
p.force_override = static_cast<int>(t[2].cast<bool>());
152151
p.n_thread = t[3].cast<int>();
153152
p.number_exported_result = t[4].cast<int>();
154-
p.recursive = static_cast<int>(t[5].cast<bool>());
155-
p.biomass_initial_concentration = t[6].cast<double>();
156-
p.number_particle = t[7].cast<int>();
157-
p.save_serde = t[8].cast<int>();
153+
p.biomass_initial_concentration = t[5].cast<double>();
154+
p.number_particle = t[6].cast<int>();
155+
p.save_serde = t[7].cast<int>();
158156
// NOLINTEND
159157
return p;
160158
}));
@@ -198,8 +196,7 @@ PYBIND11_MODULE(handle_module, m) // NOLINT (Pybind11 MACRO)
198196
m.def("register_cma_path",
199197
&PythonBindings::register_cma_path,
200198
py::arg("handle"),
201-
py::arg("cma_path"),
202-
py::arg("recursive") = false);
199+
py::arg("cma_path"));
203200

204201
m.def("register_serde", &register_serde);
205202
m.def("register_parameters", &register_parameters);

0 commit comments

Comments
 (0)