Skip to content

Commit 4e4bef7

Browse files
author
David, Mark H
committed
minor bug fixing, refactoring, and doc improvements for benchmark-nq stuff
Makefile - remove a nonexistent and put in the two actual new PHONY's benchmarking/quilc-mon-prof.lisp - add top-level documentation, explaining "WIP" limitation - restore use of sample-interval arg to MONITOR-RUN, left commented out in error - add doc string for MONITOR-RUN - remove depth check subsection, which contained obsolete code benchmarking/quilc-perf.lisp - document format of *benchmark-quilc-perf-series*, which is also results returned by benchmark-nq and the format of the main arg to the CSV emitter. - replace two nearly identical CSV emitter functions by a single one, and add a doc string for it.
1 parent 15ac5e2 commit 4e4bef7

File tree

3 files changed

+58
-75
lines changed

3 files changed

+58
-75
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ test-ccl:
164164
###############################################################################
165165
# BENCHMARKS
166166
###############################################################################
167-
.PHONY: benchmark-qasm benchmark-qasm-big
167+
.PHONY: benchmark-qasm benchmark-nq benchmark-nq-2x
168168

169169
benchmark-qasm:
170170
$(QUICKLISP) \

benchmarking/quilc-mon-prof.lisp

+16-31
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,28 @@
99
;;;; Monitoring and Profiling
1010

1111
;; This builds on quilc-perf.lisp and is for monitoring and profiling,
12-
;; as opposed to simple benchmarks, and is a WIP.
12+
;; as opposed to simple benchmarks, and is a WIP in that we have not
13+
;; established a makefile entry to run this. That is because, while
14+
;; it's been useful to run for probing and experimenting in a REPL, we
15+
;; so far lack really good theory of operation and associated modes of
16+
;; running. We hope with time to get there.
1317

1418

1519
(defparameter *monitor-types*
1620
'(:mon #+sbcl :sb-sprof))
1721

1822
(defun monitor-run (program-type chip-type nq repeats monitor
1923
&optional report-type sample-interval)
24+
"Do REPEATS perf runs for PROGRAM-TYPE and CHIP-TYPE (as documented
25+
at the top of QUILC-PERF module) using the specified MONITOR, which
26+
must be one of those in the list *monitor-types*. Optional args
27+
REPORT-TYPE and SAMPLE-INTERVAL are only relevant when MONITOR is
28+
:SB-SPROF in which case REPORT-TYPE is passed as the same-named arg
29+
to SB-SPROF:REPORT, and SAMPLE-INTERVAL is passed as the same-named
30+
arg to SB-SPROF:START-PROFILING. Note as well that for :SB-SPROF
31+
monitor, only the current thread is profiled. This returns no
32+
useful value. It's just run in order to get output from the
33+
monitor."
2034
(when (not (member monitor *monitor-types*))
2135
(unless (null monitor) ; if so, just silently default with no warning
2236
(warn "unrecognized monitor, should be one of ~s; using ~s"
@@ -55,8 +69,7 @@
5569
(progn
5670
(sb-sprof:reset)
5771
(sb-sprof:start-profiling
58-
;; :sample-interval (or sample-interval 0.005) ; default = 0.01
59-
:sample-interval 0.0001
72+
:sample-interval (or sample-interval 0.005) ; default = 0.01
6073
:threads (list sb-thread:*current-thread*))
6174
(funcall thunk)
6275
(sb-sprof:report
@@ -116,34 +129,6 @@
116129

117130

118131

119-
120-
;;;; depth check
121-
122-
(defun quil-parse-to-logical-schedule (parse)
123-
(let* ((instructions-vector (quil:parsed-program-executable-code parse))
124-
(instructions-list (concatenate 'list instructions-vector))
125-
(lsched (quil.si:make-lscheduler)))
126-
(quil.si:append-instructions-to-lschedule lsched instructions-list)
127-
lsched))
128-
129-
(defun depth-check (nq)
130-
(let* ((parse (build-benchmark-program nq :hadamard))
131-
(logical-schedule (quil-parse-to-logical-schedule parse)))
132-
(depth-check-1 logical-schedule)))
133-
134-
(defun depth-check-1 (logical-schedule)
135-
(let* ((old-walk-depth
136-
(let ((quil::*new-walk* nil))
137-
(quil::lscheduler-calculate-depth logical-schedule)))
138-
(new-walk-depth
139-
(let ((quil::*new-walk* t))
140-
(quil::lscheduler-calculate-depth logical-schedule))))
141-
(list
142-
(= old-walk-depth new-walk-depth)
143-
old-walk-depth new-walk-depth logical-schedule)))
144-
145-
146-
147132
;;;; SB-SPROF run 20, 50, 80, 110, 140
148133

149134
(defun sb-sprof-run ()

benchmarking/quilc-perf.lisp

+41-43
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
;;; We provide a few kinds of chips and Quil programs and several
1515
;;; methods of benchmarking as a function of nQ.
1616
;;;
17-
;;; The chip types: :fully-connectes, :linear
17+
;;; The chip types: :fully-connected, :linear
1818
;;;
1919
;;; The program types:
2020
;;;
@@ -48,17 +48,24 @@
4848
(defvar *benchmark-quilc-perf-series* '()
4949
"Initially an empty list, gets set to the list of results by each
5050
run of benchmark-nq, provided as a developer convenience for later
51-
perusal, e.g., in a REPL.")
51+
perusal, e.g., in a REPL. These results are in a list of sublists
52+
of the form
53+
54+
((program-type chip-type) . timings)
55+
56+
where timings is a list of lists of the form (nQ time), where time
57+
is an integer as a multiple of internal-time-units-per-second. Each
58+
sublist has the same length and contains the same nQ values.")
5259

5360
(defun benchmark-nq ()
5461
(setq *benchmark-quilc-perf-series*
5562
(benchmark-quilc-perf
5663
:start *default-benchmark-nq-start*
5764
:step *default-benchmark-nq-step*
5865
:end *default-benchmark-nq-end*))
59-
(csv-raw-timings *benchmark-quilc-perf-series*)
66+
(csv-timings *benchmark-quilc-perf-series*)
6067
(terpri)
61-
(csv-max-of-series-style *benchmark-quilc-perf-series*)
68+
(csv-timings *benchmark-quilc-perf-series* :max-of-series-style t)
6269
*benchmark-quilc-perf-series*)
6370

6471
(defparameter *benchmark-program-types*
@@ -219,68 +226,59 @@
219226
`(((,Program-type ,chip-type)
220227
,@perf-series)))))))
221228

222-
(defun csv-raw-timings (x)
223-
;; Arrange like so:
224-
;; header row:
225-
;; "nQ", program1/chip1, ..., programn, chipn"
226-
;; rest of rows:
227-
;; <nQ>, <time of program1/chip1>, ..., <time of programn/chipn>
229+
(defun csv-timings (x &key max-of-series-style)
230+
"Output timing data X as comma-separated values like so
228231
229-
;; header row:
230-
(princ "nQ")
231-
(loop :with rows := '()
232-
:for ((chip-type program-type) . timings) :in x
233-
:do (format t ", ~(~a/~a~)" chip-type program-type)
234-
(loop :for (nq time) :in timings
235-
:as time-in-seconds-float
236-
:= (internal-time-to-seconds time)
237-
:as row := (assoc nq rows)
238-
:when (null row)
239-
:do (setq row (list nq))
240-
(setq rows (nconc rows (list row)))
241-
:do (nconc row (list time-in-seconds-float)))
242-
:finally (terpri)
243-
(loop :for (nq . times) :in rows
244-
:do (format t "~d" nq)
245-
(loop :for time :in times
246-
:do (format t ", ~,3f" time))
247-
(terpri))
248-
(return rows)))
232+
header row:
233+
\"nQ\", program/chip-1, ..., program/chip-n
234+
data rows:
235+
<nQ>, <time of program/chip-1>, ..., <time of program/chip-n>
249236
250-
(defun transform-val-to-ratio-of-max (original-val max-of-series)
251-
(/ (float original-val) max-of-series))
237+
In the header row, each program/chip pair is the name of the program
238+
type and chip type, respectively. In the data rows each row represents
239+
a series of program/chip timings, each written as a floating point
240+
number. MAX-OF-SERIES-STYLE defaults to false, but if specified true,
241+
each timing is converted to be a ratio of the origin timing to the
242+
maximum timing of the series.
252243
253-
(defun csv-max-of-series-style (x)
254-
;; Arrange like so:
255-
;; header row:
256-
;; "nQ", program1/chip1, ..., programn, chipn"
257-
;; rest of rows:
258-
;; <nQ>, <time of program1/chip1>, ..., <time of programn/chipn>
244+
X's format is as documented for *benchmark-quilc-perf-series*.
259245
246+
Besides outputting the rows as described, this returns a list of the
247+
data rows only, each row being of the form (nQ . timings), where nQ is
248+
a fixnum and timings is a list of floats."
260249
;; header row:
261250
(princ "nQ")
262251
(loop :with rows := '()
263252
:for ((chip-type program-type) . timings) :in x
264253
:as max-of-series
265-
:= (loop :for (nil time) :in timings
266-
:maximize time)
254+
:= (and max-of-series-style
255+
(loop :for (nil time) :in timings
256+
:maximize time))
267257
:do (format t ", ~(~a/~a~)" chip-type program-type)
268258
(loop :for (nq time) :in timings
269-
:as time-ratio
270-
:= (transform-val-to-ratio-of-max time max-of-series)
259+
:as time-as-float
260+
:= (if max-of-series-style
261+
;; time/max ratio
262+
(transform-val-to-ratio-of-max time max-of-series)
263+
;; time in seconds
264+
(internal-time-to-seconds time))
271265
:as row := (assoc nq rows)
272266
:when (null row)
273267
:do (setq row (list nq))
274268
(setq rows (nconc rows (list row)))
275-
:do (nconc row (list time-ratio)))
269+
:do (nconc row (list time-as-float)))
276270
:finally (terpri)
271+
;; data rows:
277272
(loop :for (nq . times) :in rows
278273
:do (format t "~d" nq)
279274
(loop :for time :in times
280275
:do (format t ", ~,3f" time))
281276
(terpri))
282277
(return rows)))
283278

279+
(defun transform-val-to-ratio-of-max (original-val max-of-series)
280+
(/ (float original-val) max-of-series))
281+
284282

285283

286284

0 commit comments

Comments
 (0)