Skip to content

Commit 10c93e4

Browse files
author
Michael Zingale
committed
docstringing
1 parent e82b18f commit 10c93e4

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

util/profile.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,28 @@
3636
class TimerCollection:
3737

3838
def __init__(self):
39+
"""
40+
Initialize the collection of timers
41+
"""
3942
self.timers = []
4043

4144

4245
def timer(self, name):
46+
"""
47+
Create a timer with the given name. If one with that name already
48+
exists, then we return that timer.
49+
50+
Parameters
51+
----------
52+
name : str
53+
Name of the timer
54+
55+
Returns
56+
-------
57+
out : Timer object
58+
A timer object corresponding to the name.
59+
60+
"""
4361

4462
# check if any existing timer has this name, if so, return that
4563
# object
@@ -63,6 +81,9 @@ def timer(self, name):
6381

6482

6583
def report(self):
84+
"""
85+
Generate a timing summary report
86+
"""
6687

6788
spacing = ' '
6889
for t in self.timers:
@@ -72,7 +93,18 @@ def report(self):
7293
class Timer:
7394

7495
def __init__ (self, name, stack_count=0):
75-
96+
"""
97+
Initialize a timer with the given name.
98+
99+
Parameters
100+
----------
101+
name : str
102+
The name of the timer
103+
stack_count : int, optional
104+
The depth of the timer (i.e. how many timers is this nested
105+
in). This is used for printing purposes.
106+
107+
"""
76108
self.name = name
77109
self.stack_count = stack_count
78110
self.is_running = False
@@ -82,11 +114,18 @@ def __init__ (self, name, stack_count=0):
82114

83115

84116
def begin(self):
117+
"""
118+
Start timing
119+
"""
85120
self.start_time = time.time()
86121
self.is_running = True
87122

88123

89124
def end(self):
125+
"""
126+
Stop timing. This does not destroy the timer, it simply
127+
stops it from counting time.
128+
"""
90129
elapsed_time = time.time() - self.start_time
91130
self.elapsed_time += elapsed_time
92131
self.is_running = False

util/runparams.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def is_float(string):
6666
class RuntimeParameters:
6767

6868
def __init__ (self):
69+
"""
70+
Initialize a collection of runtime parameters. This class
71+
holds a dictionary of the parameters, their comments, and keeps
72+
track of which parameters were actually used.
73+
"""
6974

7075
# keep track of the parameters and their comments
7176
self.params = {}
@@ -77,8 +82,18 @@ def __init__ (self):
7782

7883
def load_params(self, file, no_new=0):
7984
"""
80-
reads lines from file and makes dictionary pairs from the data
81-
to store in self.params
85+
Reads line from file and makes dictionary pairs from the data
86+
to store.
87+
88+
Parameters
89+
----------
90+
file : str
91+
The name of the file to parse
92+
no_new : int, optional
93+
If no_new = 1, then we don't add any new paramters to the
94+
dictionary of runtime parameters, but instead just override
95+
the values of existing ones.
96+
8297
"""
8398

8499
# check to see whether the file exists
@@ -142,6 +157,12 @@ def command_line_params(self, cmd_strings):
142157
we expect things in the string in the form:
143158
["sec.opt=value", "sec.opt=value"]
144159
with each opt an element in the list
160+
161+
Parameters
162+
----------
163+
cmd_strings : list
164+
The list of strings containing runtime parameter pairs
165+
145166
"""
146167

147168
for item in cmd_strings:
@@ -185,14 +206,17 @@ def get_param(self, key):
185206

186207
def print_unused_params(self):
187208
"""
188-
print out the list of parameters that were defined by never used
209+
Print out the list of parameters that were defined by never used
189210
"""
190211
for key in self.params.keys():
191212
if not key in self.used_params:
192213
msg.warning("parameter %s never used" % (key))
193214

194215

195216
def print_all_params(self):
217+
"""
218+
Print out all runtime parameters and their values
219+
"""
196220
keys = self.params.keys()
197221
keys.sort()
198222

@@ -203,6 +227,11 @@ def print_all_params(self):
203227

204228

205229
def print_paramfile(self):
230+
"""
231+
Create a file, inputs.auto, that has the structure of a pyro
232+
inputs file, with all known parameters and values
233+
"""
234+
206235
keys = self.params.keys()
207236
keys.sort()
208237

0 commit comments

Comments
 (0)