From a1a3cddc846909a346a6eb3076cf0687ccf35845 Mon Sep 17 00:00:00 2001 From: "O'Keefe, Colin B" Date: Thu, 8 Feb 2024 09:14:53 -0800 Subject: [PATCH] using flets rather than lambdas; some nits --- src/addresser/fidelity-addresser.lisp | 8 ++++---- src/addresser/logical-schedule.lisp | 14 ++++++-------- src/chip/chip-specification.lisp | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/addresser/fidelity-addresser.lisp b/src/addresser/fidelity-addresser.lisp index 6f2a652f..39bae0b0 100644 --- a/src/addresser/fidelity-addresser.lisp +++ b/src/addresser/fidelity-addresser.lisp @@ -28,10 +28,10 @@ (defun calculate-instructions-log-fidelity (instructions chip-specification) "Calculates the fidelity of a sequence of native INSTRUCTIONS on a chip with architecture governed by CHIP-SPECIFICATION (and with assumed perfect parallelization across resources)." - (reduce #'+ instructions - :key (lambda (instr) - (expt (log (get-instruction-fidelity instr chip-specification)) - 2)))) + (flet ((log-squared-fidelity (instr) + (expt (log (get-instruction-fidelity instr chip-specification)) + 2))) + (reduce #'+ instructions :key #'log-squared-fidelity :initial-value 0.0d0))) (defun application-fidelity-cost (state instr) "Compute the fidelity cost of INSTR, with respect to the provided addresser state." diff --git a/src/addresser/logical-schedule.lisp b/src/addresser/logical-schedule.lisp index eefb882b..f6be3ab1 100644 --- a/src/addresser/logical-schedule.lisp +++ b/src/addresser/logical-schedule.lisp @@ -667,19 +667,17 @@ Returns the reduction of all bumped values by COMBINE-VALUES, and a hash table m "Computes sqrt( ∑ ln(f_i)^2 ) where f_i is a fidelity associated with an instruction i, i ranging over all instructions in the LSCHEDULE" (let ((running-fidelity 0d0)) - (map-lschedule-in-topological-order - lschedule - (lambda (instr) - (incf running-fidelity (expt (log (get-instruction-fidelity instr chip-spec)) 2)))) + (flet ((add-log-fidelity-squared (instr) + (incf running-fidelity (expt (log (get-instruction-fidelity instr chip-spec)) 2)))) + (map-lschedule-in-topological-order lschedule #'add-log-fidelity-squared)) (sqrt running-fidelity))) (defun lschedule-calculate-fidelity (lschedule chip-spec) "Calculate fidelity as the minimum fidelity of the individual instructions." (let ((min-fidelity 1.0d0)) - (map-lschedule-in-topological-order - lschedule - (lambda (instr) - (setf min-fidelity (min min-fidelity (get-instruction-fidelity instr chip-spec))))) + (flet ((minimize-fidelity (instr) + (setf min-fidelity (min min-fidelity (get-instruction-fidelity instr chip-spec))))) + (map-lschedule-in-topological-order lschedule #'minimize-fidelity)) min-fidelity)) (defun lschedule-all-instructions (lschedule) diff --git a/src/chip/chip-specification.lisp b/src/chip/chip-specification.lisp index fb10621b..0e5754bb 100644 --- a/src/chip/chip-specification.lisp +++ b/src/chip/chip-specification.lisp @@ -812,7 +812,7 @@ Compilers are listed in descending precedence.") (declaim (inline warn-and-return-perfect-fidelity)) (defun warn-and-return-perfect-fidelity (instr) - (format-noise "Unknown fidelity for ~/cl-quil::instruction-fmt/. Skipping." instr) + (format-noise "Unknown fidelity for ~/cl-quil::instruction-fmt/. Assuming 1.0d0." instr) 1.0d0) (defun get-instruction-fidelity (instr chip-spec) @@ -834,7 +834,7 @@ perfect fidelity (i.e. 1.0)." (let (fidelity) (a:when-let* ((obj (lookup-hardware-object chip-spec instr)) (specs-hash (hardware-object-gate-information obj)) - (binding (and (< 0 (hash-table-count specs-hash)) + (binding (and (plusp (hash-table-count specs-hash)) (binding-from-instr instr)))) (dohash ((key val) specs-hash) (when (binding-subsumes-p key binding)