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

Make chip-contiguous-subschedule-from-last-instructions non-recursive #693

Closed
wants to merge 2 commits into from

Conversation

erichulburd
Copy link
Contributor

@erichulburd erichulburd commented Jan 26, 2021

Closes #697.

@erichulburd erichulburd requested a review from notmgsk January 26, 2021 03:02
@erichulburd erichulburd requested a review from a team as a code owner January 26, 2021 03:02
@erichulburd erichulburd force-pushed the nonrecursive_contiguous_subschedule branch from f73467f to 568dcbe Compare January 26, 2021 03:06
Copy link
Contributor Author

@erichulburd erichulburd left a comment

Choose a reason for hiding this comment

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

Lisp single-link lists are still not entirely intuitive to me, so want to double check myself on the append and setf/cdr operation below.

Also, any reason to use setq in place of setf here or just generally?

src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
(loop for predecessor in predecessors
do (unless (gethash predecessor seen)
(setf (gethash predecessor seen) t)
(setf queue (append queue (list predecessor)))))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this operation efficient memory resource-wise?

Copy link
Member

Choose a reason for hiding this comment

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

Generally, no. It will copy the entire queue, and as a part of that copy, append the element. So it's O(N) in time and space. It's preferred to use an actual queue-like data structure instead of raw Lisp lists.

There are a couple options for FIFO queues in quilc. The first is to use cl-heap. The second is to use the very simple queue data structure in god-table.lisp (see cl-quil.clifford::make-queue).

Copy link
Member

Choose a reason for hiding this comment

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

If you instead just want a stack, then using push and pop on Lisp lists works fine, and is O(1). (I don't think a stack can be used for this BFS though.)

src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
Copy link
Member

@stylewarning stylewarning left a comment

Choose a reason for hiding this comment

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

I noted mostly style and efficiency concerns, which you may incorporate. After that, I'll be happy to check correctness.

(loop for predecessor in predecessors
do (unless (gethash predecessor seen)
(setf (gethash predecessor seen) t)
(setf queue (append queue (list predecessor)))))
Copy link
Member

Choose a reason for hiding this comment

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

Generally, no. It will copy the entire queue, and as a part of that copy, append the element. So it's O(N) in time and space. It's preferred to use an actual queue-like data structure instead of raw Lisp lists.

There are a couple options for FIFO queues in quilc. The first is to use cl-heap. The second is to use the very simple queue data structure in god-table.lisp (see cl-quil.clifford::make-queue).

src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
(loop for predecessor in predecessors
do (unless (gethash predecessor seen)
(setf (gethash predecessor seen) t)
(setf queue (append queue (list predecessor)))))
Copy link
Member

Choose a reason for hiding this comment

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

If you instead just want a stack, then using push and pop on Lisp lists works fine, and is O(1). (I don't think a stack can be used for this BFS though.)

src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
@erichulburd erichulburd force-pushed the nonrecursive_contiguous_subschedule branch from 568dcbe to 0d1084b Compare January 26, 2021 21:50
Copy link
Contributor Author

@erichulburd erichulburd left a comment

Choose a reason for hiding this comment

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

Per discussion with Mark, I also owe a new test case that passes here but will blow up on the previous implementation.

src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Show resolved Hide resolved
@erichulburd erichulburd force-pushed the nonrecursive_contiguous_subschedule branch from 0d1084b to 9c35515 Compare January 26, 2021 21:59
@@ -100,3 +100,26 @@
(quil::chip-contiguous-subschedule-from-last-instructions
sched (quil::make-qubit-resource 0 2))
expected-subschedule))))))

(deftest test-fidelity-addresser-subschedule-on-deep-circuit ()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can confirm this spec will result in control stack exhaustion with old implementation:

Screen Shot 2021-01-27 at 11 32 38 AM (2)

Copy link
Member

Choose a reason for hiding this comment

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

we gotta work on your emacs theme at some point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All I really care about is ENORMOUS FONT. Otherwise, I'm open.

@notmgsk
Copy link
Member

notmgsk commented Jan 27, 2021

FYI it looks like chip-schedule-from-carving-point is unused now, and can probably be removed.

@erichulburd erichulburd force-pushed the nonrecursive_contiguous_subschedule branch from f7ad1f3 to 7331aee Compare January 27, 2021 20:16
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
((resource-subsetp (instruction-resources instr)
resource)
(map nil #'mark-predecessors-seen (gethash instr earlier-instrs)))))
(bottoms-up (instr)
Copy link
Member

Choose a reason for hiding this comment

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

This was nice while it lasted 🍻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🍻

@@ -100,3 +100,26 @@
(quil::chip-contiguous-subschedule-from-last-instructions
sched (quil::make-qubit-resource 0 2))
expected-subschedule))))))

(deftest test-fidelity-addresser-subschedule-on-deep-circuit ()
Copy link
Member

Choose a reason for hiding this comment

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

we gotta work on your emacs theme at some point

@erichulburd erichulburd force-pushed the nonrecursive_contiguous_subschedule branch from 7331aee to afb4812 Compare January 28, 2021 01:38
@notmgsk notmgsk changed the title refactor chip-contiguous-subschedule-from-last-instructions to non-re… Make chip-contiguous-subschedule-from-last-instructions non-ronrecursive Jan 28, 2021
@erichulburd erichulburd requested a review from notmgsk January 28, 2021 18:28
@kalzoo kalzoo changed the title Make chip-contiguous-subschedule-from-last-instructions non-ronrecursive Make chip-contiguous-subschedule-from-last-instructions non-recursive Feb 1, 2021
notmgsk
notmgsk previously approved these changes Apr 1, 2021
Copy link
Member

@stylewarning stylewarning left a comment

Choose a reason for hiding this comment

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

My comments are consistency-in-style nits. Otherwise looks good-to-go.

src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
src/addresser/outgoing-schedule.lisp Outdated Show resolved Hide resolved
@erichulburd erichulburd force-pushed the nonrecursive_contiguous_subschedule branch from afb4812 to a298cdf Compare April 12, 2021 23:51
@erichulburd
Copy link
Contributor Author

test error

   When attempting to read the slot's value (slot-value), the slot
  COMPILATION-TOLERANCE is missing from the object
  #<CL-QUIL::STATE-PREP-COMPRESSION-TOLERANCE-ERROR {100560AB83}>.
It has a slot CL-QUIL::COMPILATION-TOLERANCE, while CL-QUIL-TESTS::COMPILATION-TOLERANCE is requested.

@stylewarning
Copy link
Member

test error

   When attempting to read the slot's value (slot-value), the slot
  COMPILATION-TOLERANCE is missing from the object
  #<CL-QUIL::STATE-PREP-COMPRESSION-TOLERANCE-ERROR {100560AB83}>.
It has a slot CL-QUIL::COMPILATION-TOLERANCE, while CL-QUIL-TESTS::COMPILATION-TOLERANCE is requested.

Seems like a simple package issue, somewhere there's a (slot-value foo 'compilation-tolerance) that ought to be (slot-value foo 'cl-quil::compilation-tolerance). (could also be with-slots)

@erichulburd erichulburd force-pushed the nonrecursive_contiguous_subschedule branch from 4f56b08 to 576baef Compare May 10, 2021 21:17
@notmgsk
Copy link
Member

notmgsk commented Oct 23, 2021

Can this be closed in favour of #717, @erichulburd?

@notmgsk notmgsk closed this Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Call stack exhaustion when compiling very deep programs
3 participants