コード例 #1
0
def hit_global_weight_test():
    Hit.clear_global_weights()
    hit = Hit.new_from_dict({
        "spill": 1,
        "event_number": 2,
        "particle_number": 3
    })
    if (abs(hit.get("global_weight") - 1.) > 1e-9): return 'fail'
    hit.set('global_weight', 0.5)
    if (abs(hit.get_global_weight() - 0.5) > 1e-9): return 'fail'
    Hitcore.clear_global_weights()
    if (abs(hit.get_global_weight() - 1.) > 1e-9): return 'fail'
    return 'pass'
コード例 #2
0
ファイル: test_system.py プロジェクト: chrisrogers1234/xboa
def system_mem_test(verbose=True):
    # Test memory usage isn't too huge
    # Test bunch cleans up after itself
    # We allocate new memory in this test and then deallocate it. Python process
    # will increase its buffer but the buffer should be empty by the end. Then
    # run again - python process should not increase buffer size by much as on
    # second iteration we
    import gc
    gc.collect()  #force a memory cleanup
    mem_usage_b4 = print_mem_usage()
    bunch_list = []
    print("Allocating memory")
    for i in range(3):
        bunch_list.append(Bunch())
        for i in range(10000):
            bunch_list[-1].append(Hit())
            bunch_list[-1][0].get('x')
            bunch_list[-1][0].set('x', 1.)
            bunch_list[-1][0].set('global_weight', 0.5)
            bunch_list[-1][0].get('global_weight')  # this function was leaking
        bunch_list[-1].moment(['x'])
    Hit.clear_global_weights()
    mem_usage = print_mem_usage()
    print("Cleaning memory")
    bunch = bunch_list[0]
    while len(bunch) > 0:
        del bunch[0]

    bunch_list.remove(bunch_list[0])
    del bunch_list
    Hit.clear_global_weights()
    gc.collect()  #force a memory cleanup
    mem_usage = print_mem_usage()
    if verbose:
        print("Memory usage after cleanup in Mb (target 0 Mb):", mem_usage,
              '(absolute)', mem_usage - mem_usage_b4, '(difference)')
    if mem_usage - mem_usage_b4 > 1000.:
        return "warn"  # looks like memory leak...
    return "pass"
コード例 #3
0
def hit_clear_global_weights_test(hit):
    hit.set('global_weight', 1000.)
    Hit.clear_global_weights()
    test_pass = abs(hit.get('global_weight') - 1.) < __float_tol
    if test_pass: return 'pass'
    return 'fail'