-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the permutation synthesis machinery better.
- Loading branch information
Showing
2 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
;;;; linear-reversible-circuit.lisp | ||
;;;; permutation-tests.lisp | ||
;;;; | ||
;;;; Author: Charles Zhang | ||
|
||
(in-package #:cl-quil-tests) | ||
|
||
(a:define-constant +prime+ #(0 2 3 5 7 1 4 6) :test #'equalp) | ||
|
||
;; Test that internal assertions are all satisfied. | ||
(deftest permutation-internal-assertion () | ||
(quil::synthesize-permutation #(0 1)) | ||
(quil::synthesize-permutation #(1 0)) | ||
(quil::synthesize-permutation #(3 0 1 2)) | ||
(quil::synthesize-permutation +prime+)) | ||
(defun matrix-from-permutation (permutation) | ||
(let* ((size (length permutation)) | ||
(matrix (magicl:zeros (list size size) :type '(complex double-float)))) | ||
(loop :for i :from 0 | ||
:for j :across permutation | ||
:do (setf (magicl:tref matrix j i) 1)) | ||
matrix)) | ||
|
||
(defun permutation-synthesis-as-parsed-program (permutation) | ||
(make-instance 'quil::parsed-program | ||
:executable-code (coerce (quil::synthesize-permutation permutation) 'vector))) | ||
|
||
;;; Test that the synthesized permutation when simulated performs the | ||
;;; action of the permutation. | ||
(deftest test-permutation-gates-logical-matrix-equivalent () | ||
(flet ((test (permutation) | ||
(assert (quil::operator= | ||
(quil:parsed-program-to-logical-matrix | ||
(permutation-synthesis-as-parsed-program permutation) | ||
:compress-qubits nil) | ||
(matrix-from-permutation permutation))))) | ||
(test #(0 1)) | ||
(test #(1 0)) | ||
(test #(3 0 1 2)) | ||
(test #(2 0 3 1)) | ||
(test #(1 0 3 2)) | ||
(test #(0 2 3 1)) | ||
(test #(2 1 3 0)) | ||
(test #(3 1 2 0)) | ||
(test +prime+))) |