Skip to content

Commit 01d2321

Browse files
committed
added toffoli as an example
1 parent eeb0ebd commit 01d2321

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

example/makedocs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Pkg.activate("../")
44
using Literate, GroverAlgorithm, ITensors, ITensorMPS
55

66
base_dir = pkgdir(GroverAlgorithm)
7-
output_dir = joinpath(base_dir, "docs", "src", "examples")
7+
output_dir = joinpath(base_dir, "docs", "src", "example")
88
mkpath(output_dir)
99

1010
Literate.markdown("toffoli.jl", output_dir; documenter=true)

example/toffoli.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
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+
914
circuit = QuantumCircuit(3)
1015
add_gate!(circuit, ThreeQubitGate(1, 2, 3, :Toffoli))
1116

@@ -33,10 +38,9 @@ function test_actions(circuit)
3338
end
3439
end
3540

36-
circuit = QuantumCircuit(3)
37-
add_gate!(circuit, ThreeQubitGate(1, 2, 3, :Toffoli))
3841
test_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.
4246
function toffoli_decomposed(circuit)
@@ -60,6 +64,8 @@ function toffoli_decomposed(circuit)
6064
end
6165
circuit_decomposed = QuantumCircuit(3)
6266
toffoli_decomposed(circuit_decomposed)
63-
test_actions(circuit_decomposed)
6467

6568
tp = 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

Comments
 (0)