|
14 | 14 | ;;; We provide a few kinds of chips and Quil programs and several
|
15 | 15 | ;;; methods of benchmarking as a function of nQ.
|
16 | 16 | ;;;
|
17 |
| -;;; The chip types: :fully-connectes, :linear |
| 17 | +;;; The chip types: :fully-connected, :linear |
18 | 18 | ;;;
|
19 | 19 | ;;; The program types:
|
20 | 20 | ;;;
|
|
48 | 48 | (defvar *benchmark-quilc-perf-series* '()
|
49 | 49 | "Initially an empty list, gets set to the list of results by each
|
50 | 50 | 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.") |
52 | 59 |
|
53 | 60 | (defun benchmark-nq ()
|
54 | 61 | (setq *benchmark-quilc-perf-series*
|
55 | 62 | (benchmark-quilc-perf
|
56 | 63 | :start *default-benchmark-nq-start*
|
57 | 64 | :step *default-benchmark-nq-step*
|
58 | 65 | :end *default-benchmark-nq-end*))
|
59 |
| - (csv-raw-timings *benchmark-quilc-perf-series*) |
| 66 | + (csv-timings *benchmark-quilc-perf-series*) |
60 | 67 | (terpri)
|
61 |
| - (csv-max-of-series-style *benchmark-quilc-perf-series*) |
| 68 | + (csv-timings *benchmark-quilc-perf-series* :max-of-series-style t) |
62 | 69 | *benchmark-quilc-perf-series*)
|
63 | 70 |
|
64 | 71 | (defparameter *benchmark-program-types*
|
|
219 | 226 | `(((,Program-type ,chip-type)
|
220 | 227 | ,@perf-series)))))))
|
221 | 228 |
|
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 |
228 | 231 |
|
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> |
249 | 236 |
|
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. |
252 | 243 |
|
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*. |
259 | 245 |
|
| 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." |
260 | 249 | ;; header row:
|
261 | 250 | (princ "nQ")
|
262 | 251 | (loop :with rows := '()
|
263 | 252 | :for ((chip-type program-type) . timings) :in x
|
264 | 253 | :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)) |
267 | 257 | :do (format t ", ~(~a/~a~)" chip-type program-type)
|
268 | 258 | (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)) |
271 | 265 | :as row := (assoc nq rows)
|
272 | 266 | :when (null row)
|
273 | 267 | :do (setq row (list nq))
|
274 | 268 | (setq rows (nconc rows (list row)))
|
275 |
| - :do (nconc row (list time-ratio))) |
| 269 | + :do (nconc row (list time-as-float))) |
276 | 270 | :finally (terpri)
|
| 271 | + ;; data rows: |
277 | 272 | (loop :for (nq . times) :in rows
|
278 | 273 | :do (format t "~d" nq)
|
279 | 274 | (loop :for time :in times
|
280 | 275 | :do (format t ", ~,3f" time))
|
281 | 276 | (terpri))
|
282 | 277 | (return rows)))
|
283 | 278 |
|
| 279 | +(defun transform-val-to-ratio-of-max (original-val max-of-series) |
| 280 | + (/ (float original-val) max-of-series)) |
| 281 | + |
284 | 282 |
|
285 | 283 |
|
286 | 284 |
|
|
0 commit comments