Skip to content

Commit

Permalink
using flets rather than lambdas; some nits
Browse files Browse the repository at this point in the history
  • Loading branch information
macrologist committed Feb 8, 2024
1 parent f77ad83 commit a1a3cdd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/addresser/fidelity-addresser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
14 changes: 6 additions & 8 deletions src/addresser/logical-schedule.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/chip/chip-specification.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a1a3cdd

Please sign in to comment.