Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d42a8b7
file reoganisation
francoisbonneau Mar 27, 2026
b3e9957
feat(ObjectSets): add map registry in ObjectSets.
francoisbonneau Mar 31, 2026
5b95c35
keep refactoring
francoisbonneau Apr 1, 2026
3d7e55c
feat(EnergyTerm): builder for energy terms
francoisbonneau Apr 9, 2026
4e4a5a6
Apply prepare changes
francoisbonneau Apr 9, 2026
14e2055
static monitoring
francoisbonneau Apr 28, 2026
964ff1f
Apply prepare changes
francoisbonneau Apr 28, 2026
a1b1ea5
feat(Helpers): create inference helpers.
francoisbonneau May 25, 2026
b4cfae3
Merge remote-tracking branch 'origin/HEAD' into energy_term_refactoring
francoisbonneau May 25, 2026
2c94303
Apply prepare changes
francoisbonneau May 25, 2026
1dd751a
update to last OpenGeode Version
francoisbonneau May 25, 2026
538826d
fix wind compile
francoisbonneau May 25, 2026
79a054d
Merge pull request #36 from Geode-solutions/energy_term_refactoring
francoisbonneau May 25, 2026
43b70fb
PA comments
francoisbonneau May 25, 2026
adfec09
Apply prepare changes
francoisbonneau May 25, 2026
8ddb2df
feat(statisticstools): implement validator and quadratic loss.
francoisbonneau May 25, 2026
fda9aff
feat(StatsticTool): Implement validator
francoisbonneau May 25, 2026
f534c2c
Apply prepare changes
francoisbonneau May 25, 2026
9f30eda
fix clang error
francoisbonneau May 25, 2026
866cb84
try linking issue
francoisbonneau May 25, 2026
64cc95d
feat(StraussTest): reactivate Strauss and Poisson Tests.
francoisbonneau May 26, 2026
07bdc97
Apply prepare changes
francoisbonneau May 26, 2026
cf5d658
tidy 00
francoisbonneau May 26, 2026
8a30a3f
Apply prepare changes
francoisbonneau May 26, 2026
ddab952
tidy01
francoisbonneau May 26, 2026
2e072dd
Apply prepare changes
francoisbonneau May 26, 2026
c9128a9
tidy02
francoisbonneau May 26, 2026
405e0e4
tidy 04
francoisbonneau May 26, 2026
d436520
Apply prepare changes
francoisbonneau May 26, 2026
0a32698
tidy05
francoisbonneau May 26, 2026
a813370
reduce nb iteration
francoisbonneau May 26, 2026
4c2ec76
modif param
francoisbonneau May 26, 2026
683ebba
avoid generic capture in lambdas
francoisbonneau May 27, 2026
60b8dca
tidy 05
francoisbonneau May 27, 2026
40339c3
tidy06
francoisbonneau May 27, 2026
94c997a
tidy07
francoisbonneau May 27, 2026
3331379
Merge pull request #40 from Geode-solutions/update_test_strauss
francoisbonneau May 27, 2026
dbf2fdf
feat(SimulationContext): remove inheritance in simulation runner
francoisbonneau May 27, 2026
1dd8903
Apply prepare changes
francoisbonneau May 27, 2026
449ca08
fix execution
francoisbonneau May 28, 2026
3c30a67
tidy
francoisbonneau May 28, 2026
e0a5a94
Apply prepare changes
francoisbonneau May 28, 2026
d724578
create simulation context builder
francoisbonneau May 28, 2026
68f5d6f
tidy
francoisbonneau May 29, 2026
7d1a5be
Apply prepare changes
francoisbonneau May 29, 2026
fd01ad8
tidy2
francoisbonneau May 29, 2026
426a3a2
Update include/geode/stochastic/sampling/mcmc/simulation_runner.hpp
francoisbonneau May 29, 2026
3f3192a
Apply prepare changes
francoisbonneau May 29, 2026
2ae78a9
more tidy
francoisbonneau May 29, 2026
8e86a7b
Merge pull request #41 from Geode-solutions/refacto_simulation_runner
francoisbonneau May 29, 2026
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
2 changes: 1 addition & 1 deletion bindings/python/src/stochastic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
add_geode_python_binding(
NAME "py_stochastic"
SOURCES
"sampling/mcmc/helpers/fracture_simulation_runner.hpp"
# "sampling/mcmc/helpers/fracture_simulation_runner.hpp"
"sampling/mcmc/helpers/simulation_monitor.hpp"
"sampling/mcmc/helpers/simulation_printer.hpp"
"sampling/mcmc/simulation_runner.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
void define_fracture_simulation( pybind11::module& module )
{
using namespace geode;

Check warning on line 30 in bindings/python/src/stochastic/sampling/mcmc/helpers/fracture_simulation_runner.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/fracture_simulation_runner.hpp:30:9 [google-build-using-namespace]

do not use namespace using-directives; use using-declarations instead

pybind11::class_< FractureSetDescription >(
module, "FractureSetDescription" )
Expand Down Expand Up @@ -88,7 +88,7 @@
// pybind11::arg( "engine" ), pybind11::arg( "steps"
// ), "Run simulation for a fixed number of steps." )
.def( "run",
static_cast< StatisticsMonitor ( FractureSimulationRunner::* )(
static_cast< StatisticsTracker ( FractureSimulationRunner::* )(
RandomEngine&, const SimulationConfigurator& ) >(
&FractureSimulationRunner::run ),
pybind11::arg( "engine" ), pybind11::arg( "config" ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@
*
*/

#include <geode/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp>
#include <geode/stochastic/inference/statistics_tracker.hpp>

namespace geode
{
void define_simulation_monitor( pybind11::module &module )

Check failure on line 28 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:28:37 [clang-diagnostic-error]

use of undeclared identifier 'pybind11'
{
pybind11::class_< geode::StatisticsMonitor >(
module, "StatisticsMonitor" )
pybind11::class_< geode::StatisticsTracker >(

Check failure on line 30 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:30:52 [clang-diagnostic-error]

expected '(' for function-style cast or type construction

Check failure on line 30 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:30:9 [clang-diagnostic-error]

use of undeclared identifier 'pybind11'
module, "StatisticsTracker" )
.def( pybind11::init< geode::index_t >(),

Check failure on line 32 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:32:52 [clang-diagnostic-error]

expected expression

Check failure on line 32 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:32:50 [clang-diagnostic-error]

expected '(' for function-style cast or type construction

Check failure on line 32 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:32:19 [clang-diagnostic-error]

use of undeclared identifier 'pybind11'
pybind11::arg( "nb_energy_terms" ),

Check failure on line 33 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:33:17 [clang-diagnostic-error]

use of undeclared identifier 'pybind11'
"Create a StatisticsMonitor for a given number of energy "
"Create a StatisticsTracker for a given number of energy "
"terms" )
.def( "add_realization", &geode::StatisticsMonitor::add_realization,
.def( "add_realization", &geode::StatisticsTracker::add_realization,

Check failure on line 36 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:36:46 [clang-diagnostic-error]

use of class template 'geode::StatisticsTracker' requires template arguments
pybind11::arg( "values" ),

Check failure on line 37 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:37:17 [clang-diagnostic-error]

use of undeclared identifier 'pybind11'
"Add a realization (vector of doubles) to update statistics" )
.def( "statiscal_count", &geode::StatisticsMonitor::statiscal_count,
.def( "statiscal_count", &geode::StatisticsTracker::statiscal_count,

Check failure on line 39 in bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_monitor.hpp:39:46 [clang-diagnostic-error]

use of class template 'geode::StatisticsTracker' requires template arguments
"Return the number of realizations added" )
.def_property_readonly( "means", &geode::StatisticsMonitor::means,
.def_property_readonly( "means", &geode::StatisticsTracker::means,
"Return the computed mean values for each energy term" )
.def_property_readonly( "variances",
&geode::StatisticsMonitor::variances,
&geode::StatisticsTracker::variances,
"Return the computed variances for each energy term" )
.def( "__repr__", []( const geode::StatisticsMonitor &self ) {
return "<StatisticsMonitor count="
.def( "__repr__", []( const geode::StatisticsTracker &self ) {
return "<StatisticsTracker count="
+ std::to_string( self.statiscal_count() ) + ">";
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace geode
// &SimulationPrinter::print_statistics_summary,
// pybind11::arg( "monitor" ),
// pybind11::arg( "energy_term_names" ) = "",
// "Print statistics summary from a StatisticsMonitor."
// "Print statistics summary from a StatisticsTracker."
// );
}
} // namespace geode
8 changes: 4 additions & 4 deletions bindings/python/src/stochastic/stochastic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

#include "sampling/direct/double_sampler.hpp"

#include "sampling/mcmc/helpers/fracture_simulation_runner.hpp"
#include "sampling/mcmc/helpers/simulation_monitor.hpp"
// #include "sampling/mcmc/helpers/fracture_simulation_runner.hpp"
// #include "sampling/mcmc/helpers/simulation_monitor.hpp"
#include "sampling/mcmc/helpers/simulation_printer.hpp"
#include "sampling/mcmc/simulation_runner.hpp"

Expand All @@ -49,8 +49,8 @@ PYBIND11_MODULE( opengeode_stochastic_py_stochastic, module )
geode::define_random_engine( module );
geode::define_double_sampler( module );

geode::define_simulation_monitor( module );
// geode::define_simulation_monitor( module );
geode::define_simulation_printer( module );
geode::define_simulation_runner( module );
geode::define_fracture_simulation( module );
// geode::define_fracture_simulation( module );
}
10 changes: 5 additions & 5 deletions bindings/python/tests/stochastic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

add_geode_python_test(
SOURCE "test-py-mh-fractures.py"
DEPENDENCIES
${PROJECT_NAME}::py_stochastic
)
#add_geode_python_test(
Comment thread
francoisbonneau marked this conversation as resolved.
# SOURCE "test-py-mh-fractures.py"
# DEPENDENCIES
# ${PROJECT_NAME}::py_stochastic
#)
73 changes: 73 additions & 0 deletions include/geode/stochastic/inference/statistics_tools.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#pragma once

#include <absl/container/flat_hash_map.h>

#include <geode/stochastic/inference/statistics_tracker.hpp>
#include <geode/stochastic/inference/target_statistics.hpp>

namespace geode::statistics
{
template < typename ObjectType >
void validate( const StatisticsTracker< ObjectType >& tracker,
const TargetStatistics< ObjectType >& targets )
{
const auto& model = targets.model();

for( const auto& term_uuid : targets.active_terms() )
{
const auto mean = tracker.mean( term_uuid );
const auto target = targets.target( term_uuid );

const auto rel_error =
std::fabs( mean - target )
/ ( std::fabs( target ) + geode::GLOBAL_EPSILON );

OpenGeodeStochasticStochasticException::check_exception(
rel_error < targets.tolerance( term_uuid ), nullptr,
OpenGeodeException::TYPE::result,
"[StatisticsValidator] Failure \n --> term ",
model.term_name( term_uuid ), "\n mean = ", mean,
"\n target = ", target, "\n error = ", rel_error,
"\n tol = ", targets.tolerance( term_uuid ) );
}
}

template < typename ObjectType >
double quadratic_loss( const StatisticsTracker< ObjectType >& tracker,
const TargetStatistics< ObjectType >& targets )
{
double loss = 0.0;

for( const auto& term_uuid : targets.active_terms() )
{
const auto diff =
tracker.mean( term_uuid ) - targets.value( term_uuid );

loss += diff * diff;
}

return loss;
}
} // namespace geode::statistics
86 changes: 86 additions & 0 deletions include/geode/stochastic/inference/statistics_tracker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once

// #include <absl/container/flat_hash_map.h>
#include <geode/basic/common.hpp>
#include <geode/basic/uuid.hpp>

#include <geode/stochastic/common.hpp>
#include <geode/stochastic/models/model.hpp>

namespace geode
{
template < typename ObjectType >
class StatisticsTracker
{
public:
StatisticsTracker( const Model< ObjectType >& model ) : model_{ model }

Check warning on line 16 in include/geode/stochastic/inference/statistics_tracker.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/stochastic/inference/statistics_tracker.hpp:16:9 [google-explicit-constructor]

single-argument constructors must be marked explicit to avoid unintentional implicit conversions
{
means_.resize( model.nb_terms(), 0.0 );
m2_.resize( model.nb_terms(), 0.0 );
}

[[nodiscard]] index_t statiscal_count() const
{
return count_;
}

void add_realization( const std::vector< double >& values )
{
++count_;
for( const auto value_id : geode::Range{ values.size() } )
{
auto& value = values[value_id];

Check warning on line 32 in include/geode/stochastic/inference/statistics_tracker.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/stochastic/inference/statistics_tracker.hpp:32:17 [readability-qualified-auto]

'auto &value' can be declared as 'const auto &value'
auto& mean = means_[value_id];
auto& sum_of_squares = m2_[value_id];

const auto delta = value - mean;
mean += delta / count_;
const auto delta2 = value - mean;
sum_of_squares += delta * delta2;
}
}

[[nodiscard]] double mean( const uuid& term_uuid ) const
{
return means_[model_.term_index( term_uuid )];
}

[[nodiscard]] const std::vector< double >& means() const
{
return means_;
}

[[nodiscard]] double variance( const uuid& term_uuid ) const
{
return variance( model_.term_index( term_uuid ) );
}

[[nodiscard]] std::vector< double > variances() const
{
std::vector< double > variances;
variances.reserve( model_.nb_terms() );
for( const auto variance_id : geode::Range{ model_.nb_terms() } )
{
variances.emplace_back( this->variance( variance_id ) );
}
return variances;
}

private:
[[nodiscard]] double variance( index_t term_index ) const
{
if( count_ < 2 )
{
return 0.0;
}
return m2_[term_index] / ( count_ - 1 );
}

private:
const Model< ObjectType >& model_;

std::vector< double > means_;
std::vector< double > m2_;
index_t count_{ 0 };
};
} // namespace geode
107 changes: 107 additions & 0 deletions include/geode/stochastic/inference/target_statistics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#pragma once
#include <geode/basic/uuid.hpp>
#include <geode/stochastic/models/model.hpp>

namespace geode
{
struct TargetStatisticConfig
{
std::string term_name;
double value;
double tolerance;
};

template < typename ObjectType >
class TargetStatistics
{
public:
explicit TargetStatistics( const Model< ObjectType >& model,
const std::vector< TargetStatisticConfig >& statistic_targets )
: model_( model )
{
values_.resize( model.nb_terms(), 0.0 );
tolerances_.resize( model.nb_terms(), 0.0 );
active_.resize( model.nb_terms(), false );
for( const auto& target : statistic_targets )
{
set_target( target );
}
}

[[nodiscard]] const Model< ObjectType >& model() const
{
return model_;
}

[[nodiscard]] bool has_target( const uuid& term_uuid ) const
{
return active_[model_.term_index( term_uuid )];
}

[[nodiscard]] double target( const uuid& term_uuid ) const
{
return values_[model_.term_index( term_uuid )];
}

[[nodiscard]] double tolerance( const uuid& term_uuid ) const
{
return tolerances_[model_.term_index( term_uuid )];
}

[[nodiscard]] std::vector< uuid > active_terms() const
{
std::vector< uuid > active_terms_uuid;

for( const auto& term : model_.terms().energy_terms() )
{
const auto& term_id = term->id();
if( active_[model_.term_index( term_id )] )
{
active_terms_uuid.push_back( term_id );
}
}
return active_terms_uuid;
}

private:
void set_target( const TargetStatisticConfig& statistic )
{
const auto term_uuid =
model_.terms().get_term_uuid( statistic.term_name );
const auto idx = model_.term_index( term_uuid );

values_[idx] = statistic.value;
tolerances_[idx] = statistic.tolerance;
active_[idx] = true;
}

private:
const Model< ObjectType >& model_;

std::vector< double > values_;
std::vector< double > tolerances_;
std::vector< bool > active_;
};
} // namespace geode
Loading
Loading