madspace 0.3.1__cp311-cp311-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.
Files changed (75) hide show
  1. madspace/__init__.py +1 -0
  2. madspace/_madspace_py.cpython-311-x86_64-linux-gnu.so +0 -0
  3. madspace/_madspace_py.pyi +2189 -0
  4. madspace/_madspace_py_loader.py +111 -0
  5. madspace/include/madspace/constants.h +17 -0
  6. madspace/include/madspace/madcode/function.h +102 -0
  7. madspace/include/madspace/madcode/function_builder_mixin.h +591 -0
  8. madspace/include/madspace/madcode/instruction.h +208 -0
  9. madspace/include/madspace/madcode/opcode_mixin.h +134 -0
  10. madspace/include/madspace/madcode/optimizer.h +31 -0
  11. madspace/include/madspace/madcode/type.h +203 -0
  12. madspace/include/madspace/madcode.h +6 -0
  13. madspace/include/madspace/phasespace/base.h +74 -0
  14. madspace/include/madspace/phasespace/channel_weight_network.h +46 -0
  15. madspace/include/madspace/phasespace/channel_weights.h +51 -0
  16. madspace/include/madspace/phasespace/chili.h +32 -0
  17. madspace/include/madspace/phasespace/cross_section.h +47 -0
  18. madspace/include/madspace/phasespace/cuts.h +34 -0
  19. madspace/include/madspace/phasespace/discrete_flow.h +44 -0
  20. madspace/include/madspace/phasespace/discrete_sampler.h +53 -0
  21. madspace/include/madspace/phasespace/flow.h +53 -0
  22. madspace/include/madspace/phasespace/histograms.h +26 -0
  23. madspace/include/madspace/phasespace/integrand.h +204 -0
  24. madspace/include/madspace/phasespace/invariants.h +26 -0
  25. madspace/include/madspace/phasespace/luminosity.h +41 -0
  26. madspace/include/madspace/phasespace/matrix_element.h +70 -0
  27. madspace/include/madspace/phasespace/mlp.h +37 -0
  28. madspace/include/madspace/phasespace/multichannel.h +49 -0
  29. madspace/include/madspace/phasespace/observable.h +85 -0
  30. madspace/include/madspace/phasespace/pdf.h +78 -0
  31. madspace/include/madspace/phasespace/phasespace.h +67 -0
  32. madspace/include/madspace/phasespace/rambo.h +26 -0
  33. madspace/include/madspace/phasespace/scale.h +52 -0
  34. madspace/include/madspace/phasespace/t_propagator_mapping.h +34 -0
  35. madspace/include/madspace/phasespace/three_particle.h +68 -0
  36. madspace/include/madspace/phasespace/topology.h +116 -0
  37. madspace/include/madspace/phasespace/two_particle.h +63 -0
  38. madspace/include/madspace/phasespace/vegas.h +53 -0
  39. madspace/include/madspace/phasespace.h +27 -0
  40. madspace/include/madspace/runtime/context.h +147 -0
  41. madspace/include/madspace/runtime/discrete_optimizer.h +24 -0
  42. madspace/include/madspace/runtime/event_generator.h +257 -0
  43. madspace/include/madspace/runtime/format.h +68 -0
  44. madspace/include/madspace/runtime/io.h +343 -0
  45. madspace/include/madspace/runtime/lhe_output.h +132 -0
  46. madspace/include/madspace/runtime/logger.h +46 -0
  47. madspace/include/madspace/runtime/runtime_base.h +39 -0
  48. madspace/include/madspace/runtime/tensor.h +603 -0
  49. madspace/include/madspace/runtime/thread_pool.h +101 -0
  50. madspace/include/madspace/runtime/vegas_optimizer.h +26 -0
  51. madspace/include/madspace/runtime.h +12 -0
  52. madspace/include/madspace/umami.h +202 -0
  53. madspace/include/madspace/util.h +142 -0
  54. madspace/lib/libmadspace.so +0 -0
  55. madspace/lib/libmadspace_cpu.so +0 -0
  56. madspace/lib/libmadspace_cpu_avx2.so +0 -0
  57. madspace/lib/libmadspace_cpu_avx512.so +0 -0
  58. madspace/lib/libmadspace_cuda.so +0 -0
  59. madspace/lib/libmadspace_hip.so +0 -0
  60. madspace/madnis/__init__.py +44 -0
  61. madspace/madnis/buffer.py +167 -0
  62. madspace/madnis/channel_grouping.py +85 -0
  63. madspace/madnis/distribution.py +103 -0
  64. madspace/madnis/integrand.py +175 -0
  65. madspace/madnis/integrator.py +973 -0
  66. madspace/madnis/interface.py +191 -0
  67. madspace/madnis/losses.py +186 -0
  68. madspace/torch.py +82 -0
  69. madspace-0.3.1.dist-info/METADATA +71 -0
  70. madspace-0.3.1.dist-info/RECORD +75 -0
  71. madspace-0.3.1.dist-info/WHEEL +6 -0
  72. madspace-0.3.1.dist-info/licenses/LICENSE +21 -0
  73. madspace.libs/libgfortran-83c28eba.so.5.0.0 +0 -0
  74. madspace.libs/libopenblas-r0-11edc3fa.3.15.so +0 -0
  75. madspace.libs/libquadmath-2284e583.so.0.0.0 +0 -0
@@ -0,0 +1,51 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/base.h"
4
+ #include "madspace/phasespace/topology.h"
5
+ #include "madspace/util.h"
6
+
7
+ namespace madspace {
8
+
9
+ class PropagatorChannelWeights : public FunctionGenerator {
10
+ public:
11
+ PropagatorChannelWeights(
12
+ const std::vector<Topology>& topologies,
13
+ const nested_vector3<std::size_t>& permutations,
14
+ const nested_vector2<std::size_t>& channel_indices
15
+ );
16
+
17
+ private:
18
+ ValueVec
19
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
20
+
21
+ nested_vector2<double> _momentum_factors;
22
+ nested_vector2<me_int_t> _invariant_indices;
23
+ nested_vector2<double> _masses;
24
+ nested_vector2<double> _widths;
25
+ };
26
+
27
+ class SubchannelWeights : public FunctionGenerator {
28
+ public:
29
+ SubchannelWeights(
30
+ const nested_vector2<Topology>& topologies,
31
+ const nested_vector3<std::size_t>& permutations,
32
+ const nested_vector2<std::size_t>& channel_indices
33
+ );
34
+
35
+ std::size_t channel_count() const { return _channel_indices.size(); }
36
+
37
+ private:
38
+ ValueVec
39
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
40
+
41
+ nested_vector2<double> _momentum_factors;
42
+ nested_vector2<double> _masses;
43
+ nested_vector2<double> _widths;
44
+ nested_vector2<me_int_t> _invariant_indices;
45
+ nested_vector2<me_int_t> _on_shell;
46
+ std::vector<me_int_t> _group_sizes;
47
+ std::vector<me_int_t> _channel_indices;
48
+ std::vector<me_int_t> _subchannel_indices;
49
+ };
50
+
51
+ } // namespace madspace
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/base.h"
4
+
5
+ #include <vector>
6
+
7
+ namespace madspace {
8
+
9
+ class ChiliMapping : public Mapping {
10
+ public:
11
+ ChiliMapping(
12
+ std::size_t n_particles,
13
+ const std::vector<double>& y_max,
14
+ const std::vector<double>& pt_min
15
+ );
16
+
17
+ std::size_t random_dim() const { return 3 * _n_particles - 2; }
18
+
19
+ private:
20
+ Result build_forward_impl(
21
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
22
+ ) const override;
23
+ Result build_inverse_impl(
24
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
25
+ ) const override;
26
+
27
+ std::size_t _n_particles;
28
+ std::vector<double> _y_max;
29
+ std::vector<double> _pt_min;
30
+ };
31
+
32
+ } // namespace madspace
@@ -0,0 +1,47 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/matrix_element.h"
4
+ #include "madspace/phasespace/pdf.h"
5
+ #include "madspace/phasespace/scale.h"
6
+
7
+ namespace madspace {
8
+
9
+ class DifferentialCrossSection : public FunctionGenerator {
10
+ public:
11
+ DifferentialCrossSection(
12
+ const MatrixElement& matrix_element,
13
+ double cm_energy,
14
+ const RunningCoupling& running_coupling,
15
+ const EnergyScale& energy_scale,
16
+ const nested_vector2<me_int_t>& pid_options = {},
17
+ bool has_pdf1 = false,
18
+ bool has_pdf2 = false,
19
+ const std::optional<PdfGrid>& pdf_grid1 = std::nullopt,
20
+ const std::optional<PdfGrid>& pdf_grid2 = std::nullopt,
21
+ bool has_mirror = false,
22
+ bool input_momentum_fraction = true
23
+ );
24
+
25
+ const nested_vector2<me_int_t>& pid_options() const { return _pid_options; }
26
+ bool has_mirror() const { return _has_mirror; }
27
+ bool has_pdf(std::size_t pdf_index) const {
28
+ return _pdfs.at(pdf_index) != std::nullopt;
29
+ }
30
+ const MatrixElement& matrix_element() const { return _matrix_element; }
31
+
32
+ private:
33
+ ValueVec
34
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
35
+
36
+ nested_vector2<me_int_t> _pid_options;
37
+ MatrixElement _matrix_element;
38
+ std::array<std::optional<PartonDensity>, 2> _pdfs;
39
+ std::array<std::vector<me_int_t>, 2> _pdf_indices;
40
+ RunningCoupling _running_coupling;
41
+ double _e_cm;
42
+ EnergyScale _energy_scale;
43
+ bool _has_mirror;
44
+ bool _input_momentum_fraction;
45
+ };
46
+
47
+ } // namespace madspace
@@ -0,0 +1,34 @@
1
+ #pragma once
2
+
3
+ #include "madspace/madcode.h"
4
+ #include "madspace/phasespace/base.h"
5
+ #include "madspace/phasespace/observable.h"
6
+
7
+ #include <vector>
8
+
9
+ namespace madspace {
10
+
11
+ class Cuts : public FunctionGenerator {
12
+ public:
13
+ enum CutMode { any, all };
14
+ struct CutItem {
15
+ Observable observable;
16
+ double min = -std::numeric_limits<double>::infinity();
17
+ double max = std::numeric_limits<double>::infinity();
18
+ CutMode mode = CutMode::all;
19
+ };
20
+
21
+ Cuts(const std::vector<CutItem>& cut_data);
22
+ Cuts(std::size_t particle_count);
23
+ double sqrt_s_min() const;
24
+ std::vector<double> eta_max() const;
25
+ std::vector<double> pt_min() const;
26
+
27
+ private:
28
+ ValueVec
29
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
30
+
31
+ std::vector<CutItem> _cut_data;
32
+ };
33
+
34
+ } // namespace madspace
@@ -0,0 +1,44 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/base.h"
4
+ #include "madspace/phasespace/mlp.h"
5
+
6
+ namespace madspace {
7
+
8
+ class DiscreteFlow : public Mapping {
9
+ public:
10
+ DiscreteFlow(
11
+ const std::vector<std::size_t>& option_counts,
12
+ const std::string& prefix = "",
13
+ const std::vector<std::size_t>& dims_with_prior = {},
14
+ std::size_t condition_dim = 0,
15
+ std::size_t subnet_hidden_dim = 32,
16
+ std::size_t subnet_layers = 3,
17
+ MLP::Activation subnet_activation = MLP::leaky_relu
18
+ );
19
+ const std::vector<std::size_t>& option_counts() const { return _option_counts; }
20
+ std::size_t condition_dim() const { return _condition_dim; }
21
+ void initialize_globals(ContextPtr context) const;
22
+
23
+ private:
24
+ Result build_forward_impl(
25
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
26
+ ) const override;
27
+ Result build_inverse_impl(
28
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
29
+ ) const override;
30
+ Result build_transform(
31
+ FunctionBuilder& fb,
32
+ const ValueVec& inputs,
33
+ const ValueVec& conditions,
34
+ bool inverse
35
+ ) const;
36
+
37
+ std::vector<std::size_t> _option_counts;
38
+ std::size_t _condition_dim;
39
+ std::optional<std::string> _first_prob_name;
40
+ std::vector<MLP> _subnets;
41
+ std::vector<bool> _dim_has_prior;
42
+ };
43
+
44
+ } // namespace madspace
@@ -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 DiscreteHistogram : public FunctionGenerator {
9
+ public:
10
+ DiscreteHistogram(const std::vector<std::size_t>& option_counts);
11
+
12
+ private:
13
+ ValueVec
14
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
15
+
16
+ std::vector<std::size_t> _option_counts;
17
+ };
18
+
19
+ class DiscreteSampler : public Mapping {
20
+ public:
21
+ DiscreteSampler(
22
+ const std::vector<std::size_t>& option_counts,
23
+ const std::string& prefix = "",
24
+ const std::vector<std::size_t>& dims_with_prior = {}
25
+ );
26
+ const std::vector<std::size_t>& option_counts() const { return _option_counts; }
27
+ const std::vector<std::string>& prob_names() const { return _prob_names; }
28
+ void initialize_globals(ContextPtr context) const;
29
+
30
+ private:
31
+ Result build_forward_impl(
32
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
33
+ ) const override;
34
+ Result build_inverse_impl(
35
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
36
+ ) const override;
37
+ Result build_transform(
38
+ FunctionBuilder& fb,
39
+ const ValueVec& inputs,
40
+ const ValueVec& conditions,
41
+ bool inverse
42
+ ) const;
43
+
44
+ std::vector<std::size_t> _option_counts;
45
+ std::vector<bool> _dim_has_prior;
46
+ std::vector<std::string> _prob_names;
47
+ };
48
+
49
+ void initialize_uniform_probs(
50
+ ContextPtr context, const std::string& name, std::size_t option_count
51
+ );
52
+
53
+ } // namespace madspace
@@ -0,0 +1,53 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/base.h"
4
+ #include "madspace/phasespace/mlp.h"
5
+
6
+ namespace madspace {
7
+
8
+ class Flow : public Mapping {
9
+ public:
10
+ Flow(
11
+ std::size_t input_dim,
12
+ std::size_t condition_dim = 0,
13
+ const std::string& prefix = "",
14
+ std::size_t bin_count = 10,
15
+ std::size_t subnet_hidden_dim = 32,
16
+ std::size_t subnet_layers = 3,
17
+ MLP::Activation subnet_activation = MLP::leaky_relu,
18
+ bool invert_spline = true
19
+ );
20
+ std::size_t input_dim() const { return _input_dim; }
21
+ std::size_t condition_dim() const { return _condition_dim; }
22
+ void initialize_globals(ContextPtr context) const;
23
+ void initialize_from_vegas(ContextPtr context, const std::string& grid_name) const;
24
+
25
+ private:
26
+ Result build_forward_impl(
27
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
28
+ ) const override;
29
+ Result build_inverse_impl(
30
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
31
+ ) const override;
32
+ Result build_transform(
33
+ FunctionBuilder& fb,
34
+ const ValueVec& inputs,
35
+ const ValueVec& conditions,
36
+ bool inverse
37
+ ) const;
38
+
39
+ struct CouplingBlock {
40
+ MLP subnet1;
41
+ MLP subnet2;
42
+ std::vector<me_int_t> indices1;
43
+ std::vector<me_int_t> indices2;
44
+ };
45
+
46
+ std::vector<CouplingBlock> _coupling_blocks;
47
+ std::size_t _input_dim;
48
+ std::size_t _condition_dim;
49
+ std::size_t _bin_count;
50
+ bool _invert_spline;
51
+ };
52
+
53
+ } // namespace madspace
@@ -0,0 +1,26 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/base.h"
4
+ #include "madspace/phasespace/observable.h"
5
+
6
+ namespace madspace {
7
+
8
+ class ObservableHistograms : public FunctionGenerator {
9
+ public:
10
+ struct HistItem {
11
+ Observable observable;
12
+ double min;
13
+ double max;
14
+ std::size_t bin_count;
15
+ };
16
+ ObservableHistograms(const std::vector<HistItem>& observables);
17
+ const std::vector<HistItem>& observables() const { return _observables; }
18
+
19
+ private:
20
+ ValueVec
21
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
22
+
23
+ std::vector<HistItem> _observables;
24
+ };
25
+
26
+ } // namespace madspace
@@ -0,0 +1,204 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/channel_weight_network.h"
4
+ #include "madspace/phasespace/channel_weights.h"
5
+ #include "madspace/phasespace/cross_section.h"
6
+ #include "madspace/phasespace/discrete_flow.h"
7
+ #include "madspace/phasespace/discrete_sampler.h"
8
+ #include "madspace/phasespace/flow.h"
9
+ #include "madspace/phasespace/matrix_element.h"
10
+ #include "madspace/phasespace/pdf.h"
11
+ #include "madspace/phasespace/phasespace.h"
12
+ #include "madspace/phasespace/vegas.h"
13
+ #include "madspace/util.h"
14
+
15
+ namespace madspace {
16
+
17
+ class Unweighter : public FunctionGenerator {
18
+ public:
19
+ Unweighter(const TypeVec& types);
20
+
21
+ private:
22
+ ValueVec
23
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
24
+ };
25
+
26
+ class Integrand : public FunctionGenerator {
27
+ public:
28
+ using AdaptiveMapping = std::variant<std::monostate, VegasMapping, Flow>;
29
+ using AdaptiveDiscrete =
30
+ std::variant<std::monostate, DiscreteSampler, DiscreteFlow>;
31
+ inline static const int sample = 1;
32
+ inline static const int unweight = 2;
33
+ inline static const int return_momenta = 4;
34
+ inline static const int return_x1_x2 = 8;
35
+ inline static const int return_indices = 16;
36
+ inline static const int return_random = 32;
37
+ inline static const int return_latent = 64;
38
+ inline static const int return_channel = 128;
39
+ inline static const int return_chan_weights = 256;
40
+ inline static const int return_cwnet_input = 512;
41
+ inline static const int return_discrete = 1024;
42
+ inline static const int return_discrete_latent = 2048;
43
+
44
+ inline static const std::vector<MatrixElement::MatrixElementInput>
45
+ matrix_element_inputs = {
46
+ MatrixElement::momenta_in,
47
+ MatrixElement::alpha_s_in,
48
+ MatrixElement::flavor_in,
49
+ MatrixElement::random_color_in,
50
+ MatrixElement::random_helicity_in,
51
+ MatrixElement::random_diagram_in,
52
+ };
53
+ inline static const std::vector<MatrixElement::MatrixElementOutput>
54
+ matrix_element_outputs = {
55
+ MatrixElement::matrix_element_out,
56
+ MatrixElement::diagram_amp2_out,
57
+ MatrixElement::color_index_out,
58
+ MatrixElement::helicity_index_out,
59
+ MatrixElement::diagram_index_out,
60
+ };
61
+
62
+ Integrand(
63
+ const PhaseSpaceMapping& mapping,
64
+ const DifferentialCrossSection& diff_xs,
65
+ const AdaptiveMapping& adaptive_map = std::monostate{},
66
+ const AdaptiveDiscrete& discrete_before = std::monostate{},
67
+ const AdaptiveDiscrete& discrete_after = std::monostate{},
68
+ const std::optional<PdfGrid>& pdf_grid = std::nullopt,
69
+ const std::optional<EnergyScale>& energy_scale = std::nullopt,
70
+ const std::optional<PropagatorChannelWeights>& prop_chan_weights = std::nullopt,
71
+ const std::optional<SubchannelWeights>& subchan_weights = std::nullopt,
72
+ const std::optional<ChannelWeightNetwork>& chan_weight_net = std::nullopt,
73
+ const std::vector<me_int_t>& chan_weight_remap = {},
74
+ std::size_t remapped_chan_count = 0,
75
+ int flags = 0,
76
+ const std::vector<std::size_t>& channel_indices = {},
77
+ const std::vector<std::size_t>& active_flavors = {}
78
+ );
79
+ std::size_t particle_count() const { return _mapping.particle_count(); }
80
+ int flags() const { return _flags; }
81
+ std::optional<std::string> vegas_grid_name() const {
82
+ if (auto vegas = std::get_if<VegasMapping>(&_adaptive_map)) {
83
+ return vegas->grid_name();
84
+ } else {
85
+ return std::nullopt;
86
+ }
87
+ }
88
+ std::size_t vegas_dimension() const {
89
+ if (auto vegas = std::get_if<VegasMapping>(&_adaptive_map)) {
90
+ return vegas->dimension();
91
+ } else {
92
+ return 0;
93
+ }
94
+ }
95
+ std::size_t vegas_bin_count() const {
96
+ if (auto vegas = std::get_if<VegasMapping>(&_adaptive_map)) {
97
+ return vegas->bin_count();
98
+ } else {
99
+ return 0;
100
+ }
101
+ }
102
+ const PhaseSpaceMapping& mapping() const { return _mapping; }
103
+ const DifferentialCrossSection& diff_xs() const { return _diff_xs; }
104
+ const AdaptiveMapping& adaptive_map() const { return _adaptive_map; }
105
+ const AdaptiveDiscrete& discrete_before() const { return _discrete_before; }
106
+ const AdaptiveDiscrete& discrete_after() const { return _discrete_after; }
107
+ const std::optional<EnergyScale>& energy_scale() const { return _energy_scale; }
108
+ const std::optional<PropagatorChannelWeights>& prop_chan_weights() const {
109
+ return _prop_chan_weights;
110
+ }
111
+ const std::optional<ChannelWeightNetwork>& chan_weight_net() const {
112
+ return _chan_weight_net;
113
+ }
114
+ const std::size_t random_dim() const { return _random_dim; }
115
+ std::tuple<std::vector<std::size_t>, std::vector<bool>> latent_dims() const;
116
+
117
+ private:
118
+ struct ChannelArgs {
119
+ Value r, batch_size;
120
+ bool has_permutations, has_multi_flavor, has_mirror, has_pdf_prior;
121
+ Value max_weight;
122
+ };
123
+ struct ChannelResult {
124
+ std::array<Value, 21> values;
125
+
126
+ Value& r() { return values[0]; }
127
+ Value& latent() { return values[1]; }
128
+ Value& momenta() { return values[2]; }
129
+ Value& momenta_mirror() { return values[3]; }
130
+ Value& momenta_acc() { return values[4]; }
131
+ Value& x(std::size_t pdf_index) { return values[5 + pdf_index]; }
132
+ Value& x_acc(std::size_t pdf_index) { return values[7 + pdf_index]; }
133
+ Value& pdf_prior() { return values[9]; }
134
+ Value& chan_index() { return values[10]; }
135
+ Value& chan_index_in_group() { return values[11]; }
136
+ Value& flavor_id() { return values[12]; }
137
+ Value& mirror_id() { return values[13]; }
138
+ Value& indices_acc() { return values[14]; }
139
+ Value& weight_before_cuts() { return values[15]; }
140
+ Value& weight_after_cuts() { return values[16]; }
141
+ Value& adaptive_prob() { return values[17]; }
142
+ Value& pdf_cache(std::size_t pdf_index) { return values[18 + pdf_index]; }
143
+ Value& scale_cache() { return values[20]; }
144
+ };
145
+
146
+ ValueVec
147
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
148
+ ChannelResult
149
+ build_channel_part(FunctionBuilder& fb, const ChannelArgs& args) const;
150
+ ValueVec build_common_part(
151
+ FunctionBuilder& fb, const ChannelArgs& args, ChannelResult& result
152
+ ) const;
153
+
154
+ PhaseSpaceMapping _mapping;
155
+ DifferentialCrossSection _diff_xs;
156
+ AdaptiveMapping _adaptive_map;
157
+ AdaptiveDiscrete _discrete_before;
158
+ AdaptiveDiscrete _discrete_after;
159
+ std::array<std::optional<PartonDensity>, 2> _pdfs;
160
+ std::array<std::vector<me_int_t>, 2> _pdf_indices;
161
+ std::optional<EnergyScale> _energy_scale;
162
+ std::optional<PropagatorChannelWeights> _prop_chan_weights;
163
+ std::optional<SubchannelWeights> _subchan_weights;
164
+ std::optional<ChannelWeightNetwork> _chan_weight_net;
165
+ std::vector<me_int_t> _chan_weight_remap;
166
+ me_int_t _remapped_chan_count;
167
+ int _flags;
168
+ std::vector<me_int_t> _channel_indices;
169
+ me_int_t _random_dim;
170
+ std::size_t _latent_dim;
171
+ std::vector<double> _active_flavors;
172
+
173
+ friend class IntegrandProbability;
174
+ friend class MultiChannelIntegrand;
175
+ };
176
+
177
+ class MultiChannelIntegrand : public FunctionGenerator {
178
+ public:
179
+ MultiChannelIntegrand(const std::vector<std::shared_ptr<Integrand>>& integrands);
180
+
181
+ private:
182
+ ValueVec
183
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
184
+
185
+ std::vector<std::shared_ptr<Integrand>> _integrands;
186
+ };
187
+
188
+ class IntegrandProbability : public FunctionGenerator {
189
+ public:
190
+ IntegrandProbability(const Integrand& integrand);
191
+
192
+ private:
193
+ ValueVec
194
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
195
+
196
+ Integrand::AdaptiveMapping _adaptive_map;
197
+ Integrand::AdaptiveDiscrete _discrete_before;
198
+ Integrand::AdaptiveDiscrete _discrete_after;
199
+ std::size_t _permutation_count;
200
+ std::size_t _flavor_count;
201
+ bool _has_pdf_prior;
202
+ };
203
+
204
+ } // namespace madspace
@@ -0,0 +1,26 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/base.h"
4
+
5
+ namespace madspace {
6
+
7
+ class Invariant : public Mapping {
8
+ public:
9
+ Invariant(double power = 0, double mass = 0, double width = 0) :
10
+ Mapping("Invariant", {batch_float}, {batch_float}, {batch_float, batch_float}),
11
+ _power(power),
12
+ _mass(mass),
13
+ _width(width) {}
14
+
15
+ private:
16
+ Result build_forward_impl(
17
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
18
+ ) const override;
19
+ Result build_inverse_impl(
20
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
21
+ ) const override;
22
+
23
+ double _power, _mass, _width;
24
+ };
25
+
26
+ } // namespace madspace
@@ -0,0 +1,41 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/base.h"
4
+ #include "madspace/phasespace/invariants.h"
5
+
6
+ namespace madspace {
7
+
8
+ class Luminosity : public Mapping {
9
+ public:
10
+ Luminosity(
11
+ double s_lab,
12
+ double s_hat_min,
13
+ double s_hat_max = 0,
14
+ double invariant_power = 1,
15
+ double mass = 0,
16
+ double width = 0
17
+ ) :
18
+ Mapping(
19
+ "Luminosity",
20
+ {batch_float, batch_float},
21
+ {batch_float, batch_float, batch_float},
22
+ {}
23
+ ),
24
+ _s_lab(s_lab),
25
+ _s_hat_min(s_hat_min),
26
+ _s_hat_max(s_hat_max == 0 ? s_lab : s_hat_max),
27
+ _invariant(invariant_power, mass, width) {}
28
+
29
+ private:
30
+ Result build_forward_impl(
31
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
32
+ ) const override;
33
+ Result build_inverse_impl(
34
+ FunctionBuilder& fb, const ValueVec& inputs, const ValueVec& conditions
35
+ ) const override;
36
+
37
+ double _s_lab, _s_hat_min, _s_hat_max;
38
+ Invariant _invariant;
39
+ };
40
+
41
+ } // namespace madspace
@@ -0,0 +1,70 @@
1
+ #pragma once
2
+
3
+ #include "madspace/phasespace/base.h"
4
+ #include "madspace/runtime/context.h"
5
+
6
+ namespace madspace {
7
+
8
+ class MatrixElement : public FunctionGenerator {
9
+ public:
10
+ enum MatrixElementInput {
11
+ momenta_in,
12
+ alpha_s_in,
13
+ flavor_in,
14
+ random_color_in,
15
+ random_helicity_in,
16
+ random_diagram_in,
17
+ helicity_in,
18
+ diagram_in
19
+ };
20
+
21
+ enum MatrixElementOutput {
22
+ matrix_element_out,
23
+ diagram_amp2_out,
24
+ color_index_out,
25
+ helicity_index_out,
26
+ diagram_index_out
27
+ };
28
+
29
+ MatrixElement(
30
+ std::size_t matrix_element_index,
31
+ std::size_t particle_count,
32
+ const std::vector<MatrixElementInput>& inputs = {momenta_in},
33
+ const std::vector<MatrixElementOutput>& outputs = {matrix_element_out},
34
+ std::size_t diagram_count = 1,
35
+ bool sample_random_inputs = false
36
+ );
37
+ MatrixElement(
38
+ const MatrixElementApi& matrix_element_api,
39
+ const std::vector<MatrixElementInput>& inputs = {momenta_in},
40
+ const std::vector<MatrixElementOutput>& outputs = {matrix_element_out},
41
+ bool sample_random_inputs = false
42
+ ) :
43
+ MatrixElement(
44
+ matrix_element_api.index(),
45
+ matrix_element_api.particle_count(),
46
+ inputs,
47
+ outputs,
48
+ matrix_element_api.diagram_count(),
49
+ sample_random_inputs
50
+ ) {};
51
+ std::size_t matrix_element_index() const { return _matrix_element_index; }
52
+ std::size_t diagram_count() const { return _diagram_count; }
53
+ std::size_t particle_count() const { return _particle_count; }
54
+ const std::vector<MatrixElementInput>& inputs() const { return _inputs; }
55
+ const std::vector<MatrixElementOutput>& outputs() const { return _outputs; }
56
+ std::vector<MatrixElementInput> external_inputs() const;
57
+
58
+ private:
59
+ ValueVec
60
+ build_function_impl(FunctionBuilder& fb, const ValueVec& args) const override;
61
+
62
+ std::size_t _matrix_element_index;
63
+ std::size_t _particle_count;
64
+ std::size_t _diagram_count;
65
+ std::vector<MatrixElementInput> _inputs;
66
+ std::vector<MatrixElementOutput> _outputs;
67
+ bool _sample_random_inputs;
68
+ };
69
+
70
+ } // namespace madspace