Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions benchmark/bench_tfphasespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

import tensorflow as tf

import numpy as np

from tfphasespace import tfphasespace

import os, sys

sys.path.append(os.path.dirname(__file__))

from .monitoring import Timer
from monitoring import Timer

# to play around with optimization, no big effect though
NUM_PARALLEL_EXEC_UNITS = 1
Expand All @@ -26,17 +28,16 @@
B_AT_REST = tf.stack((0.0, 0.0, 0.0, B_MASS), axis=-1)
PION_MASS = 139.6

N_EVENTS = 1000000
CHUNK_SIZE = N_EVENTS
N_EVENTS = 100000000
CHUNK_SIZE = 1000000

N_EVENTS_VAR = tf.Variable(initial_value=N_EVENTS)
CHUNK_SIZE_VAR = tf.Variable(initial_value=CHUNK_SIZE)

samples = [tfphasespace.generate(B_AT_REST,
[PION_MASS, PION_MASS, PION_MASS],
CHUNK_SIZE_VAR)
for _ in range(0, N_EVENTS, CHUNK_SIZE)
]
for _ in range(0, N_EVENTS, CHUNK_SIZE)]

sess = tf.Session(
config=config
Expand All @@ -51,10 +52,15 @@ def test_three_body():
print("Initial run (may takes more time than consequent runs)")
do_run() # to get rid of initial overhead
print("starting benchmark")
with Timer(verbose=True):
with Timer(verbose=True) as timer:
CHUNK_SIZE_VAR.load(CHUNK_SIZE + 1, session=sess) # +1 to make sure we're not using any trivial caching
samples = do_run()
tot_samples = sum(sample[0].shape[0] for sample in samples)
if np.any(samples[0][0] == samples[1][0]):
raise ValueError("You're generating the same sample!")
print("Total number of generated samples", tot_samples)
print("Shape of one particle momentum", samples[0][1][0].shape)
print("Time per sample: {} ms".format(timer.elapsed/tot_samples))


def do_run():
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bench_tgenphasespace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "TLorentzVector.h"
#include "TGenPhaseSpace.h"

Int_t N_EVENTS = 1000000;
Int_t N_EVENTS = 100000000;

int bench_tgenphasespace()
{
Expand Down