Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.1 #7

Merged
merged 37 commits into from
Oct 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
544de61
separate core from cli + start doc
Sep 4, 2024
f682af0
pass lib from .so to .a
Sep 4, 2024
3f2bbd8
add custom initialiser feature
Sep 5, 2024
03a1df0
check rd perf + clean wrap cereal dep
Sep 5, 2024
8c2c515
start implementing cereal serialization
Sep 5, 2024
8dc31d2
Improve post process package + check monod model
Sep 6, 2024
d75a6a6
improve way to get particle properties with kokkos_view in post_proce…
Sep 9, 2024
9ae456c
Refractor kernel into functor + reduce branching in move process + ch…
Sep 12, 2024
479b37a
Refractor and add autogenerated compile_time flag + start impl probes
Sep 13, 2024
fa00757
Fix(simulation) RTD for batch and continuous reactor; Fix(init) gas s…
Sep 24, 2024
985222d
Fix(model): mass_transfer + feed support, optimisation(MC), refractor…
Sep 27, 2024
fc6ad6f
WIP(Data exporter): new data exporter architecture
Sep 27, 2024
7706398
feat: Implement DataExporter and MPI Feed
Benncs Sep 29, 2024
d15407e
feat,fix: add mass calculation function and improve Monod uptake
Oct 1, 2024
f43e572
chore, fix(dataexport): refractor, new files
Oct 3, 2024
9307c1b
fix: matrix layout (row/column major) between Eigen and Kokkos
Oct 3, 2024
675aedd
chore + fix rtd
Oct 4, 2024
5ba315c
misc: test sanofi ok
Benncs Oct 6, 2024
3e963a3
fix(monod model): fix model to have correct final biomass concentration
Benncs Oct 9, 2024
336243b
feat: steady_state test
Oct 11, 2024
207e966
feat: test model parameters
Benncs Oct 13, 2024
c3b6a6b
Fix Monod and Uptake model, working in steady state
Oct 15, 2024
144ca33
script steady
Benncs Oct 16, 2024
bc68353
perf: improve flowmap creation and transition performance
Oct 17, 2024
c7115d8
chore
Oct 17, 2024
964ea53
add external hdf5 compressor
Oct 17, 2024
3a22247
opti: bench and add profiling
Oct 18, 2024
529f346
feat: add prng to division model function
Oct 21, 2024
04355bf
opti,feat: bench try opti + start impl sunya's model
Oct 23, 2024
de23d2f
refractor: model_uptake rename k_pts
Oct 23, 2024
41261a5
feat(model) fix uptake, implem metabolism
Oct 30, 2024
c23d528
fix(simulation): fix oxygen transfer and henry constant
Oct 30, 2024
aa54989
fix(cli): scalar gas-liquid from files, todo find better fix
Oct 30, 2024
905c40b
fix(main): confirm overriding when using MPI
Oct 30, 2024
0e506f8
chore
Oct 30, 2024
0487515
feat,fix,,chore: working 0.0.9 version
Oct 30, 2024
1522bbf
version upgrade
Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: steady_state test
  • Loading branch information
Casale Benjamin committed Oct 11, 2024
commit 336243b4e1b79ad26ae4e269e8f924939a6d48a6
12 changes: 9 additions & 3 deletions apps/autogenerated/biocma_cst_config.hpp.in
Original file line number Diff line number Diff line change
@@ -23,14 +23,20 @@

namespace AutoGenerated
{
constexpr std::size_t probe_buffer_size = @probe_buffer_size@;
constexpr double default_particle_container_allocation_factor = @default_particle_container_allocation_factor@;

constexpr std::string_view cma_data_folder_path = @cma_data_folder_path@; ///<Default folder to find CMA for simulation
constexpr std::string_view result_dir_path = @result_dir_path@; ///<Default folder to store simulation results

constexpr std::size_t probe_buffer_size = @probe_buffer_size@; ///<Default size for probes buffer


constexpr double default_particle_container_allocation_factor = @default_particle_container_allocation_factor@;
constexpr std::size_t MC_MAX_PARTICLE_BUFFER = @MC_MAX_PARTICLE_BUFFER@;
constexpr uint64_t debug_MC_RAND_DEFAULT_SEED = @debug_MC_RAND_DEFAULT_SEED@;

constexpr double dead_particle_ratio_threshold = @_dead_particle_ratio_threshold@;

static constexpr std::string_view result_dir_path = @result_dir_path@;

/**
* @namespace FlagCompileTIme
* @brief Namespace containing compile-time flags for application configuration.
3 changes: 2 additions & 1 deletion apps/autogenerated/meson.build
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@ conf_data = configuration_data(
'MC_MAX_PARTICLE_BUFFER': '100e6',
'debug_MC_RAND_DEFAULT_SEED': '2024',
'_dead_particle_ratio_threshold':'0.01',
'result_dir_path':'"./results/"'
'result_dir_path':'"./results/"',
'cma_data_folder_path':'"cma_data"'
},
)

2 changes: 1 addition & 1 deletion apps/cli/includes/rt_init.hpp
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ std::string sappend_date_time(std::string_view string) noexcept;
* environment, including execution context and other relevant metadata.
*/
ExecInfo
runtime_init(int argc, char **argv, const Core::SimulationParameters &params) noexcept;
runtime_init(int argc, char **argv, Core::SimulationParameters &params) noexcept;

/**
* @brief Print run metadata to log file before running */
10 changes: 0 additions & 10 deletions apps/cli/src/cli_parser.cpp
Original file line number Diff line number Diff line change
@@ -94,16 +94,6 @@ std::optional<Core::SimulationParameters> parse_cli(int argc, char **argv) noexc
params.flow_files.emplace_back(control.cma_case_path);
}

if (control.results_file_name.empty())
{
params.results_file_name =
"./results/" + sappend_date_time("result_") + std::string(".h5");
}
else
{
params.results_file_name = "./results/" + control.results_file_name + ".h5";
}

params.user_params = std::move(control);
sanitise_check_cli(params);

2 changes: 1 addition & 1 deletion apps/cli/src/main.cpp
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
return -1;
}

const auto params = params_opt.value();
auto params = params_opt.value();

if (!override_result_path(params))
{
132 changes: 77 additions & 55 deletions apps/cli/src/rt_init.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <biocma_cst_config.hpp>
#include <Eigen/Core>
#include <Kokkos_Core.hpp>
#include <biocma_cst_config.hpp>
#include <cassert>
#include <common/common.hpp>
#include <common/execinfo.hpp>
#include <core/simulation_parameters.hpp>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <filesystem>
@@ -14,7 +15,6 @@
#include <rt_init.hpp>
#include <sstream>


#ifndef NO_MPI
# include <mpi_w/wrap_mpi.hpp>
#endif
@@ -32,54 +32,20 @@ std::string env_file_path() noexcept;
void init_environment();
size_t generate_run_id();

void set_n_thread_current_rank(const int rank,
const int size,
ExecInfo &info,
const Core::UserControlParameters &params)noexcept
{
// Casting rank and size to size_t
info.current_rank = static_cast<size_t>(rank);
info.n_rank = static_cast<size_t>(size);

// Determining the number of OpenMP threads
size_t omp_n_thread = (params.n_thread > 0)
? static_cast<size_t>(params.n_thread)
: static_cast<size_t>(omp_get_max_threads());

// int num_core_per_node = omp_get_num_procs();

size_t threads_per_process = 1;

if (omp_n_thread >= info.n_rank)
{
threads_per_process = omp_n_thread / info.n_rank;
if (omp_n_thread % info.n_rank != 0 && info.current_rank == info.n_rank - 1)
{
threads_per_process += omp_n_thread % info.n_rank;
}
}

info.thread_per_process = threads_per_process;

assert(info.thread_per_process > 0);

omp_set_num_threads(static_cast<int>(info.thread_per_process));


}
void check_results_file_name(Core::SimulationParameters &params);

ExecInfo runtime_init(int argc, char **argv, const Core::SimulationParameters &params)noexcept
ExecInfo runtime_init(int argc, char **argv, Core::SimulationParameters &params) noexcept
{
init_environment();
ExecInfo info{};

int rank = 0;
int size = 0;

if constexpr (AutoGenerated::FlagCompileTIme::use_mpi)
{
#ifndef NO_MPI

// int mpi_thread_level{};
// MPI_Init_thread(&argc, &argv, MPI_THREAD_SINGLE, &mpi_thread_level);
// int mpi_thread_level{};
@@ -96,20 +62,19 @@ ExecInfo runtime_init(int argc, char **argv, const Core::SimulationParameters &p

set_n_thread_current_rank(rank, size, info, params.user_params);
// Kokkos::initialize(argc, argv);
Kokkos::initialize(Kokkos::InitializationSettings() // (since 3.7)
.set_disable_warnings(false)
.set_num_threads(info.thread_per_process)
.set_map_device_id_by("random"));
if(rank==0)
Kokkos::initialize(Kokkos::InitializationSettings() // (since 3.7)
.set_disable_warnings(false)
.set_num_threads(static_cast<int32_t>(info.thread_per_process))
.set_map_device_id_by("random"));
if (rank == 0)
{
if constexpr(AutoGenerated::FlagCompileTIme::use_mpi)
if constexpr (AutoGenerated::FlagCompileTIme::use_mpi)
{

std::cout << "USING MPI" << std::endl;
std::cout << "USING MPI" << std::endl;
}
Kokkos::DefaultExecutionSpace().print_configuration(std::cout);
}


// Eigen::setNbThreads(static_cast<int>(info.thread_per_process));
// Eigen::setNbThreads(std::min(omp_get_num_procs(), 4));
@@ -131,10 +96,10 @@ ExecInfo runtime_init(int argc, char **argv, const Core::SimulationParameters &p

const auto id_seed = static_cast<size_t>(time(nullptr) * info.n_rank *
info.thread_per_process);

std::string s = std::to_string(id_seed);
info.run_id = std::hash<std::string>{}(s);

check_results_file_name(params);
return info;
}

@@ -144,7 +109,6 @@ void init_environment()
const auto env_path = env_file_path();

static const std::string cma_data_folder_path = "cma_data";
static const std::string results_folder_path = "results";
static bool environment_initialized = false;

if (!environment_initialized)
@@ -154,9 +118,9 @@ void init_environment()
std::filesystem::create_directory(cma_data_folder_path);
}

if (!std::filesystem::exists(results_folder_path))
if (!std::filesystem::exists(AutoGenerated::result_dir_path))
{
std::filesystem::create_directory(results_folder_path);
std::filesystem::create_directory(AutoGenerated::result_dir_path);
}

if (!std::filesystem::exists(env_path))
@@ -193,7 +157,7 @@ void init_environment()
// fd << std::put_time(std::localtime(&now), "%Y-%m-%d %H:%M:%S");
// }

std::string sappend_date_time(std::string_view string)noexcept
std::string sappend_date_time(std::string_view string) noexcept
{
std::stringstream fd;
fd << string;
@@ -208,7 +172,7 @@ std::string env_file_path() noexcept
return ".bmc_info";
}

void register_run(const ExecInfo &exec, Core::SimulationParameters &params)noexcept
void register_run(const ExecInfo &exec, Core::SimulationParameters &params) noexcept
{
// Open the file in append mode
std::ofstream env(env_file_path(), std::ios_base::app);
@@ -225,3 +189,61 @@ void register_run(const ExecInfo &exec, Core::SimulationParameters &params)noexc
std::cerr << "Error: Unable to open file for writing\n";
}
}

void set_n_thread_current_rank(const int rank,
const int size,
ExecInfo &info,
const Core::UserControlParameters &params) noexcept
{
// Casting rank and size to size_t
info.current_rank = static_cast<size_t>(rank);
info.n_rank = static_cast<size_t>(size);

// Determining the number of OpenMP threads
size_t omp_n_thread = (params.n_thread > 0)
? static_cast<size_t>(params.n_thread)
: static_cast<size_t>(omp_get_max_threads());

// int num_core_per_node = omp_get_num_procs();

size_t threads_per_process = 1;

if (omp_n_thread >= info.n_rank)
{
threads_per_process = omp_n_thread / info.n_rank;
if (omp_n_thread % info.n_rank != 0 && info.current_rank == info.n_rank - 1)
{
threads_per_process += omp_n_thread % info.n_rank;
}
}

info.thread_per_process = threads_per_process;

assert(info.thread_per_process > 0);

omp_set_num_threads(static_cast<int>(info.thread_per_process));
}

void check_results_file_name(Core::SimulationParameters &params)
{

std::filesystem::path path = AutoGenerated::result_dir_path;
std::filesystem::path folder_name = AutoGenerated::result_dir_path;

if (params.user_params.results_file_name.empty())
{
folder_name.append(sappend_date_time("result_"));
path.append(sappend_date_time("result_"));

path.append(sappend_date_time("result_") + std::string(".h5"));
}
else
{
folder_name.append(params.user_params.results_file_name);
path.append(params.user_params.results_file_name);
path.append(params.user_params.results_file_name + std::string(".h5"));
}
std::filesystem::create_directory(folder_name);
params.results_file_name = path.string();
params.user_params.results_file_name = path.replace_extension();
}
10 changes: 5 additions & 5 deletions apps/cli/src/siminit.cpp
Original file line number Diff line number Diff line change
@@ -311,13 +311,13 @@ init_state(Core::SimulationParameters &params,
static Simulation::Feed::SimulationFeed init_feed()
{

constexpr double flow = 3e-6;
constexpr double expected_tau = 20e-3 / flow; // 90e-3/0.00010087625032109857;//20e-3/1.6e-5;
constexpr double expected_mu = 1 / expected_tau;
constexpr double sf = 2;
constexpr double flow = 0.;
// constexpr double expected_tau = 20e-3 / flow; // 90e-3/0.00010087625032109857;//20e-3/1.6e-5;
// constexpr double expected_mu = 1 / expected_tau;
constexpr double sf = 5;


//1: 0.5 gl
//1: 0.5 gl
//2: 2
//3: 3
//4: 5
2 changes: 1 addition & 1 deletion apps/core/includes/dataexporter/data_exporter.hpp
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ namespace CORE_DE
get_filename(std::string_view filename,
std::size_t current_rank)
{
return "./results/" + std::string(filename) + "_partial_" + std::to_string(current_rank) + ".h5";
return std::string(filename) + "_partial_" + std::to_string(current_rank) + ".h5";
}

/**
2 changes: 1 addition & 1 deletion apps/core/src/case_data.cpp
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ namespace Core
const SimulationParameters &params)
{
std::stringstream filename;
filename << AutoGenerated::result_dir_path
filename
<< params.user_params.results_file_name << "_partial_"
<< exec.current_rank << ".h5";
return filename.str();
2 changes: 1 addition & 1 deletion apps/core/src/host_specific.cpp
Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ make_main_exporter(const ExecInfo &exec, const Core::SimulationParameters &param
{
std::string group = "files/" + std::to_string(i_rank);

auto filename = "./results/" + params.user_params.results_file_name +
auto filename = params.user_params.results_file_name +
"_partial_" + std::to_string(i_rank) + ".h5";

main_exporter->do_link(filename, group, "/");
8 changes: 4 additions & 4 deletions apps/libs/biomodels/src/model_monod.cpp
Original file line number Diff line number Diff line change
@@ -26,14 +26,14 @@ namespace Models
{
auto generator = _rng.random_pool.get_state();

this->l =
Kokkos::max(minimal_length,
Kokkos::max(generator.normal(l_0 / 2., l_0 / 2. / 5.), 0.));
this->l = l_0 / 2.;
// Kokkos::max(minimal_length,
// Kokkos::max(generator.normal(l_0 / 2., l_0 / 2. / 5.), 0.));

this->mu = Kokkos::max(generator.normal(mu_max / 2., mu_max / 4), 0.);
_rng.random_pool.free_state(generator);
static_assert(l_1>l_0,"Monod: Bad Model Parameter " );
constexpr double ___init_only_cell_lenghtening = (l_1 - l_0) / ln2;
constexpr double ___init_only_cell_lenghtening = 4e-7 / ln2;
_init_only_cell_lenghtening = 4e-7 / ln2;

// p.weight = p.weight/mass();
2 changes: 1 addition & 1 deletion apps/libs/mc/public/mc/mcinit.hpp
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ namespace MC
{

constexpr bool uniform_init = false;
constexpr double initial_mass_cell = 3.14 * (0.8e-6) * (0.8e-6)/4. * 1e-6/2. * 1000;
constexpr double initial_mass_cell = 3.14 * (0.8e-6) * (0.8e-6)/4. * 0.9e-6/2. * 1000;
namespace
{

2 changes: 1 addition & 1 deletion apps/post_process/__main__.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
from matplotlib import pyplot as plt
import numpy as np

from .rtd import get_scalar_rtd

Check failure on line 5 in apps/post_process/__main__.py

GitHub Actions / python-ruff

Ruff (F401)

apps/post_process/__main__.py:5:18: F401 `.rtd.get_scalar_rtd` imported but unused

# from .old_read_results import import_results
from .read_results import import_results, Results
@@ -11,17 +11,17 @@
average_concentration,
check_mixing,
set_time_unit_to_hour,
time_average_reaction_rate,

Check failure on line 14 in apps/post_process/__main__.py

GitHub Actions / python-ruff

Ruff (F401)

apps/post_process/__main__.py:14:5: F401 `.time_average_reaction_rate` imported but unused
)
from .properties import process_particle_data, property_distribution

Check failure on line 16 in apps/post_process/__main__.py

GitHub Actions / python-ruff

Ruff (F401)

apps/post_process/__main__.py:16:48: F401 `.properties.property_distribution` imported but unused
import os
import argparse
from numpy.polynomial import Polynomial

Check failure on line 19 in apps/post_process/__main__.py

GitHub Actions / python-ruff

Ruff (F401)

apps/post_process/__main__.py:19:30: F401 `numpy.polynomial.Polynomial` imported but unused
from . import get_time


def assemble(res_folder: str, names: List[str]) -> List[str]:
return [f"{res_folder}{i}.h5" for i in names]
return [f"{res_folder}{i}/{i}.h5" for i in names]


def mk_parser():
@@ -168,7 +168,7 @@
check_time_unit(results)

last_id = results.main.n_export - 1
last_vtk_path = get_vtk(last_id)

Check failure on line 171 in apps/post_process/__main__.py

GitHub Actions / python-ruff

Ruff (F841)

apps/post_process/__main__.py:171:9: F841 Local variable `last_vtk_path` is assigned to but never used

# get_scalar_rtd(dest[i],0.00011758,results,True)
# get_scalar_rtd(dest[i],0.035,results)
3 changes: 2 additions & 1 deletion apps/post_process/properties.py
Original file line number Diff line number Diff line change
@@ -4,10 +4,10 @@

from .read_results import Results, PartialResult

from .io import append_resukts_scalar_vtk

Check failure on line 7 in apps/post_process/properties.py

GitHub Actions / python-ruff

Ruff (F401)

apps/post_process/properties.py:7:17: F401 `.io.append_resukts_scalar_vtk` imported but unused
from . import FIGURE_TYPE, mkdir
from typing import Dict, List, Optional
from . import RATIO_MASS_LENGTH, get_time

Check failure on line 10 in apps/post_process/properties.py

GitHub Actions / python-ruff

Ruff (F401)

apps/post_process/properties.py:10:15: F401 `.RATIO_MASS_LENGTH` imported but unused


def process_string_title(input_string):
@@ -40,7 +40,7 @@
plt.title(f"Probability Density Function for {title_name} (PDF)")
mkdir(f"{dest}/pdf")
plt.savefig(f"{dest}/pdf/pdf_{name}{FIGURE_TYPE}")
except:

Check failure on line 43 in apps/post_process/properties.py

GitHub Actions / python-ruff

Ruff (E722)

apps/post_process/properties.py:43:5: E722 Do not use bare `except`
pass


@@ -173,9 +173,10 @@

indices = np.where(average!=0)
average = average / np.sum(results.total_repartion,axis=1).reshape(-1,1)

mkdir(dest)
for i, key in enumerate(keys):
print(average[-1,i])
try:
plt.figure()
plt.plot(
Loading
Loading