Quantum Computing Circuits
Transcription
Quantum Computing Circuits
Quantum Computing Circuits by José Luis Gómez-Muñoz http://homepage.cem.itesm.mx/lgomez/quantum/ jose.luis.gomez@itesm.mx With contributions by Francisco Delgado-Cepeda and Sergio E. Martínez-Casas Introduction This is a tutorial on the use of Quantum`Computing` Mathematica add-on to generate and work with Quantum Computing Circuits. Load the Package First load the Quantum`Computing` package. Write: Needs["Quantum`Computing`"]; then press at the same time the keys ˜-Û to evaluate. Mathematica will load the package. The semicolon prevents Mathematica from printing the welcome message: Needs@"Quantum`Computing`"D Quantum`Computing` Version 2.2.0. HJune 2010L A Mathematica package for Quantum Computing in Dirac bra−ket notation and plotting of quantum circuits by José Luis Gómez−Muñoz Execute SetComputingAliases@D in order to use the keyboard to enter quantum objects in Dirac's notation SetComputingAliases@D must be executed again in each new notebook that is created In order to use the keyboard to enter quantum objects write: SetComputingAliases[ ]; then press at the same time the keys ˜-Û to evaluate. The semicolon prevents Mathematica from printing the help message. Remember that SetComputingAliases[ ] must be evaluated again in each new notebook: SetComputingAliases@D; Simple Quantum Computing Circuits In order to plot a simple quantum circuit, press the keys: QuantumPlot[ [ESC]cnot[ESC] [ESC]on[ESC] [ESC]hg[ESC] ] Then press the [TAB] key several times to select the first "place holder" Ñ, and press the keys: 1[TAB]2[TAB]1 then press at the same time the keys ˜-Û to evaluate: 2 v7qcircuits.nb ˆ QuantumPlotB81< Aˆ2 E ⋅ ˆ1 F 1 2 Quantum Circuits can be used exactly the same way as the Dirac expressions that were used to generate them. As an example, write: QuantumEvaluate[ ] then copy-paste the circuit inside the brackets. Place the cursor to the right of the circuit and press the keys: [ESC]on[ESC] [ESC]qqket[ESC] Then press the [TAB] key one or several times to select the first "place holder" Ñ, and press the keys: 0[TAB]1[TAB]0[TAB]2 then press at the same time the keys ˜-Û to evaluate: 1 ⋅ QuantumEvaluateB 0ˆ1 , 0ˆ2 ]F 2 0ˆ1 , 0ˆ2 ] + 2 1ˆ1 , 1ˆ2 ] 2 It is the same result that is obtained with the original Dirac expression, press the keys: QuantumEvaluate[ [ESC]cnot[ESC] [ESC]on[ESC] [ESC]hg[ESC] [ESC]on[ESC][ESC]qqket[ESC] ] Then press the [TAB] key several times to select the first "place holder" Ñ, and press the keys: 1[TAB]2[TAB]1[TAB]0[TAB]1[TAB]0[TAB]2 then press at the same time the keys ˜-Û to evaluate: ˆ QuantumEvaluateB81< Aˆ2 E ⋅ ˆ1 ⋅ 0ˆ1 , 0ˆ2 ] 2 + 0ˆ1 , 0ˆ2 ]F 1ˆ1 , 1ˆ2 ] 2 In order to plot in 3D a simple quantum circuit, press the keys: QuantumPlot3D[ [ESC]cnot[ESC] [ESC]on[ESC] [ESC]hg[ESC] ] Then press the [TAB] key several times to select the first "place holder" Ñ, and press the keys: 1[TAB]2[TAB]1 then press at the same time the keys ˜-Û to evaluate: v7qcircuits.nb ˆ QuantumPlot3DB81< Aˆ2 E ⋅ ˆ1 F Quantum Circuits can be used exactly the same way as the Dirac expressions that were used to generate them. As an example, write: QuantumMatrixForm[ ] then copy-paste the circuit from the Mathematica output inside the brackets. Finally press at the same time the keys ˜-Û to evaluate: QuantumMatrixFormB 1 1 0 2 0 0 0 2 1 1 0 2 1 − 0 2 1 2 1 2 0 2 − 1 0 2 The same result is obtained from the original Dirac expression: F 3 4 v7qcircuits.nb ˆ QuantumMatrixFormB81< Aˆ2 E ⋅ ˆ1 F 1 1 0 2 0 2 1 0 0 1 0 2 1 − 0 2 1 2 1 2 1 − 0 2 0 2 Remember that QuantumMatrixForm is only for display purposes. For actual Mathematica calculations, QuantumMatrix must be used: ˆ QuantumMatrixB81< Aˆ2 E ⋅ ˆ1 F :: 1 1 , 0, 2 , 0>, :0, 2 1 1 , 0, 2 2 >, :0, 1 2 , 0, − 1 2 >, : 1 , 0, − 2 1 , 0>> 2 This is a Determinant, calculated from QuantumMatrix, not from QuantumMatrixForm ˆ DetBQuantumMatrixB81< Aˆ2 E ⋅ ˆ1 FF −1 This is a normal power of a Quantum Circuit. Press [ESC]po[ESC] for the normal power template and copy-paste the circuit from a previous Mathematica output. Write a 3 in the exponent: 3 1 F QuantumPlotB 2 1 2 This is a tensor power of a Quantum Circuit. Press [ESC]tpow[ESC] for the tensor power template and copy-paste the circuit from the Mathematica output. Write a 3 in the exponent: v7qcircuits.nb ⊗3 1 F QuantumPlotB 2 1 2 3 4 The option QuantumGateShiftingØFalse can be used to show the circuit in another, equivalent form (the arrow Ø can be entered by pressing [ESC]->[ESC]) ⊗3 1 QuantumPlotB , 2 QuantumGateShifting → FalseF 1 2 3 4 Here is another tensor power of the circuit, where the "exponent" is actually a list that defines the first qubit for each "factor": 5 6 v7qcircuits.nb ⊗ 81,3,5< 1 F QuantumPlotB 2 1 2 3 4 5 6 This is the same circuit obtained from the Dirac expression: v7qcircuits.nb ˆ QuantumPlotBJ81< Aˆ2 E ⋅ ˆ1 N ⊗ 81,3,5< F 1 2 3 4 5 6 This circuit is similar to the previous one, but it looks different with the default qubit order: 7 8 v7qcircuits.nb ˆ ˆ E ⋅ ˆ N QuantumPlotBJ81< A101 1 ⊗3 F 1 2 3 101 102 103 Using the option QubitList we can rearrange the circuit: v7qcircuits.nb ˆ ˆ E ⋅ ˆ N QuantumPlotBJ81< A101 1 ⊗3 , QubitList → 81, 101, 2, 102, 3, 103<F 1 101 2 102 3 103 The qubit labels can be hidden using the option QubitLabels: 9 10 v7qcircuits.nb ˆ ˆ E ⋅ ˆ N QuantumPlotBJ81< A101 1 ⊗3 , QubitList → 81, 101, 2, 102, 3, 103<, QubitLabels → FalseF In order to plot a quantum circuit with initial (nonentangled) values for the qubits, press the keys: QuantumPlot[ [ESC]cnot[ESC] [ESC]on[ESC] [ESC]hg[ESC] [ESC]on[ESC][ESC]qqket[ESC] ] Then press the [TAB] key several times to select the first "place holder" Ñ, and press the keys: 1[TAB]2[TAB]1[TAB]0[TAB]1[TAB]0[TAB]2 then press at the same time the keys ˜-Û to evaluate: ˆ QuantumPlotB81< Aˆ2 E ⋅ ˆ1 ⋅ 0ˆ1 , 0ˆ2 ]F 1 0\ 2 0\ Qubit labels and initial qubit values do not need to be numbers: v7qcircuits.nb ˆ ˆF⋅ˆ ⋅ QuantumPlotB8q1< Bq2 q1 ˆ , y ˆ ^F xq1 q2 q1 x\ q2 y\ Use the option QubitLabels->False in order to have the plot without the qubit labels: ˆ ˆF⋅ˆ ⋅ QuantumPlotB8q1< Bq2 q1 x\ ˆ , y ˆ ^, QubitLabels → FalseF xq1 q2 y\ You can also have the Dirac notation for the circuit: ˆ QuantumEvaluateB81< Aˆ2 E ⋅ ˆ1 F 0ˆ1 , 0ˆ2 ] ⋅ Y0ˆ1 , 0ˆ2 1ˆ1 , 1ˆ2 ] ⋅ Y0ˆ1 , 0ˆ2 + 2 0ˆ1 , 1ˆ2 ] ⋅ Y0ˆ1 , 1ˆ2 + 2 0ˆ1 , 0ˆ2 ] ⋅ Y1ˆ1 , 0ˆ2 2 1ˆ1 , 1ˆ2 ] ⋅ Y1ˆ1 , 0ˆ2 − 2 1ˆ1 , 0ˆ2 ] ⋅ Y0ˆ1 , 1ˆ2 + 2 0ˆ1 , 1ˆ2 ] ⋅ Y1ˆ1 , 1ˆ2 + 2 − 1ˆ1 , 0ˆ2 ] ⋅ Y1ˆ1 , 1ˆ2 2 2 TraditionalForm gives a format closer to the the format used in papers and textbooks: ˆ TraditionalFormBQuantumEvaluateB81< Aˆ2 E ⋅ ˆ1 FF 00\X00 2 + 11\X00 2 + 01\X01 2 + 10\X01 2 + 00\X10 2 - 11\X10 2 + 01\X11 2 - 10\X11 2 + 11 12 v7qcircuits.nb In order to plot the circuit of a tensor product of FREDKIN gates, press the keys: QuantumPlot[ [ESC]tprod[ESC] ] Then press the [TAB] key one or more times to select the first "place holder" Ñ, and press the keys: j[TAB]1[TAB]3[TAB] Then press the keys: [ESC]fred[ESC] Then press the [TAB] key one or more times to select the first "place holder" Ñ, and press the keys: j [TAB] j+1[TAB]j+2 then press at the same time the keys ˜-Û to evaluate: 3 QuantumPlotB ⊗ ˆj,j+1ˆ ,j+2ˆ F j=1 1 2 3 4 5 Use the option QubitList in order to have the plot with some (or all) wires in a differente order. Press the keys [ESC]qb[ESC] in order to enter the qubit template: v7qcircuits.nb ˆ ˆ 3 QuantumPlotB ⊗ ˆj,j+1ˆ ,j+2ˆ , QubitList → :4, 3>F j=1 4 3 1 2 5 ˆ ˆ for Plotting Quantum Gates in the Same Column The Notation :q1 ,q2> Notice that the three Hadamard gates are not in a column: ˆ QuantumPlotBIˆ1 M ⊗ ⋅ 81< Aˆ2 EF 3 1 2 3 Notice that the Hadamard gates are not in a column: 13 14 v7qcircuits.nb ˆ QuantumPlotBIˆ1 M ⊗ ⋅ 81< Aˆ2 E, QuantumGateShifting → FalseF 3 1 2 3 There is a notation that allows to have all the gates in the same column. Press the keys [ESC]hggg[ESC] for the template: ˆ QuantumPlotB:1ˆ,2ˆ,3ˆ> ⋅ 81< Aˆ2 EF 1 2 3 These two notations evaluate to the same Dirac expression, the only diference is whether gates will be plotted in the same column or not in a quantum circuit: 3 QuantumEvaluateB:1ˆ,2ˆ,3ˆ> F QuantumEvaluateBIˆ1 M ⊗ F True There is a notation that allows to have all the gates in the same column. Press the keys [ESC]xggg[ESC] for the template: v7qcircuits.nb 15 ˆ QuantumPlotB:1ˆ,2ˆ,3ˆ> ⋅ 81< Aˆ2 EF 1 2 3 These two notations evaluate to the same Dirac expression, the only diference is whether gates will be plotted in the same column or not in a quantum circuit: QuantumEvaluateB:1ˆ,2ˆ,3ˆ> F QuantumEvaluateBIˆ1 M ⊗ F 3 True Textbook Examples It is a textbook exercise to show that the following circuit is equivalente to a Toffoli (controlled-controlled-not) gate. Press [ESC]her[ESC] for the "Hermitian Conjugate" HL† template: ˆ ˆ QuantumPlotBˆ1 ⋅ ˆ2 ⋅ 81< Aˆ2 E ⋅ Iˆ2 M ⋅ 81< Aˆ2 E ⋅ Iˆ2 M ⋅ ˆ3 ⋅ ˆ3 ⋅ ˆ † ˆ † ˆ ˆ 81< Aˆ3 E ⋅ Iˆ3 M ⋅ 82< Aˆ3 E ⋅ ˆ3 ⋅ 81< Aˆ3 E ⋅ Iˆ3 M ⋅ 82< Aˆ3 E ⋅ ˆ3 F † 1 2 3 † † † † † Use the option ImageSize Æ {250, Automatic} to have a smaller version of the circuit. Press the keys [ESC]->[ESC] ("Escape","Minus","Grater Than","Escape") in order to enter the arrow Ø 16 v7qcircuits.nb ˆ ˆ ˆ QuantumPlotBˆ1 ⋅ ˆ2 ⋅ 81< Aˆ2 E ⋅ Iˆ2 M ⋅ 81< Aˆ2 E ⋅ Iˆ2 M ⋅ ˆ3 ⋅ ˆ3 ⋅ 81< Aˆ3 E ⋅ Iˆ3 M ⋅ ˆ † ˆ † † ˆ 82< Aˆ3 E ⋅ ˆ3 ⋅ 81< Aˆ3 E ⋅ Iˆ3 M ⋅ 82< Aˆ3 E ⋅ ˆ3 , ImageSize → 8250, Automatic<F † 1 2 3 † † † † This is the Truth-Table of the circuit (write QuantumTableForm[ ] and copy-paste the circuit from the previous calculation inside the brackets). Notice that only the two last rows of the table are different from the table of an identity: 1 QuantumTableFormB 2 † 3 † Input Output 0 0ˆ1 , 0ˆ2 , 0ˆ3 ] 0ˆ1 , 0ˆ2 , 0ˆ3 ] 1 0ˆ1 , 0ˆ2 , 1ˆ3 ] 0ˆ1 , 0ˆ2 , 1ˆ3 ] 2 0ˆ1 , 1ˆ2 , 0ˆ3 ] 0ˆ1 , 1ˆ2 , 0ˆ3 ] 3 0ˆ1 , 1ˆ2 , 1ˆ3 ] 0ˆ1 , 1ˆ2 , 1ˆ3 ] 4 1ˆ1 , 0ˆ2 , 0ˆ3 ] 1ˆ1 , 0ˆ2 , 0ˆ3 ] 5 1ˆ1 , 1ˆ3 ] 1ˆ1 , 0ˆ2 , 1ˆ3 ] 6 1ˆ1 , 1ˆ2 , 0ˆ3 ] 1ˆ1 , 1ˆ2 , 1ˆ3 ] 7 1ˆ1 , 1ˆ2 , 1ˆ3 ] 1ˆ1 , 1ˆ2 , 0ˆ3 ] 0ˆ2 , † † F We can see that is identical the Truth-Table of the Toffoli gate: QuantumTableForm[ [ESC]toff[ESC] ] Then press the [TAB] key one or more times to select the first "place holder" Ñ, and press the keys: 1 [TAB] 2 [TAB] 3 then press at the same time the keys ˜-Û to evaluate. Notice that only the two last rows of the table are different from the table of an identity: QuantumTableFormAˆ1,2ˆ,3ˆ E Input Output 0 0ˆ1 , 0ˆ2 , 0ˆ3 ] 0ˆ1 , 0ˆ2 , 0ˆ3 ] 1 0ˆ1 , 1ˆ3 ] 0ˆ1 , 0ˆ2 , 1ˆ3 ] 2 0ˆ1 , 1ˆ2 , 0ˆ3 ] 0ˆ1 , 1ˆ2 , 0ˆ3 ] 3 0ˆ1 , 1ˆ2 , 1ˆ3 ] 0ˆ1 , 1ˆ2 , 1ˆ3 ] 4 1ˆ1 , 0ˆ2 , 0ˆ3 ] 1ˆ1 , 0ˆ2 , 0ˆ3 ] 5 1ˆ1 , 0ˆ2 , 1ˆ3 ] 1ˆ1 , 0ˆ2 , 1ˆ3 ] 6 1ˆ1 , 1ˆ2 , 0ˆ3 ] 1ˆ1 , 1ˆ2 , 1ˆ3 ] 7 1ˆ1 , 1ˆ2 , 1ˆ3 ] 1ˆ1 , 1ˆ2 , 0ˆ3 ] 0ˆ2 , v7qcircuits.nb 17 Another textbook example. In order to enter the "controlled-controlled not" gates press the keys [ESC]ccnot[ESC]. For the "tensor product" press the keys [ESC]tprod[ESC]. For an arbitrary controlled gate press the keys [ESC]cgate[ESC]. For the arbitrary gate w, press the keys [ESC]qg[ESC] SetQuantumGate@w, 1D; QuantumPlotB ˆ ˆ 81,2< Aˆ6 E ⋅ 3 ˆ ˆ ⊗ 8j+2,j+5<Bj+6ˆ F j=1 ˆ ˆE⋅ ⋅ 89< Aw10 3 ˆ ˆ ˆ F ⊗ 86−j,9−j<B10−j j=1 ˆ ˆ ⋅ 81,2< Aˆ6 EF 1 2 3 4 5 6 7 8 9 10 w Quantum Register Notation Press [ESC]hn[ESC] [TAB] [ESC]qr[ESC] to use the "quantum register" template in the Hadamard gate: 18 v7qcircuits.nb QuantumPlotA@3,"q"D E q1 q2 q3 Press [ESC]hn[ESC] [TAB] [ESC]qr[ESC] to use the "quantum register" template in the Hadamard gate: v7qcircuits.nb 19 QuantumPlotA@10,22,3,"Q"D E Q10 Q13 Q16 Q19 Q22 Powers of Quantum Gates in Circuits The power of a gate is by default shown as a single block. Press the keys [ESC]qg[ESC] in order to obtain the gate template ˆ SetQuantumGate@w, 1D; QuantumPlotAwˆa 4 E a w4 Integer powers of gates are shown as several gates if the option GatePowers is set to True. Press the keys [ESC]qg[ESC] in order to obtain the gate template ˆ 20 v7qcircuits.nb SetQuantumGate@w, 1D; QuantumPlotAwˆa 4 , QuantumGatePowers → FalseE a w w w w Gates of two qubits Here is a gate of two qubits. Press the keys [ESC]qqg[ESC] in order to obtain the gate template ˆ,ˆ SetQuantumGate@mygate, 2D; QuantumPlotAmygateˆa,bˆ E a b This is a controlled gate. Press the keys [ESC]cgate[ESC] in order to obtain the controlled gate template. Press the keys [ESC]qqg[ESC] in order to obtain the gate template ˆ,ˆ v7qcircuits.nb SetQuantumGate@mygate, 2D; QuantumPlotB8â< Amygateˆb,cˆ EF a b c This is a controlled gate. Press the keys [ESC]ccgate[ESC] in order to obtain the controlled-controlled gate template ˆ ˆ 8,< @D. Press the keys [ESC]qqg[ESC] in order to obtain the gate template ˆ,ˆ 21 22 v7qcircuits.nb SetQuantumGate@mygate, 2D; ˆ :â,b> QuantumPlotB Amygateˆc,dˆ EF a b c d This circuit shows controlled gates of two qbits, powers of gates, and initial values for some of the qubits: SetQuantumGate@u, 2D; QuantumPlotB ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ j2 j2 j2 j1 j1 j0 ˆ ˆ ˆ ˆ ˆ E ⋅ 8j1< Au ˆ ˆ 2 E ⋅ 8j0< Au ˆ ˆ 4 E ⋅ ˆ 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0,s1 s0,s1 ˆ ˆ ˆ 4E ⋅ ˆ ⋅ ˆ ⋅ ˆ ⋅ 8j0< Aus0 ,s1 j2 j1 j0 0\ 0\ 0\ j0 j1 ˆ , 0 ˆ , 0 ˆ ^, QuantumGateShifting → FalseF 0j0 j1 j2 j2 s0 s1 Same circuit with QuantumGateShiftingØFalse AND the use of the template 9ˆ,ˆ,ˆ= for plotting the three Hadamard gates in the same column, see the gates next to the ket and compare with the circuit above. The 9ˆ,ˆ,ˆ= template can be entered y pressing the keys [ESC]hggg[ESC] SetQuantumGate@u, 2D; QuantumPlotB ˆ ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ 8j1< Au ˆ ˆ 2 E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 s0,s1 ˆ ˆ ˆ 4E ⋅ ˆ ˆ ˆ ⋅ 8j0< Aus0 ,s1 :j0,j1,j2> 0\ 0\ 0\ j0 j1 j2 ˆ , 0 ˆ , 0 ˆ ^, QuantumGateShifting → FalseF 0j0 j1 j2 s0 s1 Same circuit with QuantumGatePowersØFalse SetQuantumGate@u, 2D; QuantumPlotB ˆ ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ 8j1< Au ˆ ˆ 2 E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 s0,s1 ˆ ˆ ˆ 4E ⋅ ˆ ⋅ ˆ ⋅ ˆ ⋅ 8j0< Aus0 ,s1 j2 j1 j0 0\ 0\ 0\ j0 j1 j2 s0 s1 ˆ , 0 ˆ , 0 ˆ ^, QuantumGatePowers → FalseF 0j0 j1 j2 v7qcircuits.nb 25 Same circuit with qubit order specified by QubitList SetQuantumGate@u, 2D; QuantumPlotB ˆ ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ 8j1< Au ˆ ˆ 2 E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 s0,s1 ˆ ˆ ˆ ˆ ˆ ˆ , 0 ˆ , 0 ˆ ^, QubitList → :s0, s1, j0, j1, j2>F 0j0 j1 j2 ˆ ˆ ˆ 4E ⋅ ˆ ⋅ ˆ ⋅ ˆ ⋅ 8j0< Aus0 ,s1 j2 j1 j0 s0 s1 0\ 0\ 0\ j0 j1 j2 Measuring Meters Next circuit shows how plot Measuring Meters in a quantum circuit. Notice that QubitMeasurement has not the same syntaxis as a quantum gate: SetQuantumGate@u, 2D; QuantumPlotBQubitMeasurementB ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 ˆ ˆ ˆ ˆ 2 E ⋅ 8j0< Au ˆ ˆ 4 E ⋅ ˆ ⋅ ˆ ⋅ ˆ ⋅ 8j1< Aus0 ,s1 s0,s1 j2 j1 j0 0\ 0\ 0\ j0 j1 j2 ˆ ˆ ˆ ˆ , 0 ˆ , 0 ˆ ^, :j0, j1, j2>FF 0j0 j1 j2 s0 s1 Same circuit with QuantumGateShiftingØFalse AND the use of the template 9ˆ,ˆ,ˆ= for plotting the three Hadamard gates in the same column, see the gates next to the ket and compare with the circuit above. The 9ˆ,ˆ,ˆ= template can be entered y pressing the keys [ESC]hggg[ESC] 26 v7qcircuits.nb SetQuantumGate@u, 2D; QuantumPlotBQubitMeasurementB ˆ ˆ ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ 8j1< Au ˆ ˆ 2 E ⋅ 8j0< Au ˆ ˆ 4 E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 s0,s1 s0,s1 ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ 0j0 , 0j1 , 0j2 ^, :j0, j1, j2>F, QuantumGateShifting → FalseF :j0,j1,j2> ⋅ 0\ 0\ 0\ j0 j1 j2 s0 s1 Controlled gates commute with measurements in their control qubit. This means these two circuits are equivalent: ˆ :QuantumPlotB QubitMeasurementB81< Aˆ2 E ⋅ ˆ1 ⋅ ˆ QuantumPlotB 81< Aˆ2 E ⋅ QubitMeasurementBˆ1 ⋅ ˆ ,1ˆ,2ˆ ], 81<F F, ˆ ,1ˆ,2ˆ ], 81<F F> 1 : , 2 1 > 2 It can be seen that both circuits are equivalent by writting QuantumEvaluate instead of QuantumPlot: v7qcircuits.nb ˆ :QuantumEvaluateB QubitMeasurementB81< Aˆ2 E ⋅ ˆ1 ⋅ ˆ QuantumEvaluateB 81< Aˆ2 E ⋅ QubitMeasurementBˆ1 ⋅ Probability Measurement : 1 2 990ˆ1 == 1 2 991ˆ1 == 0ˆ ] 0ˆ1 ] ⊗ 2 State 991ˆ1 == 0ˆ ] 2 + 1ˆ ] + 1ˆ ] 2 2 0ˆ ] 2 , 2 2 2 1ˆ1 ] ⊗ − Probability Measurement 2 2 Probability Measurement 1 2 1ˆ ] 2 0ˆ ] 1ˆ1 ] ⊗ − 0ˆ1 ] ⊗ + 2 2 State 990ˆ1 == ˆ ,1ˆ,2ˆ ], 81<F F> State Probability Measurement 1 2 ˆ ,1ˆ,2ˆ ], 81<F F, + 2 1ˆ ] > 2 2 State Use of Circuit Options SetQuantumGate@u, 2D; QuantumPlotB ˆ ˆ ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E 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ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 ˆ ˆ ˆ ˆ 2 E ⋅ 8j0< Au ˆ ˆ 4 E ⋅ ˆ ⋅ ˆ ⋅ ˆ ⋅ 8j1< Aus0 ,s1 s0,s1 j2 j1 j0 ˆ , 0 ˆ , 0 ˆ ^, 0j0 j1 j2 QuantumBackground → Black, QuantumGateStyle → Directive@Glow@BlueDD, QuantumConnectionStyle −> Directive@Glow@YellowDD, QuantumWireStyle → Directive@Glow@Darker@MagentaDDD, QuantumControlStyle → Directive@Glow@GreenDD, QuantumTextStyle → Red F SetQuantumGate@u, 2D; QuantumPlot3DB ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 ˆ ˆ ˆ ˆ 2 E ⋅ 8j0< Au ˆ ˆ 4 E ⋅ ˆ ⋅ ˆ ⋅ ˆ ⋅ 8j1< Aus0 ,s1 s0,s1 j2 j1 j0 ˆ , 0 ˆ , 0 ˆ ^, 0j0 j1 j2 QuantumBackground → Black, QuantumGateStyle → Directive@Glow@BlueDD, QuantumConnectionStyle −> Directive@Glow@YellowDD, QuantumWireStyle → Directive@Glow@Darker@MagentaDDD, QuantumControlStyle → Directive@Glow@GreenDD, QuantumTextStyle → Red, Lighting → None F 29 30 v7qcircuits.nb QuantumPlot3DB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 , QuantumBackground → Black, QuantumGateStyle → Directive@Glow@BlueDD, QuantumConnectionStyle −> Directive@Glow@MagentaDD, QuantumControlStyle → Directive@Glow@YellowDD, QuantumNotStyle → Directive@Glow@BrownDD, QuantumWireStyle → Directive@Glow@RedDD, QuantumTextStyle → Green, Lighting → NoneF SetQuantumGate@u, 2D; QuantumPlot3DB ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 ˆ ˆ ˆ ˆ 2 E ⋅ 8j0< Au ˆ ˆ 4 E ⋅ ˆ ⋅ ˆ ⋅ ˆ ⋅ 8j1< Aus0 ,s1 s0,s1 j2 j1 j0 ˆ , 0 ˆ , 0 ˆ ^, 0j0 j1 j2 QuantumConnectionStyle → Brown, QuantumGateStyle → Directive@LightYellow, EdgeForm@GreenDD, QuantumWireStyle → Directive@Blue, ThickD, QuantumBackground → LightGreen, QuantumTextStyle → Directive@Red, FontWeight → Bold, FontFamily → "Verdana"D F v7qcircuits.nb 31 SetQuantumGate@u, 2D; QuantumPlot3DB ˆ ˆ ˆ ˆ ˆ ⋅ 8j1< B ˆ F ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j0< B ˆ F ⋅ ˆ ⋅ 8j2< Au ˆ ˆ E ⋅ j2 j2 j2 j1 j1 j0 s0,s1 ˆ ˆ ˆ ˆ 2 E ⋅ 8j0< Au ˆ ˆ 4 E ⋅ ˆ ⋅ ˆ ⋅ ˆ ⋅ 8j1< Aus0 ,s1 s0,s1 j2 j1 j0 ˆ , 0 ˆ , 0 ˆ ^, 0j0 j1 j2 QuantumTextStyle → Directive@Black, Medium, FontWeight → BoldD, QuantumWireStyle → Directive@Red, ThickD, QuantumBackground → Yellow F QuantumPlot3DB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 , QuantumSwapStyle → Directive@Red, Opacity@0.4DD, QuantumGateStyle → Directive@Opacity@0.4DD F QuantumPlot has its own options, plus all the options of the standard Mathematica commands Plot and Plot3D. Following commands show a list of the options that are exclusive of QuantumPlot, together with their default value: 32 v7qcircuits.nb Select@Options@QuantumPlotD, Characters@SymbolName@@@1DDDD@@1DD "Q" &D :QubitList → 8<, QubitLabels → True, QuantumGatePowers → True, QuantumGateShifting → True, QuantumBackground → RGBColor@0.9, 0.9, 0.9D, QuantumMeterStyle → 4 DirectiveBRGBColorB0, 0, F, Thickness@0.003D, Arrowheads@SmallDF, 9 4 QuantumWireStyle → DirectiveBRGBColorB0, 0, F, Thickness@0.006DF, 9 4 QuantumConnectionStyle → DirectiveBRGBColorB , 0, 0F, Thickness@0.004DF, 9 2 QuantumNotStyle → DirectiveBRGBColorB0, , 0F, Thickness@0.004DF, 3 QuantumControlStyle → 4 DirectiveBRGBColor@0, 1, 0D, EdgeFormB:RGBColorB , 0, 0F, Thickness@0.006D>FF, 9 2 2 QuantumSwapStyle → DirectiveBRGBColorB , 0, F, Thickness@0.006DF, 3 3 QuantumGateStyle → 4 DirectiveBRGBColor@1, 1, 0.85D, EdgeFormB:Thickness@0.006D, RGBColorB , 0, 0F>FF, 9 4 QuantumTextStyle → DirectiveBSmall, RGBColorB0, 0, F, FontFamily → VerdanaF, 9 4 QuantumVerticalTextStyle → DirectiveBRGBColorB , 0, 0F, FontFamily → VerdanaF, 9 QuantumPlot3D → False> Use of Standard Graphics Options Standard Mathematica Graphics options can be used in a Quantum Circuit using the syntax: QuantumPlot[expression,options] QuantumPlotB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 , Background → Yellow, Frame → True, FrameStyle → BlueF 1 -1.0 -1.5 2 -2.0 -2.5 3 -3.0 0 1 2 3 4 v7qcircuits.nb Standard Mathematica Graphics3D options can be used in a Quantum Circuit using the syntax: QuantumPlot3D[expression,options] QuantumPlot3DB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 , Background → Yellow, Boxed → True, Axes → TrueF Standard Mathematica Graphics options can be used in a Quantum Circuit using the syntax: QuantumPlot[expression,options] QuantumPlotB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 , Background → LightPink, Frame → True, FrameTicks → None, FrameStyle → ThickF 1 2 3 Standard Mathematica primitives can be combined Quantum Circuit using the syntax: Show[QuantumPlot[expression],Graphics[{primitives}],options] 33 34 v7qcircuits.nb ShowBQuantumPlotB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 F, Graphics@8Text@Style@"My First Circuit", LargeD, 82, − 0.4<D<D, Frame → FalseF My First Circuit 1 2 3 Standard Mathematica primitives can be combined Quantum Circuit using the syntax: Show[QuantumPlot[expression],Graphics[{primitives}],options] ShowB QuantumPlotB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 F, Graphics@8 Arrow@882.5, − 1.3<, 82.1, − 1.1<<D, Text@Style@"control", LargeD, 82.5, − 1.3<, 8− 1.1, 0<D <D, Frame → TrueF 1 -1.0 control -1.5 2 -2.0 -2.5 3 -3.0 0 1 2 3 4 Standard Mathematica primitives can be combined Quantum Circuit using the syntax: Show[QuantumPlot[expression],Graphics[{primitives}],options] v7qcircuits.nb ShowB QuantumPlotB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 F, Graphics@8 Arrow@882.5, − 1.3<, 82.1, − 1.1<<D, Text@Style@"control", LargeD, 82.5, − 1.3<, 8− 1.1, 0<D <D, Frame → FalseF 1 control 2 3 Standard Mathematica primitives can be combined Quantum Circuit using the syntax: Show[QuantumPlot[expression],Graphics[{primitives}],options] 35 36 v7qcircuits.nb ShowB QuantumPlotB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 F, Graphics@8 Arrow@882.5, − 1.3<, 82.1, − 1.1<<D, Text@Style@"control", LargeD, 82.5, − 1.3<, 8− 1.1, 0<D <D, Frame → False, ImageSize → 8600, Automatic<F 1 control 2 3 Standard Mathematica primitives can be combined Quantum Circuit using the syntax: Show[QuantumPlot3D[expression],Graphics3D[{primitives}],options] v7qcircuits.nb ShowB QuantumPlot3DB ˆ ˆ2,3ˆ ⋅ 81< Aˆ2 E ⋅ ˆ1 F, Graphics3D@8 Arrow@882.6, 0.3, 0<, 82.1, − 0.9, 0<<D, Text@Style@"control", LargeD, 82.6, 0.3, 0<, 8− 1.1, 0<D <DF by José Luis Gómez-Muñoz http://homepage.cem.itesm.mx/lgomez/quantum/ jose.luis.gomez@itesm.mx 37