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

test: Use deterministic RNG for tests #2694

Merged
merged 10 commits into from
Nov 20, 2023
1 change: 0 additions & 1 deletion Core/include/Acts/Surfaces/TrapezoidBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace Acts {
/// @image html TrapezoidBounds.gif
///
/// @todo can be speed optimized by calculating kappa/delta and caching it

class TrapezoidBounds : public PlanarBounds {
public:
enum BoundValues {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct Uniform {
auto bin = binningData.search(value);
auto lower = binningData.boundaries()[bin];
auto higher = binningData.boundaries()[bin + 1];
std::uniform_real_distribution<> dist{0., 1.};
std::uniform_real_distribution<double> dist{0., 1.};
double svalue = lower + (higher - lower) * dist(rnd);
return std::pair{svalue, (higher - lower) / std::sqrt(12.)};
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Benchmarks/CovarianceTransportBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char* argv[]) {
VectorHelpers::theta(direction), qop, time;

std::minstd_rand rng;
std::uniform_real_distribution<> uniform(0.5, 0.95);
std::uniform_real_distribution<double> uniform(0.5, 0.95);

unsigned int sillyCounter = 0;

Expand Down
6 changes: 3 additions & 3 deletions Tests/Benchmarks/SolenoidFieldBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ int main(int argc, char* argv[]) {
Acts::MagneticFieldContext mctx{};

std::minstd_rand rng;
std::uniform_real_distribution<> zDist(1.5 * (-L / 2.), 1.5 * L / 2.);
std::uniform_real_distribution<> rDist(0, R * 1.5);
std::uniform_real_distribution<> phiDist(-M_PI, M_PI);
std::uniform_real_distribution<double> zDist(1.5 * (-L / 2.), 1.5 * L / 2.);
std::uniform_real_distribution<double> rDist(0, R * 1.5);
std::uniform_real_distribution<double> phiDist(-M_PI, M_PI);
auto genPos = [&]() -> Acts::Vector3 {
const double z = zDist(rng), r = rDist(rng), phi = phiDist(rng);
return {r * std::cos(phi), r * std::sin(phi), z};
Expand Down
11 changes: 6 additions & 5 deletions Tests/Benchmarks/SurfaceIntersectionBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Acts/Tests/CommonHelpers/BenchmarkTools.hpp"

#include <cmath>
#include <random>

namespace bdata = boost::unit_test::data;
namespace tt = boost::test_tools;
Expand Down Expand Up @@ -89,12 +90,12 @@ MicroBenchmarkResult intersectionTest(const surface_t& surface, double phi,

BOOST_DATA_TEST_CASE(
benchmark_surface_intersections,
bdata::random(
(bdata::seed = 21,
bdata::distribution = std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::random((bdata::seed = 22,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 21,
bdata::distribution =
std::uniform_real_distribution<double>(-M_PI, M_PI))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 22,
bdata::distribution =
std::uniform_real_distribution<>(-0.3, 0.3))) ^
std::uniform_real_distribution<double>(-0.3, 0.3))) ^
bdata::xrange(ntests),
phi, theta, index) {
(void)index;
Expand Down
14 changes: 8 additions & 6 deletions Tests/IntegrationTests/InterpolatedSolenoidBFieldTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ StreamWrapper valid(std::ofstream("magfield_lookup.csv"));
const int ntests = 10000;
BOOST_DATA_TEST_CASE(
solenoid_interpolated_bfield_comparison,
bdata::random((bdata::seed = 1, bdata::engine = std::mt19937(),
bdata::distribution = std::uniform_real_distribution<>(
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<double>(
1.5 * (-L / 2.), 1.5 * L / 2.))) ^
bdata::random((bdata::seed = 2, bdata::engine = std::mt19937(),
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(0, R * 1.5))) ^
bdata::random((bdata::seed = 3, bdata::engine = std::mt19937(),
std::uniform_real_distribution<double>(0,
R * 1.5))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(-M_PI, M_PI))) ^
std::uniform_real_distribution<double>(-M_PI,
M_PI))) ^
bdata::xrange(ntests),
z, r, phi, index) {
(void)index;
Expand Down
20 changes: 11 additions & 9 deletions Tests/UnitTests/Core/Digitization/PlanarModuleStepperTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ GeometryContext tgContext = GeometryContext();
/// guaranteed to be in on the readout/counter plane
BOOST_DATA_TEST_CASE(
readout_counter_test,
bdata::random((bdata::seed = 0,
bdata::distribution = std::uniform_real_distribution<>(
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 0,
bdata::distribution = std::uniform_real_distribution<double>(
-halfX + sguardX, halfX - sguardX))) ^
bdata::random((bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<>(
-halfX + sguardX, halfX - sguardX))) ^
bdata::random((bdata::seed = 2,
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<double>(
-halfX + sguardX, halfX - sguardX))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(-halfY, halfY))) ^
bdata::random((bdata::seed = 3,
bdata::distribution = std::uniform_int_distribution<>(
std::uniform_real_distribution<double>(-halfY,
halfY))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution = std::uniform_int_distribution<int>(
-static_cast<int>(halfY),
static_cast<int>(halfY)))) ^
bdata::xrange(ntests),
Expand Down
23 changes: 12 additions & 11 deletions Tests/UnitTests/Core/Geometry/BVHDataTestCase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ auto tg = grid.trackingGeometry;

BOOST_DATA_TEST_CASE(
bvhnavigation_test,
bdata::random((bdata::seed = 7, bdata::engine = std::mt19937(),
bdata::distribution = std::uniform_real_distribution<>(-5,
5))) ^
bdata::random((bdata::seed = 2, bdata::engine = std::mt19937(),
bdata::random(
(bdata::engine = std::mt19937(), bdata::seed = 7,
bdata::distribution = std::uniform_real_distribution<double>(-5, 5))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<>(-M_PI, M_PI))) ^
bdata::random((bdata::seed = 3, bdata::engine = std::mt19937(),
std::uniform_real_distribution<double>(-M_PI,
M_PI))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<>(-100, 100))) ^
bdata::random((bdata::seed = 4, bdata::engine = std::mt19937(),
std::uniform_real_distribution<double>(-100, 100))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution =
std::uniform_real_distribution<>(-100, 100))) ^
bdata::random((bdata::seed = 5, bdata::engine = std::mt19937(),
std::uniform_real_distribution<double>(-100, 100))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution =
std::uniform_real_distribution<>(-100, 100))) ^
std::uniform_real_distribution<double>(-100, 100))) ^
bdata::xrange(NTESTS),
eta, phi, x, y, z, index) {
using namespace Acts::UnitLiterals;
Expand Down
30 changes: 24 additions & 6 deletions Tests/UnitTests/Core/Geometry/CylinderVolumeBoundsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,30 @@ BOOST_AUTO_TEST_CASE(CylinderVolumeBoundsAccess) {
}

/// Unit test for testing the orientedSurfaces() function
BOOST_DATA_TEST_CASE(CylinderVolumeBoundsOrientedSurfaces,
bdata::random(-M_PI, M_PI) ^ bdata::random(-M_PI, M_PI) ^
bdata::random(-M_PI, M_PI) ^ bdata::random(-10., 10.) ^
bdata::random(-10., 10.) ^ bdata::random(-10., 10.) ^
bdata::xrange(100),
alpha, beta, gamma, posX, posY, posZ, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBoundsOrientedSurfaces,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution =
std::uniform_real_distribution<double>(-M_PI, M_PI))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<double>(-M_PI,
M_PI))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<double>(-M_PI,
M_PI))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution =
std::uniform_real_distribution<double>(-10., 10.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution =
std::uniform_real_distribution<double>(-10., 10.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
bdata::distribution =
std::uniform_real_distribution<double>(-10., 10.))) ^
bdata::xrange(100),
alpha, beta, gamma, posX, posY, posZ, index) {
(void)index;

// Create a test context
Expand Down
87 changes: 67 additions & 20 deletions Tests/UnitTests/Core/Geometry/CylinderVolumeBuilderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,28 @@ namespace Acts {
namespace Test {

/// Unit test for testing the wraps() function of the CylinderVolumeBuilder
BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_wraps,
bdata::random(-11., -15.) ^ bdata::random(11., 15.) ^
bdata::random(-10., 10.) ^ bdata::random(0., 4.) ^
bdata::random(11., 15.) ^ bdata::random(10., 15.) ^
bdata::xrange(100),
left, right, central, inner, outer, length, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_wraps,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution =
std::uniform_real_distribution<double>(-11., -15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<double>(11., 15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<double>(-10., 10.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution =
std::uniform_real_distribution<double>(0., 4.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution =
std::uniform_real_distribution<double>(11., 15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
bdata::distribution =
std::uniform_real_distribution<double>(10., 15.))) ^
bdata::xrange(100),
left, right, central, inner, outer, length, index) {
(void)index;
// inner volume
VolumeConfig innerConfig;
Expand Down Expand Up @@ -97,12 +113,28 @@ BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_wraps,

/// Unit test for testing the contains(), containsInR() and containsInZ()
/// function of the CylinderVolumeBuilder
BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_containes,
bdata::random(-11., -15.) ^ bdata::random(11., 15.) ^
bdata::random(-10., 10.) ^ bdata::random(0., 4.) ^
bdata::random(10., 15.) ^ bdata::random(10., 15.) ^
bdata::xrange(100),
left, right, central, inner, outer, length, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_containes,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution =
std::uniform_real_distribution<double>(-11., -15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<double>(11., 15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<double>(-10., 10.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
bdata::distribution =
std::uniform_real_distribution<double>(0., 4.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
bdata::distribution =
std::uniform_real_distribution<double>(10., 15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
bdata::distribution =
std::uniform_real_distribution<double>(10., 15.))) ^
bdata::xrange(100),
left, right, central, inner, outer, length, index) {
(void)index;
// inner volume
VolumeConfig innerConfig;
Expand Down Expand Up @@ -184,10 +216,16 @@ BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_containes,

/// Unit test for testing the coverlapsInR()
/// function of the CylinderVolumeBuilder
BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_overlapsInR,
bdata::random(0., 4.) ^ bdata::random(11., 15.) ^
bdata::xrange(100),
inner, outer, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_overlapsInR,
bdata::random((
bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution = std::uniform_real_distribution<double>(0., 4.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<double>(11., 15.))) ^
bdata::xrange(100),
inner, outer, index) {
(void)index;
// reference volume
VolumeConfig Config0;
Expand Down Expand Up @@ -246,10 +284,19 @@ BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_overlapsInR,

/// Unit test for testing the coverlapsInZ()
/// function of the CylinderVolumeBuilder
BOOST_DATA_TEST_CASE(CylinderVolumeBuilder_overlapsInZ,
bdata::random(-11., -15.) ^ bdata::random(11., 15.) ^
bdata::random(0., 4.) ^ bdata::xrange(100),
left, right, inner, index) {
BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_overlapsInZ,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution =
std::uniform_real_distribution<double>(-11., -15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<double>(11., 15.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
bdata::distribution =
std::uniform_real_distribution<double>(0., 4.))) ^
bdata::xrange(100),
left, right, inner, index) {
(void)index;
// inner volume
VolumeConfig Config0;
Expand Down
Loading
Loading