madspace 0.3.1__cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- madspace/__init__.py +1 -0
- madspace/_madspace_py.cpython-314-x86_64-linux-gnu.so +0 -0
- madspace/_madspace_py.pyi +2189 -0
- madspace/_madspace_py_loader.py +111 -0
- madspace/include/madspace/constants.h +17 -0
- madspace/include/madspace/madcode/function.h +102 -0
- madspace/include/madspace/madcode/function_builder_mixin.h +591 -0
- madspace/include/madspace/madcode/instruction.h +208 -0
- madspace/include/madspace/madcode/opcode_mixin.h +134 -0
- madspace/include/madspace/madcode/optimizer.h +31 -0
- madspace/include/madspace/madcode/type.h +203 -0
- madspace/include/madspace/madcode.h +6 -0
- madspace/include/madspace/phasespace/base.h +74 -0
- madspace/include/madspace/phasespace/channel_weight_network.h +46 -0
- madspace/include/madspace/phasespace/channel_weights.h +51 -0
- madspace/include/madspace/phasespace/chili.h +32 -0
- madspace/include/madspace/phasespace/cross_section.h +47 -0
- madspace/include/madspace/phasespace/cuts.h +34 -0
- madspace/include/madspace/phasespace/discrete_flow.h +44 -0
- madspace/include/madspace/phasespace/discrete_sampler.h +53 -0
- madspace/include/madspace/phasespace/flow.h +53 -0
- madspace/include/madspace/phasespace/histograms.h +26 -0
- madspace/include/madspace/phasespace/integrand.h +204 -0
- madspace/include/madspace/phasespace/invariants.h +26 -0
- madspace/include/madspace/phasespace/luminosity.h +41 -0
- madspace/include/madspace/phasespace/matrix_element.h +70 -0
- madspace/include/madspace/phasespace/mlp.h +37 -0
- madspace/include/madspace/phasespace/multichannel.h +49 -0
- madspace/include/madspace/phasespace/observable.h +85 -0
- madspace/include/madspace/phasespace/pdf.h +78 -0
- madspace/include/madspace/phasespace/phasespace.h +67 -0
- madspace/include/madspace/phasespace/rambo.h +26 -0
- madspace/include/madspace/phasespace/scale.h +52 -0
- madspace/include/madspace/phasespace/t_propagator_mapping.h +34 -0
- madspace/include/madspace/phasespace/three_particle.h +68 -0
- madspace/include/madspace/phasespace/topology.h +116 -0
- madspace/include/madspace/phasespace/two_particle.h +63 -0
- madspace/include/madspace/phasespace/vegas.h +53 -0
- madspace/include/madspace/phasespace.h +27 -0
- madspace/include/madspace/runtime/context.h +147 -0
- madspace/include/madspace/runtime/discrete_optimizer.h +24 -0
- madspace/include/madspace/runtime/event_generator.h +257 -0
- madspace/include/madspace/runtime/format.h +68 -0
- madspace/include/madspace/runtime/io.h +343 -0
- madspace/include/madspace/runtime/lhe_output.h +132 -0
- madspace/include/madspace/runtime/logger.h +46 -0
- madspace/include/madspace/runtime/runtime_base.h +39 -0
- madspace/include/madspace/runtime/tensor.h +603 -0
- madspace/include/madspace/runtime/thread_pool.h +101 -0
- madspace/include/madspace/runtime/vegas_optimizer.h +26 -0
- madspace/include/madspace/runtime.h +12 -0
- madspace/include/madspace/umami.h +202 -0
- madspace/include/madspace/util.h +142 -0
- madspace/lib/libmadspace.so +0 -0
- madspace/lib/libmadspace_cpu.so +0 -0
- madspace/lib/libmadspace_cpu_avx2.so +0 -0
- madspace/lib/libmadspace_cpu_avx512.so +0 -0
- madspace/lib/libmadspace_cuda.so +0 -0
- madspace/lib/libmadspace_hip.so +0 -0
- madspace/madnis/__init__.py +44 -0
- madspace/madnis/buffer.py +167 -0
- madspace/madnis/channel_grouping.py +85 -0
- madspace/madnis/distribution.py +103 -0
- madspace/madnis/integrand.py +175 -0
- madspace/madnis/integrator.py +973 -0
- madspace/madnis/interface.py +191 -0
- madspace/madnis/losses.py +186 -0
- madspace/torch.py +82 -0
- madspace-0.3.1.dist-info/METADATA +71 -0
- madspace-0.3.1.dist-info/RECORD +75 -0
- madspace-0.3.1.dist-info/WHEEL +6 -0
- madspace-0.3.1.dist-info/licenses/LICENSE +21 -0
- madspace.libs/libgfortran-83c28eba.so.5.0.0 +0 -0
- madspace.libs/libopenblas-r0-11edc3fa.3.15.so +0 -0
- madspace.libs/libquadmath-2284e583.so.0.0.0 +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "madspace/phasespace/base.h"
|
|
4
|
+
#include "madspace/runtime/context.h"
|
|
5
|
+
|
|
6
|
+
namespace madspace {
|
|
7
|
+
|
|
8
|
+
class VegasHistogram : public FunctionGenerator {
|
|
9
|
+
public:
|
|
10
|
+
VegasHistogram(std::size_t dimension, std::size_t bin_count);
|
|
11
|
+
|
|
12
|
+
private:
|
|
13
|
+
ValueVec
|
|
14
|
+
build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
|
|
15
|
+
|
|
16
|
+
std::size_t _bin_count;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
class VegasMapping : public Mapping {
|
|
20
|
+
public:
|
|
21
|
+
VegasMapping(
|
|
22
|
+
std::size_t dimension, std::size_t bin_count, const std::string& prefix = ""
|
|
23
|
+
) :
|
|
24
|
+
Mapping(
|
|
25
|
+
"VegasMapping",
|
|
26
|
+
{batch_float_array(dimension)},
|
|
27
|
+
{batch_float_array(dimension)},
|
|
28
|
+
{}
|
|
29
|
+
),
|
|
30
|
+
_dimension(dimension),
|
|
31
|
+
_bin_count(bin_count),
|
|
32
|
+
_grid_name(prefixed_name(prefix, "vegas_grid")) {}
|
|
33
|
+
const std::string& grid_name() const { return _grid_name; }
|
|
34
|
+
void initialize_globals(ContextPtr context) const;
|
|
35
|
+
std::size_t dimension() const { return _dimension; }
|
|
36
|
+
std::size_t bin_count() const { return _bin_count; }
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
Result build_forward_impl(
|
|
40
|
+
FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
|
|
41
|
+
) const override;
|
|
42
|
+
Result build_inverse_impl(
|
|
43
|
+
FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
|
|
44
|
+
) const override;
|
|
45
|
+
|
|
46
|
+
std::size_t _dimension;
|
|
47
|
+
std::size_t _bin_count;
|
|
48
|
+
std::string _grid_name;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
void initialize_vegas_grid(ContextPtr context, const std::string& grid_name);
|
|
52
|
+
|
|
53
|
+
} // namespace madspace
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "phasespace/base.h"
|
|
4
|
+
#include "phasespace/channel_weight_network.h"
|
|
5
|
+
#include "phasespace/channel_weights.h"
|
|
6
|
+
#include "phasespace/cross_section.h"
|
|
7
|
+
#include "phasespace/cuts.h"
|
|
8
|
+
#include "phasespace/discrete_flow.h"
|
|
9
|
+
#include "phasespace/discrete_sampler.h"
|
|
10
|
+
#include "phasespace/flow.h"
|
|
11
|
+
#include "phasespace/histograms.h"
|
|
12
|
+
#include "phasespace/integrand.h"
|
|
13
|
+
#include "phasespace/invariants.h"
|
|
14
|
+
#include "phasespace/luminosity.h"
|
|
15
|
+
#include "phasespace/matrix_element.h"
|
|
16
|
+
#include "phasespace/mlp.h"
|
|
17
|
+
#include "phasespace/multichannel.h"
|
|
18
|
+
#include "phasespace/observable.h"
|
|
19
|
+
#include "phasespace/pdf.h"
|
|
20
|
+
#include "phasespace/phasespace.h"
|
|
21
|
+
#include "phasespace/rambo.h"
|
|
22
|
+
#include "phasespace/scale.h"
|
|
23
|
+
#include "phasespace/t_propagator_mapping.h"
|
|
24
|
+
#include "phasespace/three_particle.h"
|
|
25
|
+
#include "phasespace/topology.h"
|
|
26
|
+
#include "phasespace/two_particle.h"
|
|
27
|
+
#include "phasespace/vegas.h"
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <stdint.h>
|
|
4
|
+
#include <unordered_map>
|
|
5
|
+
|
|
6
|
+
#include "madspace/madcode.h"
|
|
7
|
+
#include "madspace/runtime/tensor.h"
|
|
8
|
+
#include "madspace/runtime/thread_pool.h"
|
|
9
|
+
#include "madspace/umami.h"
|
|
10
|
+
|
|
11
|
+
namespace madspace {
|
|
12
|
+
|
|
13
|
+
class MatrixElementApi {
|
|
14
|
+
public:
|
|
15
|
+
MatrixElementApi(
|
|
16
|
+
const std::string& file, const std::string& param_card, std::size_t index = 0
|
|
17
|
+
);
|
|
18
|
+
MatrixElementApi(MatrixElementApi&&) noexcept = default;
|
|
19
|
+
MatrixElementApi& operator=(MatrixElementApi&&) noexcept = default;
|
|
20
|
+
MatrixElementApi(const MatrixElementApi&) = delete;
|
|
21
|
+
MatrixElementApi& operator=(const MatrixElementApi&) = delete;
|
|
22
|
+
DevicePtr device() const {
|
|
23
|
+
UmamiDevice dev;
|
|
24
|
+
check_umami_status(_get_meta(UMAMI_META_DEVICE, &dev));
|
|
25
|
+
switch (dev) {
|
|
26
|
+
case UMAMI_DEVICE_CPU:
|
|
27
|
+
return cpu_device();
|
|
28
|
+
case UMAMI_DEVICE_CUDA:
|
|
29
|
+
return cuda_device();
|
|
30
|
+
case UMAMI_DEVICE_HIP:
|
|
31
|
+
return hip_device();
|
|
32
|
+
default:
|
|
33
|
+
throw_error("matrix element device not known");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
std::size_t particle_count() const {
|
|
37
|
+
int count;
|
|
38
|
+
check_umami_status(_get_meta(UMAMI_META_PARTICLE_COUNT, &count));
|
|
39
|
+
return count;
|
|
40
|
+
}
|
|
41
|
+
std::size_t diagram_count() const {
|
|
42
|
+
int count;
|
|
43
|
+
check_umami_status(_get_meta(UMAMI_META_DIAGRAM_COUNT, &count));
|
|
44
|
+
return count;
|
|
45
|
+
}
|
|
46
|
+
std::size_t helicity_count() const {
|
|
47
|
+
int count;
|
|
48
|
+
check_umami_status(_get_meta(UMAMI_META_HELICITY_COUNT, &count));
|
|
49
|
+
return count;
|
|
50
|
+
}
|
|
51
|
+
std::size_t index() const { return _index; }
|
|
52
|
+
const std::string& file_name() const { return _file_name; }
|
|
53
|
+
|
|
54
|
+
void call(
|
|
55
|
+
UmamiHandle handle,
|
|
56
|
+
size_t count,
|
|
57
|
+
size_t stride,
|
|
58
|
+
size_t offset,
|
|
59
|
+
size_t input_count,
|
|
60
|
+
UmamiInputKey const* input_keys,
|
|
61
|
+
void const* const* inputs,
|
|
62
|
+
size_t output_count,
|
|
63
|
+
UmamiOutputKey const* output_keys,
|
|
64
|
+
void* const* outputs
|
|
65
|
+
) const {
|
|
66
|
+
check_umami_status(_matrix_element(
|
|
67
|
+
handle,
|
|
68
|
+
count,
|
|
69
|
+
stride,
|
|
70
|
+
offset,
|
|
71
|
+
input_count,
|
|
72
|
+
input_keys,
|
|
73
|
+
inputs,
|
|
74
|
+
output_count,
|
|
75
|
+
output_keys,
|
|
76
|
+
outputs
|
|
77
|
+
));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
void* process_instance(std::size_t index) const {
|
|
81
|
+
return _instances.get(index).get();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private:
|
|
85
|
+
void check_umami_status(UmamiStatus status) const;
|
|
86
|
+
[[noreturn]] void throw_error(const std::string& message) const;
|
|
87
|
+
std::unique_ptr<void, std::function<void(void*)>> _shared_lib;
|
|
88
|
+
decltype(&umami_get_meta) _get_meta;
|
|
89
|
+
decltype(&umami_initialize) _initialize;
|
|
90
|
+
decltype(&umami_matrix_element) _matrix_element;
|
|
91
|
+
decltype(&umami_free) _free;
|
|
92
|
+
using InstanceType = std::unique_ptr<void, std::function<void(void*)>>;
|
|
93
|
+
ThreadResource<InstanceType> _instances;
|
|
94
|
+
std::string _file_name;
|
|
95
|
+
std::size_t _index;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
class Context {
|
|
99
|
+
/**
|
|
100
|
+
* Contains global variables and matrix elements
|
|
101
|
+
*/
|
|
102
|
+
public:
|
|
103
|
+
Context() : _device(cpu_device()) {}
|
|
104
|
+
Context(DevicePtr device) : _device(device) {}
|
|
105
|
+
Context(Context&&) = default;
|
|
106
|
+
Context& operator=(Context&&) = default;
|
|
107
|
+
Context(const Context&) = delete;
|
|
108
|
+
Context& operator=(const Context&) = delete;
|
|
109
|
+
const MatrixElementApi&
|
|
110
|
+
load_matrix_element(const std::string& file, const std::string& param_card);
|
|
111
|
+
Tensor define_global(
|
|
112
|
+
const std::string& name,
|
|
113
|
+
DataType dtype,
|
|
114
|
+
const SizeVec& shape,
|
|
115
|
+
bool requires_grad = false
|
|
116
|
+
);
|
|
117
|
+
Tensor global(const std::string& name);
|
|
118
|
+
bool global_requires_grad(const std::string& name);
|
|
119
|
+
bool global_exists(const std::string& name);
|
|
120
|
+
std::vector<std::string> global_names() const;
|
|
121
|
+
void delete_global(const std::string& name);
|
|
122
|
+
const MatrixElementApi& matrix_element(std::size_t index) const;
|
|
123
|
+
void save(const std::string& file) const;
|
|
124
|
+
void load(const std::string& file);
|
|
125
|
+
DevicePtr device() { return _device; }
|
|
126
|
+
|
|
127
|
+
private:
|
|
128
|
+
// make sure that ThreadPool outlives any Context instance
|
|
129
|
+
inline static ThreadPool& thread_pool_ref = default_thread_pool();
|
|
130
|
+
DevicePtr _device;
|
|
131
|
+
std::unordered_map<std::string, std::tuple<Tensor, bool>> _globals;
|
|
132
|
+
std::vector<MatrixElementApi> _matrix_elements;
|
|
133
|
+
std::vector<std::string> _param_card_paths;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
using ContextPtr = std::shared_ptr<Context>;
|
|
137
|
+
|
|
138
|
+
ContextPtr default_context();
|
|
139
|
+
ContextPtr default_cuda_context();
|
|
140
|
+
ContextPtr default_hip_context();
|
|
141
|
+
ContextPtr default_device_context(DevicePtr device);
|
|
142
|
+
|
|
143
|
+
inline std::string prefixed_name(const std::string& prefix, const std::string& name) {
|
|
144
|
+
return prefix == "" ? name : std::format("{}.{}", prefix, name);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
} // namespace madspace
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "madspace/madcode.h"
|
|
4
|
+
#include "madspace/runtime/context.h"
|
|
5
|
+
#include "madspace/runtime/tensor.h"
|
|
6
|
+
|
|
7
|
+
namespace madspace {
|
|
8
|
+
|
|
9
|
+
class DiscreteOptimizer {
|
|
10
|
+
public:
|
|
11
|
+
DiscreteOptimizer(ContextPtr context, const std::vector<std::string>& prob_names) :
|
|
12
|
+
_context(context), _prob_names(prob_names), _sample_count(7000) {}
|
|
13
|
+
void add_data(const std::vector<Tensor>& values_and_counts);
|
|
14
|
+
void optimize();
|
|
15
|
+
|
|
16
|
+
private:
|
|
17
|
+
ContextPtr _context;
|
|
18
|
+
std::vector<std::string> _prob_names;
|
|
19
|
+
double _damping;
|
|
20
|
+
std::size_t _sample_count;
|
|
21
|
+
std::vector<std::tuple<std::vector<std::size_t>, std::vector<double>>> _data;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
} // namespace madspace
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <chrono>
|
|
4
|
+
#include <optional>
|
|
5
|
+
#include <random>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
#include <nlohmann/json.hpp>
|
|
9
|
+
|
|
10
|
+
#include "madspace/madcode.h"
|
|
11
|
+
#include "madspace/phasespace.h"
|
|
12
|
+
#include "madspace/runtime/discrete_optimizer.h"
|
|
13
|
+
#include "madspace/runtime/format.h"
|
|
14
|
+
#include "madspace/runtime/io.h"
|
|
15
|
+
#include "madspace/runtime/runtime_base.h"
|
|
16
|
+
#include "madspace/runtime/vegas_optimizer.h"
|
|
17
|
+
|
|
18
|
+
namespace madspace {
|
|
19
|
+
|
|
20
|
+
class RunningIntegral {
|
|
21
|
+
public:
|
|
22
|
+
RunningIntegral() : _mean(0), _var_sum(0), _count(0) {}
|
|
23
|
+
double mean() const { return _mean; }
|
|
24
|
+
double variance() const { return _count > 1 ? _var_sum / (_count - 1) : 0; }
|
|
25
|
+
double error() const { return std::sqrt(variance() / _count); }
|
|
26
|
+
double rel_error() const { return error() / mean(); }
|
|
27
|
+
double rel_std_dev() const { return std::sqrt(variance()) / _mean; }
|
|
28
|
+
std::size_t count() const { return _count; }
|
|
29
|
+
void reset() {
|
|
30
|
+
_mean = 0;
|
|
31
|
+
_var_sum = 0;
|
|
32
|
+
_count = 0;
|
|
33
|
+
}
|
|
34
|
+
void push(double value) {
|
|
35
|
+
++_count;
|
|
36
|
+
if (_count == 1) {
|
|
37
|
+
_mean = value;
|
|
38
|
+
_var_sum = 0;
|
|
39
|
+
} else {
|
|
40
|
+
double mean_diff = value - _mean;
|
|
41
|
+
_mean += mean_diff / _count;
|
|
42
|
+
_var_sum += mean_diff * (value - _mean);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
double _mean;
|
|
48
|
+
double _var_sum;
|
|
49
|
+
std::size_t _count;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
class EventGenerator {
|
|
53
|
+
public:
|
|
54
|
+
static inline const int integrand_flags = Integrand::sample |
|
|
55
|
+
Integrand::return_momenta | Integrand::return_indices |
|
|
56
|
+
Integrand::return_random | Integrand::return_discrete;
|
|
57
|
+
enum Verbosity { silent, log, pretty };
|
|
58
|
+
struct Config {
|
|
59
|
+
std::size_t target_count = 10000;
|
|
60
|
+
double vegas_damping = 0.2;
|
|
61
|
+
double max_overweight_truncation = 0.01;
|
|
62
|
+
std::size_t freeze_max_weight_after = 10000;
|
|
63
|
+
std::size_t start_batch_size = 1000;
|
|
64
|
+
std::size_t max_batch_size = 64000;
|
|
65
|
+
std::size_t survey_min_iters = 3;
|
|
66
|
+
std::size_t survey_max_iters = 4;
|
|
67
|
+
double survey_target_precision = 0.1;
|
|
68
|
+
std::size_t optimization_patience = 3;
|
|
69
|
+
double optimization_threshold = 0.99;
|
|
70
|
+
std::size_t batch_size = 1000;
|
|
71
|
+
Verbosity verbosity = silent;
|
|
72
|
+
bool write_live_data = false;
|
|
73
|
+
};
|
|
74
|
+
static const Config default_config;
|
|
75
|
+
struct Status {
|
|
76
|
+
std::size_t index;
|
|
77
|
+
std::size_t subprocess;
|
|
78
|
+
std::string name;
|
|
79
|
+
double mean;
|
|
80
|
+
double error;
|
|
81
|
+
double rel_std_dev;
|
|
82
|
+
std::size_t count;
|
|
83
|
+
std::size_t count_opt;
|
|
84
|
+
std::size_t count_after_cuts;
|
|
85
|
+
std::size_t count_after_cuts_opt;
|
|
86
|
+
double count_unweighted;
|
|
87
|
+
double count_target;
|
|
88
|
+
std::size_t iterations;
|
|
89
|
+
bool optimized;
|
|
90
|
+
bool done;
|
|
91
|
+
};
|
|
92
|
+
struct Histogram {
|
|
93
|
+
std::string name;
|
|
94
|
+
double min;
|
|
95
|
+
double max;
|
|
96
|
+
std::vector<double> bin_values;
|
|
97
|
+
std::vector<double> bin_errors;
|
|
98
|
+
};
|
|
99
|
+
static void set_abort_check_function(std::function<void(void)> func) {
|
|
100
|
+
_abort_check_function = func;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
EventGenerator(
|
|
104
|
+
ContextPtr context,
|
|
105
|
+
const std::vector<Integrand>& channels,
|
|
106
|
+
const std::string& temp_file_prefix,
|
|
107
|
+
const std::string& status_file = "",
|
|
108
|
+
const Config& config = default_config,
|
|
109
|
+
const std::vector<std::size_t>& channel_subprocesses = {},
|
|
110
|
+
const std::vector<std::string>& channel_names = {},
|
|
111
|
+
const std::vector<ObservableHistograms>& channel_histograms = {}
|
|
112
|
+
);
|
|
113
|
+
void survey();
|
|
114
|
+
void generate();
|
|
115
|
+
void combine_to_compact_npy(const std::string& file_name);
|
|
116
|
+
void combine_to_lhe_npy(const std::string& file_name, LHECompleter& lhe_completer);
|
|
117
|
+
void combine_to_lhe(const std::string& file_name, LHECompleter& lhe_completer);
|
|
118
|
+
Status status() const { return _status_all; }
|
|
119
|
+
std::vector<Status> channel_status() const;
|
|
120
|
+
std::vector<Histogram> histograms() const;
|
|
121
|
+
|
|
122
|
+
private:
|
|
123
|
+
struct ChannelState {
|
|
124
|
+
std::size_t index;
|
|
125
|
+
RuntimePtr runtime;
|
|
126
|
+
EventFile event_file;
|
|
127
|
+
EventFile weight_file;
|
|
128
|
+
std::optional<VegasGridOptimizer> vegas_optimizer;
|
|
129
|
+
RuntimePtr vegas_histogram;
|
|
130
|
+
std::optional<DiscreteOptimizer> discrete_optimizer;
|
|
131
|
+
RuntimePtr discrete_histogram;
|
|
132
|
+
RuntimePtr observable_histograms;
|
|
133
|
+
std::size_t batch_size;
|
|
134
|
+
std::string name;
|
|
135
|
+
std::size_t subprocess_index;
|
|
136
|
+
RunningIntegral cross_section;
|
|
137
|
+
bool needs_optimization = true;
|
|
138
|
+
double max_weight = 0.;
|
|
139
|
+
double eff_count = 0.;
|
|
140
|
+
double integral_fraction = 1.;
|
|
141
|
+
std::size_t total_sample_count = 0;
|
|
142
|
+
std::size_t total_sample_count_opt = 0;
|
|
143
|
+
std::size_t total_sample_count_after_cuts = 0;
|
|
144
|
+
std::size_t total_sample_count_after_cuts_opt = 0;
|
|
145
|
+
std::size_t iterations = 0;
|
|
146
|
+
std::size_t iters_without_improvement = 0;
|
|
147
|
+
double best_rsd = std::numeric_limits<double>::max();
|
|
148
|
+
std::vector<double> large_weights;
|
|
149
|
+
std::size_t job_count = 0;
|
|
150
|
+
nested_vector2<std::pair<double, double>> histograms;
|
|
151
|
+
};
|
|
152
|
+
struct RunningJob {
|
|
153
|
+
std::size_t channel_index;
|
|
154
|
+
TensorVec events;
|
|
155
|
+
std::size_t vegas_job_count;
|
|
156
|
+
};
|
|
157
|
+
struct CombineChannelData {
|
|
158
|
+
std::size_t cum_count;
|
|
159
|
+
EventBuffer event_buffer;
|
|
160
|
+
EventBuffer weight_buffer;
|
|
161
|
+
std::size_t buffer_index;
|
|
162
|
+
};
|
|
163
|
+
struct TimingData {
|
|
164
|
+
double wall_time_sec;
|
|
165
|
+
double cpu_time_sec;
|
|
166
|
+
};
|
|
167
|
+
inline static std::function<void(void)> _abort_check_function = [] {};
|
|
168
|
+
|
|
169
|
+
ContextPtr _context;
|
|
170
|
+
Config _config;
|
|
171
|
+
std::vector<ChannelState> _channels;
|
|
172
|
+
RuntimePtr _unweighter;
|
|
173
|
+
Status _status_all;
|
|
174
|
+
std::unordered_map<std::size_t, RunningJob> _running_jobs;
|
|
175
|
+
std::size_t _job_id;
|
|
176
|
+
std::chrono::time_point<std::chrono::steady_clock> _start_time;
|
|
177
|
+
std::size_t _start_cpu_microsec;
|
|
178
|
+
std::chrono::time_point<std::chrono::steady_clock> _last_print_time;
|
|
179
|
+
std::chrono::time_point<std::chrono::steady_clock> _last_status_time;
|
|
180
|
+
PrettyBox _pretty_box_upper;
|
|
181
|
+
PrettyBox _pretty_box_lower;
|
|
182
|
+
std::string _status_file;
|
|
183
|
+
std::unordered_map<std::string, TimingData> _timing_data;
|
|
184
|
+
std::vector<Histogram> _empty_histograms;
|
|
185
|
+
|
|
186
|
+
void reset_start_time();
|
|
187
|
+
void add_timing_data(const std::string& key);
|
|
188
|
+
std::string format_run_time(const std::string& key) const;
|
|
189
|
+
void unweight_all();
|
|
190
|
+
void unweight_channel(ChannelState& channel, std::mt19937 rand_gen);
|
|
191
|
+
std::tuple<Tensor, std::vector<Tensor>> integrate_and_optimize(
|
|
192
|
+
ChannelState& channel, TensorVec& events, bool always_optimize
|
|
193
|
+
);
|
|
194
|
+
double channel_weight_sum(ChannelState& channel, std::size_t event_count);
|
|
195
|
+
void start_job(
|
|
196
|
+
ChannelState& channel, std::size_t batch_size, std::size_t vegas_job_count = 0
|
|
197
|
+
);
|
|
198
|
+
void start_vegas_jobs(ChannelState& channel);
|
|
199
|
+
void clear_channel(ChannelState& channel);
|
|
200
|
+
void update_max_weight(ChannelState& channel, Tensor weights);
|
|
201
|
+
void unweight_and_write(ChannelState& channel, const std::vector<Tensor>& momenta);
|
|
202
|
+
std::size_t max_particle_count();
|
|
203
|
+
std::tuple<std::vector<CombineChannelData>, std::size_t, double> init_combine();
|
|
204
|
+
void read_and_combine(
|
|
205
|
+
std::vector<CombineChannelData>& channel_data,
|
|
206
|
+
EventBuffer& buffer,
|
|
207
|
+
double norm_factor
|
|
208
|
+
);
|
|
209
|
+
void fill_lhe_event(
|
|
210
|
+
LHECompleter& lhe_completer,
|
|
211
|
+
LHEEvent& lhe_event,
|
|
212
|
+
EventBuffer& buffer,
|
|
213
|
+
std::size_t event_index
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
void init_status(const std::string& status);
|
|
217
|
+
void write_status(const std::string& status, bool force_write);
|
|
218
|
+
|
|
219
|
+
void print_survey_init();
|
|
220
|
+
void print_survey_update(
|
|
221
|
+
bool done,
|
|
222
|
+
std::size_t done_job_count,
|
|
223
|
+
std::size_t total_job_count,
|
|
224
|
+
std::size_t iter
|
|
225
|
+
);
|
|
226
|
+
void print_survey_update_pretty(
|
|
227
|
+
bool done,
|
|
228
|
+
std::size_t done_job_count,
|
|
229
|
+
std::size_t total_job_count,
|
|
230
|
+
std::size_t iter
|
|
231
|
+
);
|
|
232
|
+
void print_survey_update_log(
|
|
233
|
+
bool done,
|
|
234
|
+
std::size_t done_job_count,
|
|
235
|
+
std::size_t total_job_count,
|
|
236
|
+
std::size_t iter
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
void print_gen_init();
|
|
240
|
+
void print_gen_update(bool done);
|
|
241
|
+
void print_gen_update_pretty(bool done);
|
|
242
|
+
void print_gen_update_log(bool done);
|
|
243
|
+
|
|
244
|
+
void print_combine_init();
|
|
245
|
+
void print_combine_update(std::size_t count);
|
|
246
|
+
void print_combine_update_pretty(std::size_t count);
|
|
247
|
+
void print_combine_update_log(std::size_t count);
|
|
248
|
+
|
|
249
|
+
friend void
|
|
250
|
+
to_json(nlohmann::json& j, const EventGenerator::TimingData& timing_data);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
void to_json(nlohmann::json& j, const EventGenerator::TimingData& timing_data);
|
|
254
|
+
void to_json(nlohmann::json& j, const EventGenerator::Status& status);
|
|
255
|
+
void to_json(nlohmann::json& j, const EventGenerator::Histogram& hist);
|
|
256
|
+
|
|
257
|
+
} // namespace madspace
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <stdexcept>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
namespace madspace {
|
|
8
|
+
|
|
9
|
+
std::string format_si_prefix(double value);
|
|
10
|
+
std::string format_with_error(double value, double error);
|
|
11
|
+
std::string format_progress(double progress, int width);
|
|
12
|
+
|
|
13
|
+
class PrettyBox {
|
|
14
|
+
public:
|
|
15
|
+
PrettyBox() = default;
|
|
16
|
+
PrettyBox(
|
|
17
|
+
const std::string& title,
|
|
18
|
+
std::size_t rows,
|
|
19
|
+
const std::vector<std::size_t>& column_sizes,
|
|
20
|
+
std::size_t offset = 0,
|
|
21
|
+
std::size_t box_width = 91
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
void print_first() const;
|
|
25
|
+
void print_update() const;
|
|
26
|
+
std::size_t line_count() const { return _rows + 3; }
|
|
27
|
+
|
|
28
|
+
void set_row(std::size_t row, const std::vector<std::string>& values) {
|
|
29
|
+
if (row >= _rows) {
|
|
30
|
+
throw std::out_of_range("row index out of range");
|
|
31
|
+
}
|
|
32
|
+
for (std::size_t column = 0; auto& value : values) {
|
|
33
|
+
_content.at(row * _columns + column) = value;
|
|
34
|
+
++column;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void set_column(std::size_t column, const std::vector<std::string>& values) {
|
|
39
|
+
if (column >= _columns) {
|
|
40
|
+
throw std::out_of_range("column index out of range");
|
|
41
|
+
}
|
|
42
|
+
for (std::size_t row = 0; auto& value : values) {
|
|
43
|
+
_content.at(row * _columns + column) = value;
|
|
44
|
+
++row;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void set_cell(std::size_t row, std::size_t column, std::string value) {
|
|
49
|
+
if (row >= _rows) {
|
|
50
|
+
throw std::out_of_range("row index out of range");
|
|
51
|
+
}
|
|
52
|
+
if (column >= _columns) {
|
|
53
|
+
throw std::out_of_range("column index out of range");
|
|
54
|
+
}
|
|
55
|
+
_content.at(row * _columns + column) = value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private:
|
|
59
|
+
std::string _header;
|
|
60
|
+
std::string _footer;
|
|
61
|
+
std::size_t _rows;
|
|
62
|
+
std::size_t _columns;
|
|
63
|
+
std::size_t _offset;
|
|
64
|
+
std::vector<std::size_t> _column_ends;
|
|
65
|
+
std::vector<std::string> _content;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
} // namespace madspace
|