madspace 0.3.1__cp314-cp314-macosx_14_0_arm64.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-darwin.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.dylib +0 -0
- madspace/lib/libmadspace_cpu.dylib +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 +68 -0
- madspace-0.3.1.dist-info/WHEEL +6 -0
- madspace-0.3.1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstring>
|
|
4
|
+
#include <fstream>
|
|
5
|
+
|
|
6
|
+
#include "madspace/runtime/lhe_output.h"
|
|
7
|
+
#include "madspace/runtime/tensor.h"
|
|
8
|
+
|
|
9
|
+
namespace madspace {
|
|
10
|
+
|
|
11
|
+
Tensor load_tensor(const std::string& file);
|
|
12
|
+
void save_tensor(const std::string& file, Tensor tensor);
|
|
13
|
+
|
|
14
|
+
using FieldLayout = std::pair<const char*, const char*>;
|
|
15
|
+
|
|
16
|
+
template <typename T>
|
|
17
|
+
class UnalignedRef {
|
|
18
|
+
public:
|
|
19
|
+
UnalignedRef(void* ptr) : _ptr(ptr) {}
|
|
20
|
+
T value() const {
|
|
21
|
+
T value;
|
|
22
|
+
std::memcpy(&value, _ptr, sizeof(T));
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
operator T() const { return value(); }
|
|
26
|
+
UnalignedRef<T> operator=(const T& value) {
|
|
27
|
+
std::memcpy(_ptr, &value, sizeof(T));
|
|
28
|
+
return *this;
|
|
29
|
+
}
|
|
30
|
+
UnalignedRef<T> operator=(const UnalignedRef<T>& value) {
|
|
31
|
+
std::memcpy(_ptr, value._ptr, sizeof(T));
|
|
32
|
+
return *this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private:
|
|
36
|
+
void* _ptr;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
struct ParticleRecord {
|
|
40
|
+
static constexpr std::size_t size = 32;
|
|
41
|
+
static constexpr std::array<FieldLayout, 4> layout = {
|
|
42
|
+
{{"energy", "<f8"}, {"px", "<f8"}, {"py", "<f8"}, {"pz", "<f8"}}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
UnalignedRef<double> energy() { return &data[0]; }
|
|
46
|
+
UnalignedRef<double> px() { return &data[8]; }
|
|
47
|
+
UnalignedRef<double> py() { return &data[16]; }
|
|
48
|
+
UnalignedRef<double> pz() { return &data[24]; }
|
|
49
|
+
|
|
50
|
+
char* data;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
constexpr int record_weight = 1;
|
|
54
|
+
constexpr int record_subproc_index = 2;
|
|
55
|
+
constexpr int record_indices = 4;
|
|
56
|
+
|
|
57
|
+
template <int fields>
|
|
58
|
+
struct EventRecord {
|
|
59
|
+
static constexpr std::size_t size = (fields & record_weight ? 8 : 0) +
|
|
60
|
+
(fields & record_subproc_index ? 4 : 0) + (fields & record_indices ? 16 : 0);
|
|
61
|
+
static constexpr std::size_t subproc_index_offset = fields & record_weight ? 8 : 0;
|
|
62
|
+
static constexpr std::size_t indices_offset =
|
|
63
|
+
subproc_index_offset + (fields & record_subproc_index ? 4 : 0);
|
|
64
|
+
|
|
65
|
+
static constexpr std::size_t field_count = (fields & record_weight ? 1 : 0) +
|
|
66
|
+
(fields & record_subproc_index ? 1 : 0) + (fields & record_indices ? 4 : 0);
|
|
67
|
+
static constexpr std::array<FieldLayout, field_count> layout = [] {
|
|
68
|
+
std::array<FieldLayout, field_count> layout;
|
|
69
|
+
std::size_t offset = 0;
|
|
70
|
+
if (fields & record_weight) {
|
|
71
|
+
layout[0] = {"weight", "<f8"};
|
|
72
|
+
offset += 1;
|
|
73
|
+
}
|
|
74
|
+
if (fields & record_subproc_index) {
|
|
75
|
+
layout[offset] = {"subprocess_index", "<i4"};
|
|
76
|
+
offset += 1;
|
|
77
|
+
}
|
|
78
|
+
if (fields & record_indices) {
|
|
79
|
+
layout[offset + 0] = {"diagram_index", "<i4"};
|
|
80
|
+
layout[offset + 1] = {"color_index", "<i4"};
|
|
81
|
+
layout[offset + 2] = {"flavor_index", "<i4"};
|
|
82
|
+
layout[offset + 3] = {"helicity_index", "<i4"};
|
|
83
|
+
offset += 4;
|
|
84
|
+
}
|
|
85
|
+
return layout;
|
|
86
|
+
}();
|
|
87
|
+
|
|
88
|
+
UnalignedRef<double> weight() { return &data[0]; }
|
|
89
|
+
UnalignedRef<int> subprocess_index() { return &data[subproc_index_offset + 0]; }
|
|
90
|
+
UnalignedRef<int> diagram_index() { return &data[indices_offset + 0]; }
|
|
91
|
+
UnalignedRef<int> color_index() { return &data[indices_offset + 4]; }
|
|
92
|
+
UnalignedRef<int> flavor_index() { return &data[indices_offset + 8]; }
|
|
93
|
+
UnalignedRef<int> helicity_index() { return &data[indices_offset + 12]; }
|
|
94
|
+
|
|
95
|
+
char* data;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
using EventWeightRecord = EventRecord<record_weight>;
|
|
99
|
+
using EventIndicesRecord = EventRecord<record_indices>;
|
|
100
|
+
using EventFullRecord =
|
|
101
|
+
EventRecord<record_weight | record_subproc_index | record_indices>;
|
|
102
|
+
|
|
103
|
+
struct EmptyParticleRecord {
|
|
104
|
+
static constexpr std::size_t size = 0;
|
|
105
|
+
static constexpr std::array<FieldLayout, 0> layout = {};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
struct PackedLHEParticle {
|
|
109
|
+
static constexpr std::size_t size = 6 * sizeof(int) + 7 * sizeof(double);
|
|
110
|
+
static constexpr std::array<FieldLayout, 13> layout = {{
|
|
111
|
+
{"pdg_id", "<i4"},
|
|
112
|
+
{"status_code", "<i4"},
|
|
113
|
+
{"mother1", "<i4"},
|
|
114
|
+
{"mother2", "<i4"},
|
|
115
|
+
{"color", "<i4"},
|
|
116
|
+
{"anti_color", "<i4"},
|
|
117
|
+
{"px", "<f8"},
|
|
118
|
+
{"py", "<f8"},
|
|
119
|
+
{"pz", "<f8"},
|
|
120
|
+
{"energy", "<f8"},
|
|
121
|
+
{"mass", "<f8"},
|
|
122
|
+
{"lifetime", "<f8"},
|
|
123
|
+
{"spin", "<f8"},
|
|
124
|
+
}};
|
|
125
|
+
|
|
126
|
+
void from_lhe_particle(const LHEParticle& particle) {
|
|
127
|
+
pdg_id() = particle.pdg_id;
|
|
128
|
+
status_code() = particle.status_code;
|
|
129
|
+
mother1() = particle.mother1;
|
|
130
|
+
mother2() = particle.mother2;
|
|
131
|
+
color() = particle.color;
|
|
132
|
+
anti_color() = particle.anti_color;
|
|
133
|
+
px() = particle.px;
|
|
134
|
+
py() = particle.py;
|
|
135
|
+
pz() = particle.pz;
|
|
136
|
+
energy() = particle.energy;
|
|
137
|
+
mass() = particle.mass;
|
|
138
|
+
lifetime() = particle.lifetime;
|
|
139
|
+
spin() = particle.spin;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
UnalignedRef<int> pdg_id() { return &data[0]; }
|
|
143
|
+
UnalignedRef<int> status_code() { return &data[4]; }
|
|
144
|
+
UnalignedRef<int> mother1() { return &data[8]; }
|
|
145
|
+
UnalignedRef<int> mother2() { return &data[12]; }
|
|
146
|
+
UnalignedRef<int> color() { return &data[16]; }
|
|
147
|
+
UnalignedRef<int> anti_color() { return &data[20]; }
|
|
148
|
+
UnalignedRef<double> px() { return &data[24]; }
|
|
149
|
+
UnalignedRef<double> py() { return &data[32]; }
|
|
150
|
+
UnalignedRef<double> pz() { return &data[40]; }
|
|
151
|
+
UnalignedRef<double> energy() { return &data[48]; }
|
|
152
|
+
UnalignedRef<double> mass() { return &data[56]; }
|
|
153
|
+
UnalignedRef<double> lifetime() { return &data[64]; }
|
|
154
|
+
UnalignedRef<double> spin() { return &data[72]; }
|
|
155
|
+
|
|
156
|
+
char* data;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
struct PackedLHEEvent {
|
|
160
|
+
static constexpr std::size_t size = 1 * sizeof(int) + 4 * sizeof(double);
|
|
161
|
+
static constexpr std::array<FieldLayout, 5> layout = {{
|
|
162
|
+
{"process_id", "<i4"},
|
|
163
|
+
{"weight", "<f8"},
|
|
164
|
+
{"scale", "<f8"},
|
|
165
|
+
{"alpha_qed", "<f8"},
|
|
166
|
+
{"alpha_qcd", "<f8"},
|
|
167
|
+
}};
|
|
168
|
+
|
|
169
|
+
void from_lhe_event(const LHEEvent& event) {
|
|
170
|
+
process_id() = event.process_id;
|
|
171
|
+
weight() = event.weight;
|
|
172
|
+
scale() = event.scale;
|
|
173
|
+
alpha_qed() = event.alpha_qed;
|
|
174
|
+
alpha_qcd() = event.alpha_qcd;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
UnalignedRef<int> process_id() { return &data[0]; }
|
|
178
|
+
UnalignedRef<double> weight() { return &data[4]; }
|
|
179
|
+
UnalignedRef<double> scale() { return &data[12]; }
|
|
180
|
+
UnalignedRef<double> alpha_qed() { return &data[20]; }
|
|
181
|
+
UnalignedRef<double> alpha_qcd() { return &data[28]; }
|
|
182
|
+
|
|
183
|
+
char* data;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
struct DataLayout {
|
|
187
|
+
std::span<const FieldLayout> event_fields;
|
|
188
|
+
std::span<const FieldLayout> particle_fields;
|
|
189
|
+
std::size_t event_size;
|
|
190
|
+
std::size_t particle_size;
|
|
191
|
+
|
|
192
|
+
template <typename E, typename P>
|
|
193
|
+
static DataLayout of() {
|
|
194
|
+
return {
|
|
195
|
+
.event_fields = {E::layout.begin(), E::layout.end()},
|
|
196
|
+
.particle_fields = {P::layout.begin(), P::layout.end()},
|
|
197
|
+
.event_size = E::size,
|
|
198
|
+
.particle_size = P::size,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
class EventBuffer {
|
|
204
|
+
public:
|
|
205
|
+
EventBuffer(
|
|
206
|
+
std::size_t event_count, std::size_t particle_count, DataLayout layout
|
|
207
|
+
) :
|
|
208
|
+
_event_count(event_count),
|
|
209
|
+
_particle_count(particle_count),
|
|
210
|
+
_layout(layout),
|
|
211
|
+
_data(
|
|
212
|
+
event_count * (layout.event_size + particle_count * layout.particle_size)
|
|
213
|
+
) {}
|
|
214
|
+
char* data() { return _data.data(); }
|
|
215
|
+
const char* data() const { return _data.data(); }
|
|
216
|
+
std::size_t size() const { return _data.size(); }
|
|
217
|
+
std::size_t event_count() const { return _event_count; }
|
|
218
|
+
std::size_t particle_count() const { return _particle_count; }
|
|
219
|
+
const DataLayout& layout() const { return _layout; }
|
|
220
|
+
|
|
221
|
+
std::size_t event_size() const {
|
|
222
|
+
return _layout.event_size + _particle_count * _layout.particle_size;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
std::size_t event_offset(std::size_t event_index) const {
|
|
226
|
+
return event_index * event_size();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
std::size_t
|
|
230
|
+
particle_offset(std::size_t event_index, std::size_t particle_index) const {
|
|
231
|
+
return event_offset(event_index) + _layout.event_size +
|
|
232
|
+
particle_index * _layout.particle_size;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
template <typename T>
|
|
236
|
+
T particle(std::size_t event_index, std::size_t particle_index) {
|
|
237
|
+
return {&_data.data()[particle_offset(event_index, particle_index)]};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
template <typename T>
|
|
241
|
+
T event(std::size_t event_index) {
|
|
242
|
+
return {&_data.data()[event_offset(event_index)]};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
void resize(std::size_t event_count) {
|
|
246
|
+
_data.resize(event_count * event_size());
|
|
247
|
+
_event_count = event_count;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
void copy_and_pad(EventBuffer& buffer) {
|
|
251
|
+
if (buffer.particle_count() > particle_count()) {
|
|
252
|
+
throw std::runtime_error("Given buffer contains too many particles");
|
|
253
|
+
}
|
|
254
|
+
resize(buffer.event_count());
|
|
255
|
+
for (std::size_t i = 0; i < event_count(); ++i) {
|
|
256
|
+
std::memcpy(
|
|
257
|
+
&_data[event_offset(i)],
|
|
258
|
+
&buffer._data[buffer.event_offset(i)],
|
|
259
|
+
buffer.event_size()
|
|
260
|
+
);
|
|
261
|
+
std::memset(
|
|
262
|
+
&_data[event_offset(i) + buffer.event_size()],
|
|
263
|
+
0,
|
|
264
|
+
event_size() - buffer.event_size()
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private:
|
|
270
|
+
std::size_t _event_count;
|
|
271
|
+
std::size_t _particle_count;
|
|
272
|
+
DataLayout _layout;
|
|
273
|
+
std::vector<char> _data;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
class EventFile {
|
|
277
|
+
public:
|
|
278
|
+
enum Mode { create, append, load };
|
|
279
|
+
|
|
280
|
+
EventFile(
|
|
281
|
+
const std::string& file_name,
|
|
282
|
+
DataLayout layout,
|
|
283
|
+
std::size_t particle_count = 0,
|
|
284
|
+
Mode mode = create,
|
|
285
|
+
bool delete_on_close = false
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
EventFile(EventFile&& other) noexcept = default;
|
|
289
|
+
EventFile& operator=(EventFile&& other) noexcept = default;
|
|
290
|
+
void seek(std::size_t index);
|
|
291
|
+
void clear();
|
|
292
|
+
std::size_t particle_count() const { return _particle_count; }
|
|
293
|
+
std::size_t event_count() const { return _event_count; }
|
|
294
|
+
~EventFile();
|
|
295
|
+
|
|
296
|
+
void write(EventBuffer& buffer) {
|
|
297
|
+
if (_mode == EventFile::load) {
|
|
298
|
+
throw std::runtime_error("Event file opened in read mode.");
|
|
299
|
+
}
|
|
300
|
+
if (buffer.particle_count() != _particle_count) {
|
|
301
|
+
throw std::invalid_argument("Wrong number of particles");
|
|
302
|
+
}
|
|
303
|
+
_file_stream.write(buffer.data(), buffer.size());
|
|
304
|
+
_current_event += buffer.event_count();
|
|
305
|
+
if (_current_event > _event_count) {
|
|
306
|
+
_event_count = _current_event;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
bool read(EventBuffer& buffer, std::size_t count) {
|
|
311
|
+
if (_current_event == _event_count) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
count = std::min(count, _event_count - _current_event);
|
|
315
|
+
buffer.resize(count);
|
|
316
|
+
if (buffer.particle_count() == _particle_count) {
|
|
317
|
+
_file_stream.read(buffer.data(), buffer.size());
|
|
318
|
+
} else if (buffer.particle_count() > _particle_count) {
|
|
319
|
+
EventBuffer tmp_buffer(count, _particle_count, buffer.layout());
|
|
320
|
+
_file_stream.read(tmp_buffer.data(), tmp_buffer.size());
|
|
321
|
+
buffer.copy_and_pad(tmp_buffer);
|
|
322
|
+
} else {
|
|
323
|
+
throw std::invalid_argument("Wrong number of particles");
|
|
324
|
+
}
|
|
325
|
+
_current_event += count;
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private:
|
|
330
|
+
std::string _file_name;
|
|
331
|
+
std::size_t _event_count;
|
|
332
|
+
std::size_t _current_event;
|
|
333
|
+
std::size_t _capacity;
|
|
334
|
+
std::size_t _particle_count;
|
|
335
|
+
std::size_t _shape_pos;
|
|
336
|
+
std::fstream _file_stream;
|
|
337
|
+
std::size_t _header_size;
|
|
338
|
+
std::size_t _event_size;
|
|
339
|
+
Mode _mode;
|
|
340
|
+
bool _delete_on_close;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
} // namespace madspace
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <fstream>
|
|
4
|
+
#include <random>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <unordered_map>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
#include "madspace/phasespace/topology.h"
|
|
10
|
+
#include "madspace/runtime/thread_pool.h"
|
|
11
|
+
#include "madspace/util.h"
|
|
12
|
+
|
|
13
|
+
namespace madspace {
|
|
14
|
+
|
|
15
|
+
struct LHEHeader {
|
|
16
|
+
std::string name;
|
|
17
|
+
std::string content;
|
|
18
|
+
bool escape_content;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
struct LHEProcess {
|
|
22
|
+
double cross_section;
|
|
23
|
+
double cross_section_error;
|
|
24
|
+
double max_weight;
|
|
25
|
+
int process_id;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
struct LHEMeta {
|
|
29
|
+
int beam1_pdg_id, beam2_pdg_id;
|
|
30
|
+
double beam1_energy, beam2_energy;
|
|
31
|
+
int beam1_pdf_authors, beam2_pdf_authors;
|
|
32
|
+
int beam1_pdf_id, beam2_pdf_id;
|
|
33
|
+
int weight_mode;
|
|
34
|
+
std::vector<LHEProcess> processes;
|
|
35
|
+
std::vector<LHEHeader> headers;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
struct LHEParticle {
|
|
39
|
+
// particle-level information as defined in arXiv:0109068
|
|
40
|
+
inline static const int status_incoming = -1;
|
|
41
|
+
inline static const int status_outgoing = 1;
|
|
42
|
+
inline static const int status_intermediate_resonance = 2;
|
|
43
|
+
|
|
44
|
+
int pdg_id;
|
|
45
|
+
int status_code;
|
|
46
|
+
int mother1, mother2;
|
|
47
|
+
int color, anti_color;
|
|
48
|
+
double px, py, pz, energy, mass;
|
|
49
|
+
double lifetime;
|
|
50
|
+
double spin;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
struct LHEEvent {
|
|
54
|
+
// event-level information as defined in arXiv:0109068
|
|
55
|
+
int process_id;
|
|
56
|
+
double weight;
|
|
57
|
+
double scale;
|
|
58
|
+
double alpha_qed;
|
|
59
|
+
double alpha_qcd;
|
|
60
|
+
std::vector<LHEParticle> particles;
|
|
61
|
+
|
|
62
|
+
void format_to(std::string& buffer) const;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
class LHECompleter {
|
|
66
|
+
public:
|
|
67
|
+
struct SubprocArgs {
|
|
68
|
+
int process_id;
|
|
69
|
+
std::vector<Topology> topologies;
|
|
70
|
+
nested_vector3<std::size_t> permutations;
|
|
71
|
+
nested_vector2<std::size_t> diagram_indices;
|
|
72
|
+
nested_vector3<std::size_t> diagram_color_indices;
|
|
73
|
+
nested_vector3<std::tuple<int, int>> color_flows;
|
|
74
|
+
std::unordered_map<int, int> pdg_color_types;
|
|
75
|
+
nested_vector2<double> helicities;
|
|
76
|
+
nested_vector3<int> pdg_ids;
|
|
77
|
+
std::vector<std::size_t> matrix_flavor_indices;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
LHECompleter(const std::vector<SubprocArgs>& subproc_args, double bw_cutoff);
|
|
81
|
+
void complete_event_data(
|
|
82
|
+
LHEEvent& event,
|
|
83
|
+
int subprocess_index,
|
|
84
|
+
int diagram_index,
|
|
85
|
+
int color_index,
|
|
86
|
+
int flavor_index,
|
|
87
|
+
int helicity_index
|
|
88
|
+
);
|
|
89
|
+
std::size_t max_particle_count() const { return _max_particle_count; }
|
|
90
|
+
|
|
91
|
+
private:
|
|
92
|
+
struct SubprocData {
|
|
93
|
+
int process_id;
|
|
94
|
+
std::size_t color_offset, pdg_id_offset, helicity_offset, mass_offset;
|
|
95
|
+
std::size_t particle_count, color_count, flavor_count, matrix_flavor_count;
|
|
96
|
+
std::size_t diagram_count, helicity_count;
|
|
97
|
+
};
|
|
98
|
+
struct PropagatorData {
|
|
99
|
+
int pdg_id;
|
|
100
|
+
int momentum_mask;
|
|
101
|
+
int child_prop_mask;
|
|
102
|
+
double mass, width;
|
|
103
|
+
};
|
|
104
|
+
std::vector<SubprocData> _subproc_data;
|
|
105
|
+
std::vector<int> _process_indices;
|
|
106
|
+
std::vector<double> _masses;
|
|
107
|
+
std::vector<std::tuple<int, int>> _colors;
|
|
108
|
+
std::vector<double> _helicities;
|
|
109
|
+
std::vector<std::array<std::size_t, 3>> _pdg_id_index_and_count;
|
|
110
|
+
std::vector<int> _pdg_ids;
|
|
111
|
+
std::unordered_map<std::size_t, std::array<std::size_t, 3>>
|
|
112
|
+
_propagator_index_and_count;
|
|
113
|
+
std::vector<PropagatorData> _propagators;
|
|
114
|
+
std::vector<std::tuple<int, int>> _propagator_colors;
|
|
115
|
+
double _bw_cutoff;
|
|
116
|
+
std::size_t _max_particle_count;
|
|
117
|
+
ThreadResource<std::mt19937> _rand_gens;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
class LHEFileWriter {
|
|
121
|
+
public:
|
|
122
|
+
LHEFileWriter(const std::string& file_name, const LHEMeta& meta);
|
|
123
|
+
void write(const LHEEvent& event);
|
|
124
|
+
void write_string(const std::string& str);
|
|
125
|
+
~LHEFileWriter();
|
|
126
|
+
|
|
127
|
+
private:
|
|
128
|
+
std::ofstream _file_stream;
|
|
129
|
+
std::string _buffer;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
} // namespace madspace
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <functional>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "madspace/util.h"
|
|
7
|
+
|
|
8
|
+
namespace madspace {
|
|
9
|
+
|
|
10
|
+
class Logger {
|
|
11
|
+
public:
|
|
12
|
+
enum LogLevel { level_debug, level_info, level_warning, level_error };
|
|
13
|
+
using LogHandlerFunc =
|
|
14
|
+
std::function<void(LogLevel level, const std::string& message)>;
|
|
15
|
+
|
|
16
|
+
static void log(LogLevel level, const std::string& message) {
|
|
17
|
+
if (_log_handler) {
|
|
18
|
+
_log_handler.value()(level, message);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
switch (level) {
|
|
22
|
+
case level_debug:
|
|
23
|
+
println("[DEBUG] {}", message);
|
|
24
|
+
break;
|
|
25
|
+
case level_info:
|
|
26
|
+
println("[INFO] {}", message);
|
|
27
|
+
break;
|
|
28
|
+
case level_warning:
|
|
29
|
+
println("[WARNIGN] {}", message);
|
|
30
|
+
break;
|
|
31
|
+
case level_error:
|
|
32
|
+
println("[ERROR] {}", message);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
static void debug(const std::string& message) { log(level_debug, message); }
|
|
37
|
+
static void info(const std::string& message) { log(level_info, message); }
|
|
38
|
+
static void warning(const std::string& message) { log(level_warning, message); }
|
|
39
|
+
static void error(const std::string& message) { log(level_error, message); }
|
|
40
|
+
static void set_log_handler(LogHandlerFunc func) { _log_handler = func; }
|
|
41
|
+
|
|
42
|
+
private:
|
|
43
|
+
static inline std::optional<LogHandlerFunc> _log_handler = std::nullopt;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
} // namespace madspace
|
|
@@ -0,0 +1,39 @@
|
|
|
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 Runtime {
|
|
10
|
+
public:
|
|
11
|
+
virtual ~Runtime() = default;
|
|
12
|
+
virtual TensorVec run(const TensorVec& inputs) const = 0;
|
|
13
|
+
virtual std::tuple<TensorVec, TensorVec, std::vector<bool>> run_with_grad(
|
|
14
|
+
const TensorVec& inputs, const std::vector<bool>& input_requires_grad
|
|
15
|
+
) const = 0;
|
|
16
|
+
virtual std::
|
|
17
|
+
tuple<TensorVec, std::vector<std::tuple<std::string, madspace::Tensor>>>
|
|
18
|
+
run_backward(
|
|
19
|
+
const TensorVec& output_grads,
|
|
20
|
+
const TensorVec& stored_locals,
|
|
21
|
+
const std::vector<bool>& eval_grad
|
|
22
|
+
) const = 0;
|
|
23
|
+
friend std::unique_ptr<Runtime>
|
|
24
|
+
build_runtime(const Function& function, ContextPtr context, bool concurrent);
|
|
25
|
+
|
|
26
|
+
private:
|
|
27
|
+
std::shared_ptr<void> shared_lib;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
using RuntimePtr = std::unique_ptr<Runtime>;
|
|
31
|
+
RuntimePtr
|
|
32
|
+
build_runtime(const Function& function, ContextPtr context, bool concurrent = true);
|
|
33
|
+
DevicePtr cpu_device();
|
|
34
|
+
DevicePtr cuda_device();
|
|
35
|
+
DevicePtr hip_device();
|
|
36
|
+
void set_lib_path(const std::string& lib_path);
|
|
37
|
+
void set_simd_vector_size(int vector_size);
|
|
38
|
+
|
|
39
|
+
} // namespace madspace
|