1- using Printf
2- using GroverAlgorithm
3- using ITensors, ITensorMPS
4-
1+ # # Toffoli Gate Example
52# Here we define the Toffoli gate (CCNOT) using the GroverAlgorithm package
63# This is an example of how to use the package.
74# Toffoli gate is available in ITensorMPS.jl as a built-in gate.
85# Let's create a Toffoli gate and check its action on the basis states.
6+
7+ # ## Using the built-in Toffoli gate
8+ # In ITensorMPS.jl, the Toffoli gate is available as a built-in three-qubit gate. We can simply add it to our quantum circuit and execute it.
9+
10+ using Printf
11+ using GroverAlgorithm
12+ using ITensors, ITensorMPS
13+
914circuit = QuantumCircuit (3 )
1015add_gate! (circuit, ThreeQubitGate (1 , 2 , 3 , :Toffoli ))
1116
@@ -33,10 +38,9 @@ function test_actions(circuit)
3338 end
3439end
3540
36- circuit = QuantumCircuit (3 )
37- add_gate! (circuit, ThreeQubitGate (1 , 2 , 3 , :Toffoli ))
3841test_actions (circuit)
3942
43+ # ## Toffoli gate decomposition
4044# Then, Lets's construct the Toffoli gate using the standard decomposition into CNOT and single-qubit gates,
4145# and verify that it produces the same results as the built-in Toffoli gate.
4246function toffoli_decomposed (circuit)
@@ -60,6 +64,8 @@ function toffoli_decomposed(circuit)
6064end
6165circuit_decomposed = QuantumCircuit (3 )
6266toffoli_decomposed (circuit_decomposed)
63- test_actions (circuit_decomposed)
6467
6568tp = to_tikz_picture (circuit_decomposed)
69+
70+ # Let's test the action of the decomposed Toffoli gate on the basis states to verify that it behaves the same as the built-in Toffoli gate.
71+ test_actions (circuit_decomposed)
0 commit comments