Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Checks: >
-readability-use-anyofallof,
-readability-redundant-access-specifiers,
-readability-convert-member-functions-to-static,
-cppcoreguidelines-avoid-const-or-ref-data-members
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-pro-bounds-constant-array-index

CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
Expand Down Expand Up @@ -63,5 +64,9 @@ CheckOptions:
value: lower_case
- key: readability-function-cognitive-complexity.Threshold
value: 10
- key: readability-function-cognitive-complexity.IgnoreMacros
value: true
- key: readability-function-size.ParameterThreshold
value: 4
- key: cppcoreguidelines-pro-type-member-init.IgnoreArrays
value: true
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"C_Cpp.default.cppStandard": "c++11",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/build/include",
"${workspaceFolder:OpenGeode}/include",
"${workspaceFolder:OpenGeode}/build/opengeode/include",
"${workspaceFolder:OpenGeode}/build/third_party/abseil/install/include",
"${workspaceFolder:OpenGeode}/build/third_party/bitsery/install/include",
Expand All @@ -14,6 +15,7 @@
"${workspaceFolder}/include",
"${workspaceFolder}/src",
"${workspaceFolder}/build/include",
"${workspaceFolder:OpenGeode}/include",
"${workspaceFolder:OpenGeode}/build/opengeode/include",
"${workspaceFolder:OpenGeode}/build/third_party/abseil/install/include",
"${workspaceFolder:OpenGeode}/build/third_party/bitsery/install/include",
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ option(OPENGEODE_STOCHASTIC_WITH_PYTHON "Compile Python bindings" OFF)
# Get MyModule dependencies
find_package(OpenGeode REQUIRED CONFIG)

install(
FILES include/geode/stochastic/project.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/geode/stochastic
COMPONENT public
)

# ------------------------------------------------------------------------------------------------
# Configure the OpenGeode-Stochastic libraries
add_subdirectory(src/geode/stochastic)
Expand Down
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
14 changes: 8 additions & 6 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 @@ -38,17 +38,19 @@
PYBIND11_MODULE( opengeode_stochastic_py_stochastic, module )
{
module.doc() = "OpenGeode-Stochastic Python binding";
pybind11::class_< geode::StochasticLibrary >( module, "StochasticLibrary" )
.def( "initialize", &geode::StochasticLibrary::initialize );
pybind11::class_< geode::OpenGeodeStochasticStochasticLibrary >(
module, "OpenGeodeStochasticStochasticLibrary" )
.def( "initialize",
&geode::OpenGeodeStochasticStochasticLibrary::initialize );

geode::define_spatial_domain( module );

geode::define_distributions( 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 );
}
2 changes: 1 addition & 1 deletion bindings/python/stochastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

from opengeode_stochastic_py_stochastic import *

StochasticLibrary.initialize()
OpenGeodeStochasticStochasticLibrary.initialize()
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(
# SOURCE "test-py-mh-fractures.py"
# DEPENDENCIES
# ${PROJECT_NAME}::py_stochastic
#)
5 changes: 3 additions & 2 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Configuration = {
"type-empty": [0],
"type-enum": [2, "always", ["feat", "fix", "perf"]],
},
}
defaultIgnores: false,
};

export default Configuration
export default Configuration;
6 changes: 5 additions & 1 deletion include/geode/stochastic/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@

#pragma once

#include <limits>

#include <geode/basic/common.hpp>
#include <geode/basic/library.hpp>
#include <geode/basic/logger.hpp>

#include <geode/stochastic/opengeode_stochastic_stochastic_export.hpp>
#include <geode/stochastic/project.hpp>

namespace geode
{
OPENGEODE_LIBRARY( opengeode_stochastic_stochastic_api, Stochastic );
OPENGEODE_LIBRARY(
opengeode_stochastic_stochastic_api, OpenGeodeStochastic, Stochastic );

static constexpr double LOG_PROB_INVALID =
-std::numeric_limits< double >::infinity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,31 @@
*/
#pragma once

#include <geode/stochastic/common.hpp>

#include <geode/stochastic/models/energy_terms/single_object_term.hpp>
#include <absl/container/flat_hash_map.h>
#include <geode/stochastic/inference/statistics_tracker.hpp>
#include <geode/stochastic/inference/target_statistic.hpp>

namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( OwnerSegment );
ALIAS_2D( OwnerSegment );
} // namespace geode

namespace geode
{
class opengeode_stochastic_stochastic_api IntensityTerm
: public SingleObjectTerm< OwnerSegment2D,
std::function< double( const OwnerSegment2D&,
const SpatialDomain< OwnerSegment2D::dim >& ) > >
template < typename ObjectType >
class StatisticObjective
{
public:
explicit IntensityTerm( std::string_view name,
double lambda,
std::vector< uuid > targeted_set_ids,
double caracteristic_length,
const SpatialDomain< OwnerSegment2D::dim >& domain );
double compute_loss( const StatisticsTracker< ObjectType >& monitor,
const std::vector< TargetStatistic >& targets ) const
{
double loss = 0.0;

for( const auto& target : targets )
{
const double mean = monitor.mean( target.term_id );
const double diff = mean - target.value;

loss += diff * diff;
}

return loss;
}
};
} // namespace geode
56 changes: 56 additions & 0 deletions include/geode/stochastic/inference/statistic_validator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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_statistic.hpp>

namespace geode
{
template < typename ObjectType >
class StatisticsValidator
{
public:
void check( const StatisticsTracker& monitor,
const std::vector< TargetStatistic >& targets ) const
{
for( const auto& target : targets )
{
const double mean = monitor.mean( target.term_id );
const double rel_error = std::abs( mean - target.value )

Check warning on line 42 in include/geode/stochastic/inference/statistic_validator.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/stochastic/inference/statistic_validator.hpp:42:30 [clang-diagnostic-unused-variable]

unused variable 'rel_error'
/ ( std::abs( target.value ) + 1e-12 );
// OpenGeodeStochasticStochasticException::check_exception(
// rel_error < t.tolerance, nullptr,
// OpenGeodeException::TYPE::data,
// "[StatisticsValidator] Failure for term ",
// t.term_id.string(), "\n mean = ",
// mean,
// "\n target = ", target.value, "\n error
// = ", rel_error,
// "\n tol = ", target.tolerance );
}
}
};
} // namespace geode
Loading
Loading