diff --git a/examples/example1.qasm b/examples/example1.qasm index 23e4712..c26ddea 100644 --- a/examples/example1.qasm +++ b/examples/example1.qasm @@ -1,31 +1,39 @@ // This program does nothing in particular, but shows how to use g2q functions.; // example1.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[5]; creg c[5]; // Five reset gates.; +// Begin g1y; reset q[0]; reset q[1]; reset q[2]; reset q[3]; reset q[4]; +// End g1y; // A swap gate.; +// Begin swap; cx q[0],q[1]; cx q[1],q[0]; cx q[0],q[1]; +// End swap; // A swap-fast gate.; swap q[0],q[1]; // Five h gates.; +// Begin g1y; h q[0]; h q[1]; h q[2]; h q[3]; h q[4]; +// End g1y; // Two x gates.; +// Begin g1y; x q[1]; x q[2]; +// End g1y; // Various basic gates.; id q[3]; y q[4]; @@ -40,18 +48,23 @@ u3(1.6,1.6,1.6) q[2]; // Controlled x.; cx q[2],q[0]; // Controlled y.; +// Begin cy; sdg q[4]; cx q[3],q[4]; s q[4]; +// End cy; // Controlled y in fast form.; cy q[3],q[1]; // Controlled z.; +// Begin cz; h q[2]; cx q[4],q[2]; h q[2]; +// End cz; // Controlled z in fast form.; cz q[4],q[2]; // Controlled h.; +// Begin ch; h q[0]; sdg q[0]; cx q[2],q[0]; @@ -63,9 +76,11 @@ h q[0]; s q[0]; x q[0]; s q[2]; +// End ch; // Controlled h in fast form.; ch q[2],q[0]; // Toffoli (ccx).; +// Begin ccx; h q[2]; cx q[1],q[2]; tdg q[2]; @@ -81,6 +96,7 @@ cx q[0],q[1]; t q[0]; tdg q[1]; cx q[0],q[1]; +// End ccx; // Toffoli in fast form.; ccx q[0],q[1],q[2]; // rx.; @@ -96,26 +112,32 @@ u1(1.6) q[3]; // rz in fast form.; rz(1.570795) q[3]; // crz.; +// Begin crz; u1(0.8) q[4]; cx q[3],q[4]; u1(-0.8) q[4]; cx q[3],q[4]; +// End crz; // crz in fast form.; crz(1.570795) q[3],q[4]; // Controlled u1.; +// Begin cu1; u1(0.8) q[2]; cx q[2],q[0]; u1(-0.8) q[0]; cx q[2],q[0]; u1(0.8) q[2]; +// End cu1; // Controlled u1 in fast form.; cu1(1.6) q[2],q[0]; // Controlled u3.; +// Begin cu3; u1(0.0) q[0]; cx q[2],q[0]; u3(-0.8,0,-1.6) q[0]; cx q[2],q[0]; u3(0.8,1.6,0) q[0]; +// End cu3; // Controlled u3 in fast form.; cu3(1.6,1.6,1.6) q[2],q[0]; // Conditional1 eq.; @@ -123,11 +145,13 @@ if(q==1) y q[2]; // Conditional2 eq.; if(q[2]!=1) y q[2]; // Barriers.; +// Begin g1y; barrier q[0]; barrier q[1]; barrier q[2]; barrier q[3]; barrier q[4]; +// End g1y; // Measuring; measure q[0] -> c[0]; measure q[1] -> c[1]; diff --git a/examples/example10.qasm b/examples/example10.qasm index e3c60a3..8b223eb 100644 --- a/examples/example10.qasm +++ b/examples/example10.qasm @@ -1,23 +1,29 @@ // example10.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[5]; creg c[5]; +// Begin g1y; h q[0]; h q[1]; h q[2]; h q[3]; h q[4]; +// End g1y; +// Begin g1y; x q[0]; x q[1]; x q[2]; x q[3]; x q[4]; +// End g1y; +// Begin qmeasy; measure q[0] -> c[0]; measure q[1] -> c[1]; measure q[2] -> c[2]; measure q[3] -> c[3]; measure q[4] -> c[4]; +// End qmeasy; // qdeclare qx-simulator error_model depolarizing_channel,0.001; // qdeclare qlib-simulator // Hello qlib-simulator; diff --git a/examples/example11.qasm b/examples/example11.qasm index e3b5bca..dec97ea 100644 --- a/examples/example11.qasm +++ b/examples/example11.qasm @@ -1,14 +1,16 @@ // example11.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[5]; creg c[5]; sdg q[0]; +// Begin g1y; id q[1]; id q[2]; id q[3]; id q[4]; +// End g1y; h q[0]; sdg q[3]; h q[3]; @@ -29,10 +31,12 @@ h q[3]; h q[4]; cx q[3],q[2]; h q[3]; +// Begin qmeasy; measure q[0] -> c[0]; measure q[1] -> c[1]; measure q[2] -> c[2]; measure q[3] -> c[3]; measure q[4] -> c[4]; +// End qmeasy; // qdeclare qx-simulator error_model depolarizing_channel,0.001; // qdeclare qlib-simulator // Hello qlib-simulator; diff --git a/examples/example12.qasm b/examples/example12.qasm index ac6072a..16bec31 100644 --- a/examples/example12.qasm +++ b/examples/example12.qasm @@ -1,5 +1,5 @@ // example12.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[3]; @@ -8,6 +8,7 @@ x q[0]; h q[1]; h q[2]; h q[0]; +// Begin ccx; h q[0]; cx q[1],q[0]; tdg q[0]; @@ -23,6 +24,7 @@ cx q[2],q[1]; t q[2]; tdg q[1]; cx q[2],q[1]; +// End ccx; h q[1]; h q[2]; x q[1]; @@ -34,7 +36,9 @@ x q[1]; x q[2]; h q[1]; h q[2]; +// Begin qmeasy; measure q[1] -> c[1]; measure q[2] -> c[2]; +// End qmeasy; // qdeclare qx-simulator error_model depolarizing_channel,0.001; // qdeclare qlib-simulator // Hello qlib-simulator; diff --git a/examples/example2.qasm b/examples/example2.qasm index 73965af..64d2d54 100644 --- a/examples/example2.qasm +++ b/examples/example2.qasm @@ -1,5 +1,5 @@ // example2.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; diff --git a/examples/example3.qasm b/examples/example3.qasm index 6866c9e..d38e4b1 100644 --- a/examples/example3.qasm +++ b/examples/example3.qasm @@ -1,29 +1,47 @@ // example3.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[5]; creg c[5]; +// Begin g1y; h q[0]; h q[1]; +// End g1y; +// Begin g1y; s q[0]; s q[1]; +// End g1y; +// Begin g1cxg1; h q[0]; cx q[1],q[0]; h q[0]; +// End g1cxg1; +// Begin g1y; s q[0]; s q[1]; +// End g1y; +// Begin g1y; h q[0]; h q[1]; +// End g1y; +// Begin g1y; x q[0]; x q[1]; +// End g1y; +// Begin g1cxg1; h q[0]; cx q[1],q[0]; h q[0]; +// End g1cxg1; +// Begin g1y; x q[0]; x q[1]; +// End g1y; +// Begin g1y; h q[0]; h q[1]; +// End g1y; // Measuring; measure q[0] -> c[0]; measure q[1] -> c[1]; diff --git a/examples/example4.qasm b/examples/example4.qasm index bcc60df..7cfcf65 100644 --- a/examples/example4.qasm +++ b/examples/example4.qasm @@ -1,42 +1,58 @@ // example4.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[5]; creg c[5]; +// Begin g1y; h q[0]; h q[1]; h q[2]; h q[3]; h q[4]; +// End g1y; +// Begin g1xy; +// Begin g1y; id q[0]; id q[1]; id q[2]; id q[3]; id q[4]; +// End g1y; +// Begin g1y; id q[0]; id q[1]; id q[2]; id q[3]; id q[4]; +// End g1y; +// Begin g1y; id q[0]; id q[1]; id q[2]; id q[3]; id q[4]; +// End g1y; +// Begin g1y; id q[0]; id q[1]; id q[2]; id q[3]; id q[4]; +// End g1y; +// Begin g1y; id q[0]; id q[1]; id q[2]; id q[3]; id q[4]; +// End g1y; +// End g1xy; // Measuring; +// Begin qmeasy; measure q[0] -> c[0]; measure q[1] -> c[1]; measure q[2] -> c[2]; measure q[3] -> c[3]; measure q[4] -> c[4]; +// End qmeasy; diff --git a/examples/example5.qasm b/examples/example5.qasm index 7e3e3af..476b7ee 100644 --- a/examples/example5.qasm +++ b/examples/example5.qasm @@ -1,13 +1,15 @@ // example5.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[4]; creg c[2]; +// Begin g1y; h q[0]; h q[1]; h q[2]; h q[3]; +// End g1y; cx q[0],q[1]; h q[2]; h q[0]; diff --git a/examples/example6.qasm b/examples/example6.qasm index 5de75d1..ea9a59c 100644 --- a/examples/example6.qasm +++ b/examples/example6.qasm @@ -1,13 +1,15 @@ // example6.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[4]; creg c[2]; +// Begin g1y; h q[0]; h q[1]; h q[2]; h q[3]; +// End g1y; cx q[0],q[1]; h q[2]; h q[0]; diff --git a/examples/example7.qasm b/examples/example7.qasm index df620d1..7323a79 100644 --- a/examples/example7.qasm +++ b/examples/example7.qasm @@ -1,13 +1,15 @@ // example7.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[4]; creg c[2]; +// Begin g1y; h q[0]; h q[1]; h q[2]; h q[3]; +// End g1y; cx q[0],q[1]; h q[2]; h q[0]; diff --git a/examples/example8.qasm b/examples/example8.qasm index 3488d83..8e6746b 100644 --- a/examples/example8.qasm +++ b/examples/example8.qasm @@ -1,21 +1,27 @@ // example8.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[5]; creg c[5]; +// Begin g1y; h q[0]; h q[1]; h q[2]; h q[3]; h q[4]; +// End g1y; +// Begin g1y; x q[0]; x q[1]; x q[2]; x q[3]; x q[4]; +// End g1y; +// Begin qmeasy; measure q[0] -> c[0]; measure q[1] -> c[1]; measure q[2] -> c[2]; measure q[3] -> c[3]; measure q[4] -> c[4]; +// End qmeasy; diff --git a/examples/example9.qasm b/examples/example9.qasm index 1696e8a..db846fc 100644 --- a/examples/example9.qasm +++ b/examples/example9.qasm @@ -1,21 +1,27 @@ // example9.qasm; -// Compiled with g2q - v1.2.3; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[5]; creg c[5]; +// Begin g1y; h q[0]; h q[1]; h q[2]; h q[3]; h q[4]; +// End g1y; +// Begin g1y; x q[0]; x q[1]; x q[2]; x q[3]; x q[4]; +// End g1y; +// Begin qmeasy; measure q[0] -> c[0]; measure q[1] -> c[1]; measure q[2] -> c[2]; measure q[3] -> c[3]; measure q[4] -> c[4]; +// End qmeasy; diff --git a/g2q0.scm b/g2q0.scm index 1c69d82..685dd44 100644 --- a/g2q0.scm +++ b/g2q0.scm @@ -48,7 +48,8 @@ qcond1 qcond2 qvalid-conditional - swap)) + swap + qcomg)) ; qhead - Defines program name. @@ -300,11 +301,25 @@ ; - https://algassert.com/post/1717 ; (define (swap p_l1 p_y1 p_y2) - (display "// swap\n") + (qcomg "swap" 0) (qcx "cx" p_l1 p_y1 p_l1 p_y2) (qcx "cx" p_l1 p_y2 p_l1 p_y1) (qcx "cx" p_l1 p_y1 p_l1 p_y2) - (display "// end swap\n")) - + (qcomg "swap" 1)) +; qxomg - Comments for complex gates. Useful to identify various code sections +; when complex gates are compiled into QASM2 code. +; +; Arguments: +; - p_s: string (gate name). +; - p_v: value indicating the kind of gate comment. +; - 0: begin block. +; - 1: end block. +; +(define (qcomg p_s p_v) + (let ((s "")) + (cond ((eq? p_v 0)(set! s (strings-append (list (g2q-txt 6) "Begin " p_s ";") 0)))) + (cond ((eq? p_v 1)(set! s (strings-append (list (g2q-txt 6) "End " p_s ";") 0)))) + (display s) + (newline))) diff --git a/g2q1.scm b/g2q1.scm index ffffc23..b92e37e 100644 --- a/g2q1.scm +++ b/g2q1.scm @@ -43,7 +43,7 @@ ; g2q-version - Returns the current version of the compiler. ; (define (g2q-version) - (let ((res "g2q - v1.2.3")) + (let ((res "g2q - v1.2.4")) res)) @@ -75,7 +75,7 @@ ; g2q-select-qpu - Select qpu to be used. ; ; Output: -; - String containing the name of the selected qpu. DEfaults to qlib_simulator. +; - String containing the name of the selected qpu. Defaults to qlib_simulator. ; (define (g2q-select-qpu) (let ((res1 3) diff --git a/g2q2.scm b/g2q2.scm index 8a6c819..f503145 100644 --- a/g2q2.scm +++ b/g2q2.scm @@ -96,13 +96,13 @@ ; - p_y2: ordinal of the last qubit. ; (define (g1y p_n1 p_l1 p_y1 p_y2) - (display "// g1y\n") + (qcomg "g1y" 0) (let loop ((i p_y1)) (if (= i p_y2) (g1 p_n1 p_l1 i) (begin (g1 p_n1 p_l1 i) (loop (+ i 1))))) - (display "// end g1y\n")) + (qcomg "g1y" 1)) ; g1x - Repeats placement of gate p_n1 and group p_l1 by repeating the use of @@ -115,13 +115,13 @@ ; - p_m1: number of iterations. ; (define (g1x p_n1 p_l1 p_y1 p_m1) - (display "// g1x\n") + (qcomg "g1x" 0) (let loop ((i 1)) (if (= i p_m1) (g1 p_n1 p_l1 p_y1) (begin (g1 p_n1 p_l1 p_y1) (loop (+ i 1))))) - (display "// end g1x\n")) + (qcomg "g1x" 1)) ; g1xy - Repeats placement of gate p_n1 and group p_l1 by repeating the use of @@ -135,13 +135,13 @@ ; - p_x1: number if iterations that g1y will be repeated along x axis of sequence as a graph. ; (define (g1xy p_n1 p_l1 p_y1 p_y2 p_x1) - (display "// g1xy\n") + (qcomg "g1xy" 0) (let loop ((j 1)) (if (= j p_x1) (g1y p_n1 p_l1 p_y1 p_y2) (begin (g1y p_n1 p_l1 p_y1 p_y2) (loop (+ j 1))))) - (display "// end g1xy\n")) + (qcomg "g1xy" 1)) ; qmeasy - Performs measurements on group p_l1 to group p_l2 from p_y1 to p_y2. @@ -153,13 +153,13 @@ ; - p_y2: ordinal of the last qubit. ; (define (qmeasy p_l1 p_l2 p_y1 p_y2) - (display "// qmeasy\n") + (qcomg "qmeasy" 0) (let loop ((i p_y1)) (if (= i p_y2) (qmeas p_l1 p_y2 p_l2 p_y2) (begin (qmeas p_l1 i p_l2 i) (loop (+ i 1))))) - (display "// end qmeasy\n")) + (qcomg "qmeasy" 1)) ; cx - Gate cx. @@ -183,11 +183,11 @@ ; - p_y2: target qubit 2. ; (define (cz p_l1 p_y1 p_l2 p_y2) - (display "// cz\n") + (qcomg "cz" 0) (g1 "h" p_l1 p_y2) (cx p_l1 p_y1 p_l2 p_y2) (g1 "h" p_l2 p_y2) - (display "// end cz\n")) + (qcomg "cz" 1)) ; cz-fast - Gate cz, controlled y in fast form. @@ -211,11 +211,11 @@ ; - p_y2: target qubit 2. ; (define (cy p_l1 p_y1 p_l2 p_y2) - (display "// cy\n") + (qcomg "cy" 0) (g1 "sdg" p_l2 p_y2) (cx p_l1 p_y1 p_l2 p_y2) (g1 "s" p_l2 p_y2) - (display "// end cy\n")) + (qcomg "cy" 1)) ; cy-fast - Gate cy, controlled y in fast form. @@ -239,7 +239,7 @@ ; - p_y2: target qubit 2. ; (define (ch p_l1 p_y1 p_l2 p_y2) - (display "// ch\n") + (qcomg "ch" 0) (g1 "h" p_l2 p_y2) (g1 "sdg" p_l2 p_y2) (cx p_l1 p_y1 p_l2 p_y2) @@ -251,7 +251,7 @@ (g1 "s" p_l2 p_y2) (g1 "x" p_l2 p_y2) (g1 "s" p_l1 p_y1) - (display "// end ch\n")) + (qcomg "ch" 1)) ; ch-fast - Gate ch, controlled h in fast form. @@ -282,7 +282,7 @@ ; - Elementary gates for quantum computation - Barenco, Bennet et al. (1995) - https://arxiv.org/pdf/quant-ph/9503016.pdf ; (define (ccx p_l1 p_y1 p_l2 p_y2 p_l3 p_y3) - (display "// ccx\n") + (qcomg "ccx" 0) (g1 "h" p_l3 p_y3) (cx p_l2 p_y2 p_l3 p_y3) (g1 "tdg" p_l3 p_y3) @@ -298,7 +298,7 @@ (g1 "t" p_l1 p_y1) (g1 "tdg" p_l2 p_y2) (cx p_l1 p_y1 p_l2 p_y2) - (display "// end ccx\n")) + (qcomg "ccx" 1)) ; ccx-fast - Toffoli (AND) gate in fast form. @@ -392,13 +392,13 @@ ; - p_y2: qubit 2. ; (define (crz p_la p_l1 p_y1 p_l2 p_y2) - (display "// crz\n") + (qcomg "crz" 0) (let ((la (/ p_la 2))) (u1 la p_l2 p_y2) (cx p_l1 p_y1 p_l2 p_y2) (u1 (* -1.0 la) p_l2 p_y2) (cx p_l1 p_y1 p_l2 p_y2)) - (display "// end crz\n")) + (qcomg "crz" 1)) ; crz-fast - Gate crz, controlled rz expressed in fast form. @@ -424,14 +424,14 @@ ; - p_y2: qubit 2. ; (define (cu1 p_la p_l1 p_y1 p_l2 p_y2) - (display "// cu1\n") + (qcomg "cu1" 0) (let ((la (* p_la 0.5))) (u1 la p_l1 p_y1) (cx p_l1 p_y1 p_l2 p_y2) (u1 (* -1.0 la) p_l2 p_y2) (cx p_l1 p_y1 p_l2 p_y2) (u1 la p_l1 p_y1)) - (display "// end cu1\n")) + (qcomg "cu1" 1)) ; cu1-fast - Gate cu1, controlled phase rotation expressed in fast form. @@ -458,13 +458,13 @@ ; - p_y2: qubit 2. ; (define (cu3 p_la p_pa p_l1 p_y1 p_l2 p_y2) - (display "// cu3\n") + (qcomg "cu3" 0) (u1 (* (- p_la p_pa) 0.5) p_l2 p_y2) (cx p_l1 p_y1 p_l2 p_y2) (u3 (* (* p_la 0.5) -1.0) 0 (* (* (+ p_pa p_la) 0.5) -1.0) p_l2 p_y2) (cx p_l1 p_y1 p_l2 p_y2) (u3 (* p_la 0.5) p_pa 0 p_l2 p_y2) - (display "// end cu3\n")) + (qcomg "cu3" 1)) ; cu3-fast - Gate cu3, controlled U expressed in fast form. @@ -491,11 +491,11 @@ ; - p_y2: qubit number 2. ; (define (g1cxg1 p_n1 p_l1 p_y1 p_y2) - (display "// g1cxg1\n") + (qcomg "g1cxg1" 0) (g1 p_n1 p_l1 p_y2) (cx p_l1 p_y1 p_l1 p_y2) (g1 p_n1 p_l1 p_y2) - (display "// end g1cxg1\n")) + (qcomg "g1cxg1" 1)) ; qendc - Prints a message stating that compilation has ended. @@ -617,10 +617,10 @@ ; - |1> -> |0> ; (define (qcnot1 p_l2 p_y2 p_l1 p_y1) - (display "// qcnot1\n") + (qcomg "qcnot1" 0) (g1 "x" p_l1 p_y1) (cx p_l2 p_y2 p_l1 p_y1) - (display "// end qcnot1\n")) + (qcomg "qcnot1" 1)) ; qxor1 - A qcnot1 based XOR gate expressed atomically. @@ -643,11 +643,11 @@ ; - |10> -> |1> ; (define (qxor1 p_l1 p_y1 p_l2 p_y2 p_l3 p_y3 p_l4 p_y4) - (display "// qxor1\n") + (qcomg "qxor1" 0) (qcnot1 p_l2 p_y2 p_l1 p_y1) (qcnot1 p_l4 p_y4 p_l3 p_y3) (qcnot1 p_l3 p_y3 p_l1 p_y1) - (display "// end qxor1\n")) + (qcomg "qxor1" 1)) ; qfclvr - Find and construct label and value registers. @@ -747,8 +747,10 @@ (display (strings-append (list "swap " (qbgna p_l1 p_y1) "," (qbgna p_l1 p_y2) (g2q-txt 2)) 0))) -; qftyn - qft for n qubits in the range [p_l1[p_y1] : p_l2[p_y2]]. +; qftyn - Quantum Fourier Transformation for n qubits in the range +; [p_l1[p_y1] : p_l2[p_y2]]. ; +; Arguments: ; p_l1: quantum register name 1. ; p_y1: qubit 1, min limit of the range. ; p_l2: quantum register name 2. @@ -758,7 +760,7 @@ ; - https://quantum-computing.ibm.com/support/guides/quantum-algorithms-with-qiskit?page=5cbc5e2d74a4010049e1a2b0#qiskit-implementation ; (define (qftyn p_l1 p_y1 p_l2 p_y2) - (display "// qftyn\n") + (qcomg "qftyn" 0) (let ((i p_y1) (j 0)) (while (<= i p_y2) @@ -768,7 +770,8 @@ (cu1 (/ (qconst "Pi") (expt 2 (- j i))) p_l1 j p_l2 i) (set! j (+ j 1))) (set! i (+ i 1)))) - (display "// end qftyn\n")) + (qcomg "qftyn" 1)) + diff --git a/tests/test1.qasm b/tests/test1.qasm index b303708..3be6e68 100644 --- a/tests/test1.qasm +++ b/tests/test1.qasm @@ -1,5 +1,5 @@ // test1.qasm; -// Compiled with g2q - v1.2.0; +// Compiled with g2q - v1.2.4; OPENQASM 2.0; include "qelib1.inc"; qreg q[3]; @@ -13,19 +13,26 @@ t q[2]; sdg q[0]; tdg q[1]; reset q[0]; +// Begin swap; cx q[1],q[2]; cx q[2],q[1]; cx q[1],q[2]; +// End swap; swap q[0],q[1]; cx q[2],q[0]; +// Begin cy; sdg q[1]; cx q[0],q[1]; s q[1]; +// End cy; cy q[2],q[0]; +// Begin cz; h q[1]; cx q[0],q[1]; h q[1]; +// End cz; cz q[2],q[0]; +// Begin ch; h q[1]; sdg q[1]; cx q[0],q[1]; @@ -37,22 +44,28 @@ h q[1]; s q[1]; x q[1]; s q[0]; +// End ch; ch q[2],q[0]; u1(1.6) q[0]; u2(1.6,1.6) q[1]; u3(1.6,1.6,1.6) q[2]; +// Begin cu1; u1(0.8) q[2]; cx q[2],q[0]; u1(-0.8) q[0]; cx q[2],q[0]; u1(0.8) q[2]; +// End cu1; cu1(1.6) q[2],q[1]; +// Begin cu3; u1(0.0) q[2]; cx q[2],q[2]; u3(-0.8,0,-1.6) q[2]; cx q[2],q[2]; u3(0.8,1.6,0) q[2]; +// End cu3; cu3(1.6,1.6,1.6) q[2],q[0]; +// Begin ccx; h q[2]; cx q[1],q[2]; tdg q[2]; @@ -68,6 +81,7 @@ cx q[0],q[1]; t q[0]; tdg q[1]; cx q[0],q[1]; +// End ccx; ccx q[0],q[1],q[2]; u3(1.6,-1.570795,1.570795) q[1]; rx(1.570795) q[1]; @@ -75,18 +89,50 @@ u3(1.6,0,0) q[2]; ry(1.570795) q[2]; u1(1.6) q[3]; rz(1.570795) q[0]; +// Begin crz; u1(0.8) q[2]; cx q[1],q[2]; u1(-0.8) q[2]; cx q[1],q[2]; +// End crz; crz(1.570795) q[0],q[1]; if(q==1) y q[2]; if(q[2]!=1) y q[2]; +// Begin qftyn; +h q[0]; +// Begin cu1; +u1(0.7853975) q[1]; +cx q[1],q[0]; +u1(-0.7853975) q[0]; +cx q[1],q[0]; +u1(0.7853975) q[1]; +// End cu1; +// Begin cu1; +u1(0.39269875) q[2]; +cx q[2],q[0]; +u1(-0.39269875) q[0]; +cx q[2],q[0]; +u1(0.39269875) q[2]; +// End cu1; +h q[1]; +// Begin cu1; +u1(0.7853975) q[2]; +cx q[2],q[1]; +u1(-0.7853975) q[1]; +cx q[2],q[1]; +u1(0.7853975) q[2]; +// End cu1; +h q[2]; +// End qftyn; +// Begin g1y; barrier q[0]; barrier q[1]; barrier q[2]; +// End g1y; +// Begin qmeasy; measure q[0] -> c[0]; measure q[1] -> c[1]; measure q[2] -> c[2]; +// End qmeasy; // qdeclare qx-simulator error_model depolarizing_channel,0.001; // qdeclare qlib-simulator // Hello qlib-simulator; diff --git a/tests/test1.scm b/tests/test1.scm index 924eb99..1c3f72d 100644 --- a/tests/test1.scm +++ b/tests/test1.scm @@ -138,6 +138,8 @@ ; Conditionals. (qcond1 "==" q 1)(g1 "y" q 2) (qcond2 "!=" q 2 1)(g1 "y" q 2) + ; QFT + (qftyn q 0 q 2) ; Barrier and measure. (g1y "barrier" q 0 (- qn 1)) (qmeasy p_q p_c p_cnl p_cnh)