/
testProfiler.py
67 lines (54 loc) · 2.28 KB
/
testProfiler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import unittest
import pygsti
import numpy as np
import pickle
import time
from pygsti.construction import std1Q_XYI
import pygsti.construction as pc
from ..testutils import BaseTestCase, compare_files, temp_files
class ProfilerTestCase(BaseTestCase):
def setUp(self):
super(ProfilerTestCase, self).setUp()
def test_profler_methods(self):
comm=None
mem = pygsti.baseobjs.profiler._get_root_mem_usage(comm)
mem = pygsti.baseobjs.profiler._get_max_mem_usage(comm)
start_time = time.time()
p = pygsti.baseobjs.Profiler(comm, default_print_memcheck=True)
p.add_time("My Name", start_time, prefix=1)
p.add_count("My Count", inc=1, prefix=1)
p.add_count("My Count", inc=2, prefix=1)
p.mem_check("My Memcheck", prefix=1)
p.mem_check("My Memcheck", prefix=1)
p.print_mem("My Memcheck just to print")
p.print_mem("My Memcheck just to print", show_minmax=True)
p.print_msg("My Message")
p.print_msg("My Message", all_ranks=True)
s = p.format_times(sortBy="name")
s = p.format_times(sortBy="time")
with self.assertRaises(ValueError):
p.format_times(sortBy="foobar")
s = p.format_counts(sortBy="name")
s = p.format_counts(sortBy="count")
with self.assertRaises(ValueError):
p.format_counts(sortBy="foobar")
s = p.format_memory(sortBy="name")
s = p.format_memory(sortBy="usage")
with self.assertRaises(ValueError):
p.format_memory(sortBy="foobar")
with self.assertRaises(NotImplementedError):
p.format_memory(sortBy="timestamp")
empty = pygsti.baseobjs.Profiler(comm, default_print_memcheck=True)
self.assertEqual(empty.format_memory(sortBy="timestamp"),"No memory checkpoints")
def test_profiler_pickling(self):
comm=None
start_time = time.time()
p = pygsti.baseobjs.Profiler(comm, default_print_memcheck=True)
p.add_time("My Name", start_time, prefix=1)
p.add_count("My Count", inc=1, prefix=1)
p.add_count("My Count", inc=2, prefix=1)
p.mem_check("My Memcheck", prefix=1)
s = pickle.dumps(p)
p2 = pickle.loads(s)
if __name__ == '__main__':
unittest.main(verbosity=2)