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

bugfix: copy-instance was not robust enough #905

Merged
merged 2 commits into from
Oct 19, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/clifford/perm.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"Convert a Clifford group element C into a permutation representation."
(let* ((num-qubits (num-qubits c))
(num-points (clifford-perm-degree num-qubits))
(rep (perm::iota-vector (1+ num-points))))
(rep (perm::iota-vector (1+ num-points) :element-type 'perm::perm-element)))
(dotimes (i num-points (perm::%make-perm rep))
;; The 2*(2 + i) and x/2 - 2 are to convert in/out from integers
;; which keep track of +-i/I and which don't.
Expand Down
13 changes: 11 additions & 2 deletions src/frontend-utilities.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
(:documentation
"Create a shallow copy of the object INSTANCE.
WARNING: The default will work for instances of \"idiomatic\" classes that aren't doing too many crazy things.")
(:method ((instance t))
(:method ((instance t)) instance)
(:method ((instance structure-object))
(let* ((class (class-of instance))
(copy (allocate-instance class)))
(dolist (slot (mapcar #'closer-mop:slot-definition-name (closer-mop:class-slots class)))
(when (slot-boundp instance slot)
(setf (slot-value copy slot)
(slot-value instance slot))))
(copy-instance (slot-value instance slot)))))
copy))
(:method ((instance standard-object))
(let* ((class (class-of instance))
(copy (allocate-instance class)))
(dolist (slot (mapcar #'closer-mop:slot-definition-name (closer-mop:class-slots class)))
(when (slot-boundp instance slot)
(setf (slot-value copy slot)
(copy-instance (slot-value instance slot)))))
copy)))

(defmacro dohash (((key val) hash &optional ret) &body body)
Expand Down
Loading