Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some additional support for higher order objects #783

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion benchmarking/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
chip-spec-live-qubit-cc
chip-specification
chip-specification-objects
hardware-object-cxns
make-memory-descriptor
pragma-end-commuting-blocks
pragma-end-block
Expand Down
2 changes: 1 addition & 1 deletion benchmarking/qaoa-tests/generate-program.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ NOTE: This copies the list first, and so is safe to apply to &REST lists."
:do (return))
;; collect all links between these qubits
(loop :for link-obj :across (vnth 1 (chip-specification-objects chip-specification))
:for qubit-list := (first (hardware-object-cxns link-obj))
:for qubit-list := (first (quil::hardware-object-cxns link-obj))
:when (subsetp qubit-list program-qubits)
:do (push qubit-list program-links))
(apply 'qaoa-program-from-graph
Expand Down
25 changes: 9 additions & 16 deletions benchmarking/rewiring-analysis.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,21 @@
(defun init-chip (&key (architecture ':cz))
"Initialize a chip from a given architecture with no objects"
(let ((chip-spec (quil::make-chip-specification
:objects (vector (quil::make-adjustable-vector)
(quil::make-adjustable-vector))
:generic-rewriting-rules (coerce (quil::global-rewriting-rules) 'vector))))
(quil::install-generic-compilers chip-spec architecture)
chip-spec))

;;; FIXME: Duplicate of BUILD-CHIP-FROM-DIGRAPH
(defun make-graph-chip (graph &key (architecture ':cz))
"Make a chip from a graph"
(let* ((chip-spec (init-chip :architecture architecture))
(qubits
(loop :for i :below (length graph) :collect (quil::build-qubit i :type '(:RZ :X/2 :MEASURE))))
(qubit-array (make-array (length graph) :initial-contents qubits))
(links
(loop
:for (a . b) :in (graph-edges graph)
:for link-index :from 0
:collect (quil::build-link a b :type architecture)
:do (vector-push-extend link-index (quil::vnth 1 (quil::hardware-object-cxns (aref qubit-array a))))
:do (vector-push-extend link-index (quil::vnth 1 (quil::hardware-object-cxns (aref qubit-array b)))))))
(setf (quil::chip-specification-objects chip-spec)
(make-array 2 :initial-contents (list qubit-array
(coerce links 'vector))))
(let ((chip-spec (init-chip :architecture architecture)))
(loop :for i :below (length graph)
:do (quil::adjoin-hardware-object
(quil::build-qubit i :type '(:RZ :X/2 :MEASURE))
chip-spec))
(loop
:for (a . b) :in (graph-edges graph)
:do (quil::install-link-onto-chip chip-spec a b :architecture architecture))
(quil:warm-hardware-objects chip-spec)))

;; 0 -- 1
Expand Down
2 changes: 1 addition & 1 deletion boondoggle/src/producers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ PARAMETER-BOUNDS is a list of maximum random values for the gate parameters."
"This gate spec expects higher order hardware objects to exist.")
(elt (quil::chip-specification-objects chip-specification) gate-order)))
(device-index (random (length available-devices))))
(quil::vnth 0 (quil::hardware-object-cxns (quil::vnth device-index available-devices)))))
(quil::objects-on-hardware-object 0 (quil::vnth device-index available-devices))))
(t
(assert (< gate-order qubits-on-device)
nil
Expand Down
10 changes: 5 additions & 5 deletions src/addresser/addresser-common.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,11 @@ If DRY-RUN, this returns T as soon as it finds an instruction it can handle."

(loop
:for (candidate-hardware-index candidate-instr) :in instrs
:for physical-qubits := (coerce (vnth 0
(hardware-object-cxns
(chip-spec-hw-object chip-spec (1- (length (application-arguments
candidate-instr)))
candidate-hardware-index)))
:for physical-qubits := (coerce (objects-on-hardware-object
0
(chip-spec-hw-object chip-spec (1- (length (application-arguments
candidate-instr)))
candidate-hardware-index))
'list)

:for candidate-cost := (cost-function state :instr candidate-instr)
Expand Down
43 changes: 28 additions & 15 deletions src/addresser/addresser-state.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ INSTR is the \"active instruction\".
(loop :for link :across (chip-spec-links chip-spec)
:for value := (funcall link-cost link)
:do (destructuring-bind (q0 q1)
(coerce (vnth 0 (hardware-object-cxns link)) 'list)
(coerce (objects-on-hardware-object 0 link) 'list)
(setf (aref dist q0 q1) value
(aref dist q1 q0) value)))
;; for each intermediate vertex...
Expand Down Expand Up @@ -177,20 +177,33 @@ INSTR is the \"active instruction\".
:do (dotimes (j (length order-list))
(let ((hw (vnth j order-list)))
(unless (hardware-object-dead-p hw)
(let* ((instr (apply #'anon-gate "FLEX" (random-special-unitary (expt 2 qubits))
(or (coerce (vnth 0 (hardware-object-cxns hw)) 'list)
(list j))))
(instrs-decomposed (expand-to-native-instructions (list instr) chip-spec))
(instrs-compressed (if *compute-tight-recombination-bound*
(compress-instructions instrs-decomposed chip-spec)
instrs-decomposed)))
(setf (addresser-state-initial-l2p state) (make-rewiring (chip-spec-n-qubits chip-spec))
(addresser-state-working-l2p state) (make-rewiring (chip-spec-n-qubits chip-spec))
(addresser-state-logical-schedule state) (make-lscheduler)
(addresser-state-chip-schedule state) (make-chip-schedule chip-spec))
(append-instructions-to-lschedule (addresser-state-logical-schedule state)
instrs-compressed)
(funcall hardware-op hw))))))
(unless (gethash "no-compiler-path-found"
(hardware-object-misc-data hw))
(handler-case
;; This code is optional; it's only to needed
;; to help compute a bound on the single
;; operation cost on this chip. This may be a
;; source of non-determinism.
(let* ((instr (apply #'anon-gate "FLEX" (random-special-unitary (expt 2 qubits))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're just refactoring something gross I wrote, but I want to put on the record that this is a very poor kludge. I might open an issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or (coerce (objects-on-hardware-object 0 hw) 'list)
(list j))))
(instrs-decomposed (expand-to-native-instructions (list instr) chip-spec))
(instrs-compressed (if *compute-tight-recombination-bound*
(compress-instructions instrs-decomposed chip-spec)
instrs-decomposed)))
(setf (addresser-state-initial-l2p state) (make-rewiring (chip-spec-n-qubits chip-spec))
(addresser-state-working-l2p state) (make-rewiring (chip-spec-n-qubits chip-spec))
(addresser-state-logical-schedule state) (make-lscheduler)
(addresser-state-chip-schedule state) (make-chip-schedule chip-spec))
(append-instructions-to-lschedule (addresser-state-logical-schedule state)
instrs-compressed)
(funcall hardware-op hw))
(expand-instruction-recursion-depth-exceeded (condition)
(declare (ignore condition))
;; We could have cycles (but the code is
;; ultimately still compilable) because
;; there's no way to insert swaps.
(values))))))))
(setf (addresser-state-initial-l2p state) initial-l2p
(addresser-state-working-l2p state) working-l2p
(addresser-state-logical-schedule state) lscheduler
Expand Down
2 changes: 1 addition & 1 deletion src/addresser/astar-rewiring-search.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ index at a time, rather than one octet at a time."

(defun next-swap-info (swap)
(with-slots (link) swap
(destructuring-bind (q0 q1) (coerce (vnth 0 (hardware-object-cxns link)) 'list)
(destructuring-bind (q0 q1) (coerce (objects-on-hardware-object 0 link) 'list)
;; TODO: Eventually this should look up swap in the list. (See cost-function.lisp)
(values
(permutation-record-duration (vnth 0 (hardware-object-permutation-gates link)))
Expand Down
4 changes: 2 additions & 2 deletions src/addresser/fidelity-addresser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
(subschedule (chip-contiguous-subschedule-from-last-instructions
(addresser-state-chip-schedule state)
(apply #'make-qubit-resource
(coerce (vnth 0 (hardware-object-cxns hardware-object)) 'list))))
(coerce (objects-on-hardware-object 0 hardware-object) 'list))))
(preceding-fidelity
(calculate-instructions-log-fidelity subschedule
(addresser-state-chip-specification state))))
Expand Down Expand Up @@ -205,7 +205,7 @@
(swap (apply #'build-gate
(permutation-record-operator permutation-record)
'()
(coerce (vnth 0 (hardware-object-cxns hardware-object)) 'list))))
(coerce (objects-on-hardware-object 0 hardware-object) 'list))))
(calculate-instructions-fidelity (expand-to-native-instructions (list swap) chip-spec) chip-spec)))

(defmethod initialize-instance :after ((instance fidelity-addresser-state)
Expand Down
2 changes: 1 addition & 1 deletion src/addresser/temporal-addresser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
(chip-schedule-resource-carving-point
(addresser-state-chip-schedule state)
(apply #'make-qubit-resource
(coerce (vnth 0 (hardware-object-cxns hardware-object)) 'list))))))
(coerce (objects-on-hardware-object 0 hardware-object) 'list))))))
(setf time (min time intelligent-bound)))
time))))

Expand Down
13 changes: 5 additions & 8 deletions src/chip/chip-reader.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,12 @@
(t
(setf link (build-link q0 q1 :type '(:CZ)))))
(when link
;; notify the qubits that they're attached.
(dolist (qubit-index (list q0 q1))
(vector-push-extend link-index (chip-spec-links-on-qubit chip-spec qubit-index)))
(adjoin-hardware-object link chip-spec)
;; set up the connections between the qubits and the links
(connect-hardware-objects chip-spec link (chip-spec-nth-qubit chip-spec q0))
(connect-hardware-objects chip-spec link (chip-spec-nth-qubit chip-spec q1))
;; store the descriptor in the link hardware-object for later reference
(setf (hardware-object-misc-data link) link-hash)
;; and store the hardware-object into the chip specification
(vector-push-extend link (chip-spec-links chip-spec)))))))))
(setf (hardware-object-misc-data link) link-hash))))))))

(defun load-specs-layer (chip-spec specs-hash)
"Loads the \"specs\" layer into a chip-specification object."
Expand Down Expand Up @@ -375,8 +374,6 @@
(or (gethash "isa" hash-table)
(error 'missing-isa-layer-error))))
(chip-spec (make-chip-specification
:objects (make-array 2 :initial-contents (list (make-adjustable-vector)
(make-adjustable-vector)))
:generic-rewriting-rules (coerce (global-rewriting-rules) 'vector))))
;; set up the self-referential compilers
(install-generic-compilers chip-spec (list ':cz))
Expand Down
Loading