Skip to content

Commit

Permalink
Merge pull request #69 from harshangrjn/minor_updates
Browse files Browse the repository at this point in the history
Updates: QFT3 added and minor bug fixes
  • Loading branch information
harshangrjn authored Feb 26, 2024
2 parents 946f9c0 + 86cadae commit 5734d7e
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 179 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
QuantumCircuitOpt.jl Change Log
===============================

### v0.5.9
- Catch error in `data.jl` if `set_cnot_lower_bound` > `maximum_depth`
- Feasibility switching warning moved to the correct condition in objective.jl
- Renamed function `get_full_sized_gate` -> `get_unitary`
- Added 3-qubit `QFT3Gate` to gates.jl
- Added `QFT3` circuit using controlled-phase gates in examples
- Updated docs and unit tests to reflect above changes

### v0.5.8
- Readme update for dark/light theme logo display
- Fixed Docs compile issue
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumCircuitOpt"
uuid = "88128e30-b60a-4e54-ab02-1050a5f92a36"
authors = ["Harsha Nagarajan"]
version = "0.5.8"
version = "0.5.9"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
12 changes: 6 additions & 6 deletions examples/2qubit_gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function hadamard()
"num_qubits" => 2,
"maximum_depth" => 3,
"elementary_gates" => ["U3_1", "CNot_1_2", "Identity"],
"target_gate" => QCOpt.get_full_sized_gate("H_1", 2),
"target_gate" => QCOpt.get_unitary("H_1", 2),
"objective" => "minimize_depth",
"decomposition_type" => "exact_optimal",

Expand Down Expand Up @@ -152,7 +152,7 @@ function S_using_U3()
"num_qubits" => 2,
"maximum_depth" => 3,
"elementary_gates" => ["U3_1", "U3_2", "CNot_1_2", "Identity"],
"target_gate" => QCOpt.get_full_sized_gate("S_1", 2),
"target_gate" => QCOpt.get_unitary("S_1", 2),
"objective" => "minimize_depth",
"decomposition_type" => "exact_optimal",

Expand Down Expand Up @@ -378,9 +378,9 @@ end
function GR_using_R()
println(">>>>> GRGate testing <<<<<")

GR1 = QCOpt.get_full_sized_gate("GR", 2; angle =/6, π/3])
# GR2 = QCOpt.get_full_sized_gate("GR", 2; angle = [π/3, π/6])
CNot_1_2 = QCOpt.get_full_sized_gate("CNot_1_2", 2)
GR1 = QCOpt.get_unitary("GR", 2; angle =/6, π/3])
# GR2 = QCOpt.get_unitary("GR", 2; angle = [π/3, π/6])
CNot_1_2 = QCOpt.get_unitary("CNot_1_2", 2)
T = QCOpt.round_complex_values(GR1 * CNot_1_2)

return Dict{String, Any}(
Expand All @@ -405,7 +405,7 @@ function X_using_GR()
"num_qubits" => 2,
"maximum_depth" => 5,
"elementary_gates" => ["GR", "R_1", "R_2", "CZ_1_2", "Identity"],
"target_gate" => QCOpt.get_full_sized_gate("X_1", 2),
"target_gate" => QCOpt.get_unitary("X_1", 2),
"objective" => "minimize_depth",
"decomposition_type" => "exact_optimal",
"GR_θ_discretization" => [-π, -π/2, 0, π/2, π],
Expand Down
66 changes: 36 additions & 30 deletions examples/3qubit_gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ function RX_on_q3()
println(">>>>> RX Gate on third qubit using U3Gate <<<<<")

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 3,
"elementary_gates" => ["U3_3", "Identity"],
Expand Down Expand Up @@ -42,7 +41,6 @@ function toffoli()
println(">>>>> Toffoli gate <<<<<")

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 15,
"elementary_gates" => ["T_1", "T_2", "T_3", "H_3", "CNot_1_2", "CNot_1_3", "CNot_2_3", "Tdagger_1", "Tdagger_2", "Tdagger_3", "Identity"],
Expand All @@ -61,7 +59,6 @@ function toffoli_using_kronecker()
println(">>>>> Toffoli gate using Kronecker <<<<<")

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 12,
"elementary_gates" => ["T_3", "H_3", "CNot_1_2", "CNot_1_3", "CNot_2_3", "Tdagger_3", "I_1xT_2xT_3", "CNot_1_2xH_3", "T_1xTdagger_2xI_3", "Identity"],
Expand All @@ -79,7 +76,6 @@ function toffoli_using_2qubit_gates()
println(">>>>> Toffoli gate with controlled gates <<<<<")

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 5,
"elementary_gates" => ["CV_1_3", "CV_2_3", "CV_1_2", "CVdagger_1_3", "CVdagger_2_3", "CVdagger_1_2", "CNot_2_1", "CNot_1_2", "Identity"],
Expand All @@ -92,12 +88,11 @@ end
function CNot_1_3()

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 8,
# "elementary_gates" => ["CNot_1_2", "CNot_2_3", "Identity"],
"elementary_gates" => ["H_1", "H_3", "H_2", "CNot_2_1", "CNot_3_2", "Identity"],
"target_gate" => QCOpt.get_full_sized_gate("CNot_1_3", 3),
"target_gate" => QCOpt.get_unitary("CNot_1_3", 3),
"objective" => "minimize_depth",
)
end
Expand Down Expand Up @@ -132,17 +127,16 @@ function toffoli_left()
# Reference: https://arxiv.org/pdf/0803.2316.pdf

function target_gate()
H_3 = QCOpt.get_full_sized_gate("H_3", 3)
Tdagger_3 = QCOpt.get_full_sized_gate("Tdagger_3", 3)
T_3 = QCOpt.get_full_sized_gate("T_3", 3)
cnot_23 = QCOpt.get_full_sized_gate("CNot_2_3", 3)
CNot_1_3 = QCOpt.get_full_sized_gate("CNot_1_3", 3)
H_3 = QCOpt.get_unitary("H_3", 3)
Tdagger_3 = QCOpt.get_unitary("Tdagger_3", 3)
T_3 = QCOpt.get_unitary("T_3", 3)
cnot_23 = QCOpt.get_unitary("CNot_2_3", 3)
CNot_1_3 = QCOpt.get_unitary("CNot_1_3", 3)

return H_3 * cnot_23 * Tdagger_3 * CNot_1_3 * T_3 * cnot_23 * Tdagger_3
end

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 7,
"elementary_gates" => ["H_3", "T_1", "T_2", "T_3", "Tdagger_1", "Tdagger_2", "Tdagger_3", "CNot_1_2", "CNot_2_3", "CNot_1_3", "Identity"],
Expand All @@ -157,19 +151,18 @@ function toffoli_right()
# Reference: https://arxiv.org/pdf/0803.2316.pdf

function target_gate()
H_3 = QCOpt.get_full_sized_gate("H_3", 3)
Tdagger_2 = QCOpt.get_full_sized_gate("Tdagger_2", 3)
T_1 = QCOpt.get_full_sized_gate("T_1", 3)
T_2 = QCOpt.get_full_sized_gate("T_2", 3)
T_3 = QCOpt.get_full_sized_gate("T_3", 3)
CNot_1_2 = QCOpt.get_full_sized_gate("CNot_1_2", 3)
CNot_1_3 = QCOpt.get_full_sized_gate("CNot_1_3", 3)
H_3 = QCOpt.get_unitary("H_3", 3)
Tdagger_2 = QCOpt.get_unitary("Tdagger_2", 3)
T_1 = QCOpt.get_unitary("T_1", 3)
T_2 = QCOpt.get_unitary("T_2", 3)
T_3 = QCOpt.get_unitary("T_3", 3)
CNot_1_2 = QCOpt.get_unitary("CNot_1_2", 3)
CNot_1_3 = QCOpt.get_unitary("CNot_1_3", 3)

return CNot_1_3 * T_2 * T_3 * CNot_1_2 * H_3 * T_1 * Tdagger_2 * CNot_1_2
end

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 8,
"elementary_gates" => ["H_3", "T_1", "T_2", "T_3", "Tdagger_1", "Tdagger_2", "Tdagger_3", "CNot_1_2", "CNot_2_3", "CNot_1_3", "Identity"],
Expand All @@ -182,18 +175,17 @@ function miller()
# Reference: https://doi.org/10.1109/TCAD.2005.858352

function target_gate()
CV_1_3 = QCOpt.get_full_sized_gate("CV_1_3", 3)
CV_2_3 = QCOpt.get_full_sized_gate("CV_2_3", 3)
CVdagger_2_3 = QCOpt.get_full_sized_gate("CVdagger_2_3", 3)
CNot_1_2 = QCOpt.get_full_sized_gate("CNot_1_2", 3)
CNot_3_1 = QCOpt.get_full_sized_gate("CNot_3_1", 3)
CNot_3_2 = QCOpt.get_full_sized_gate("CNot_3_2", 3)
CV_1_3 = QCOpt.get_unitary("CV_1_3", 3)
CV_2_3 = QCOpt.get_unitary("CV_2_3", 3)
CVdagger_2_3 = QCOpt.get_unitary("CVdagger_2_3", 3)
CNot_1_2 = QCOpt.get_unitary("CNot_1_2", 3)
CNot_3_1 = QCOpt.get_unitary("CNot_3_1", 3)
CNot_3_2 = QCOpt.get_unitary("CNot_3_2", 3)

return CNot_3_1 * CNot_3_2 * CV_2_3 * CNot_1_2 * CVdagger_2_3 * CV_1_3 * CNot_3_1 * CNot_1_2
end

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 8,
"elementary_gates" => ["CV_1_3", "CV_2_3", "CVdagger_2_3", "CNot_1_2", "CNot_3_1", "CNot_3_2", "Identity"],
Expand All @@ -206,7 +198,6 @@ function relative_toffoli()
#Reference: https://arxiv.org/pdf/1508.03273.pdf

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 9,
"elementary_gates" => ["H_3", "T_3", "Tdagger_3", "CNot_1_2", "CNot_2_3", "CNot_1_3", "Identity"],
Expand All @@ -221,7 +212,6 @@ function margolus()
#Reference: https://arxiv.org/pdf/quant-ph/0312225.pdf

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 7,
"elementary_gates" => ["RY_3", "CNot_1_2", "CNot_2_3", "CNot_1_3", "Identity"],
Expand All @@ -238,12 +228,28 @@ function CiSwap()
#Reference: https://doi.org/10.1103/PhysRevResearch.2.033097

return Dict{String, Any}(

"num_qubits" => 3,
"maximum_depth" => 12,
"elementary_gates" => ["H_3", "T_3", "Tdagger_3", "CNot_3_2", "CNot_2_3", "CNot_1_3", "Identity"],
"target_gate" => QCOpt.CiSwapGate(),
"objective" => "minimize_depth",
"decomposition_type" => "exact_optimal",
)
end

function QFT3()

# QFT3 circuit using Controlled-Phase gates
return Dict{String, Any}(
"num_qubits" => 3,
"maximum_depth" => 7,
# "elementary_gates" => ["H_1", "H_2", "H_3", "CS_2_1", "CS_3_2", "CT_3_1", "Swap_1_3", "Identity"],
"elementary_gates" => ["H_1", "H_2", "H_3", "CU3_2_1", "CU3_3_2", "CU3_3_1", "Swap_1_3", "Identity"],
"CU3_θ_discretization" => [0],
"CU3_ϕ_discretization" => [0],
"CU3_λ_discretization" =>/2, π/4],
"target_gate" => QCOpt.QFT3Gate(),
"objective" => "minimize_depth",
"decomposition_type" => "exact_optimal",
)
end
38 changes: 19 additions & 19 deletions examples/4qubit_gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function CNot_41()
"num_qubits" => 4,
"maximum_depth" => 10,
"elementary_gates" => ["H_1", "H_2", "H_3", "CNot_1_3", "CNot_4_3", "Identity"],
"target_gate" => QCOpt.get_full_sized_gate("CNot_4_1", 4),
"target_gate" => QCOpt.get_unitary("CNot_4_1", 4),
"objective" => "minimize_depth",
"decomposition_type" => "exact_optimal"
)
Expand All @@ -20,13 +20,13 @@ function quantum_fulladder()

function target_gate_1()

CV_1_2 = QCOpt.get_full_sized_gate("CV_1_2", num_qubits);
CV_4_2 = QCOpt.get_full_sized_gate("CV_4_2", num_qubits);
CVdagger_1_2 = QCOpt.get_full_sized_gate("CVdagger_1_2", num_qubits);
CVdagger_3_2 = QCOpt.get_full_sized_gate("CVdagger_3_2", num_qubits);
CNot_3_1 = QCOpt.get_full_sized_gate("CNot_3_1", num_qubits);
CNot_4_3 = QCOpt.get_full_sized_gate("CNot_4_3", num_qubits);
CNot_2_4 = QCOpt.get_full_sized_gate("CNot_2_4", num_qubits);
CV_1_2 = QCOpt.get_unitary("CV_1_2", num_qubits);
CV_4_2 = QCOpt.get_unitary("CV_4_2", num_qubits);
CVdagger_1_2 = QCOpt.get_unitary("CVdagger_1_2", num_qubits);
CVdagger_3_2 = QCOpt.get_unitary("CVdagger_3_2", num_qubits);
CNot_3_1 = QCOpt.get_unitary("CNot_3_1", num_qubits);
CNot_4_3 = QCOpt.get_unitary("CNot_4_3", num_qubits);
CNot_2_4 = QCOpt.get_unitary("CNot_2_4", num_qubits);

return CNot_2_4 * CV_4_2 * CVdagger_1_2 * CVdagger_3_2 * CNot_4_3 * CNot_3_1 * CV_1_2
end
Expand All @@ -49,11 +49,11 @@ function double_toffoli()
num_qubits = 4

function target_gate()
CV_3_4 = QCOpt.get_full_sized_gate("CV_3_4", num_qubits);
CV_2_4 = QCOpt.get_full_sized_gate("CV_2_4", num_qubits);
CVdagger_2_4 = QCOpt.get_full_sized_gate("CVdagger_2_4", num_qubits);
CNot_1_3 = QCOpt.get_full_sized_gate("CNot_1_3", num_qubits);
CNot_3_2 = QCOpt.get_full_sized_gate("CNot_3_2", num_qubits);
CV_3_4 = QCOpt.get_unitary("CV_3_4", num_qubits);
CV_2_4 = QCOpt.get_unitary("CV_2_4", num_qubits);
CVdagger_2_4 = QCOpt.get_unitary("CVdagger_2_4", num_qubits);
CNot_1_3 = QCOpt.get_unitary("CNot_1_3", num_qubits);
CNot_3_2 = QCOpt.get_unitary("CNot_3_2", num_qubits);

return CV_2_4 * CNot_1_3 * CNot_3_2 * CV_3_4 * CVdagger_2_4 * CNot_3_2 * CNot_1_3
end
Expand All @@ -76,12 +76,12 @@ function double_peres()
num_qubits = 4

function target_gate()
CV_1_4 = QCOpt.get_full_sized_gate("CV_1_4", num_qubits);
CV_2_4 = QCOpt.get_full_sized_gate("CV_2_4", num_qubits);
CV_3_4 = QCOpt.get_full_sized_gate("CV_3_4", num_qubits);
CVdagger_3_4 = QCOpt.get_full_sized_gate("CVdagger_3_4", num_qubits);
CNot_1_2 = QCOpt.get_full_sized_gate("CNot_1_2", num_qubits);
CNot_2_3 = QCOpt.get_full_sized_gate("CNot_2_3", num_qubits);
CV_1_4 = QCOpt.get_unitary("CV_1_4", num_qubits);
CV_2_4 = QCOpt.get_unitary("CV_2_4", num_qubits);
CV_3_4 = QCOpt.get_unitary("CV_3_4", num_qubits);
CVdagger_3_4 = QCOpt.get_unitary("CVdagger_3_4", num_qubits);
CNot_1_2 = QCOpt.get_unitary("CNot_1_2", num_qubits);
CNot_2_3 = QCOpt.get_unitary("CNot_2_3", num_qubits);

return CV_2_4 * CNot_1_2 * CV_3_4 * CV_1_4 * CNot_2_3 * CVdagger_3_4
end
Expand Down
24 changes: 12 additions & 12 deletions examples/gates_sc21.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ function double_toffoli()
num_qubits = 4

function target_gate()
CV_3_4 = QCOpt.get_full_sized_gate("CV_3_4", num_qubits);
CV_2_4 = QCOpt.get_full_sized_gate("CV_2_4", num_qubits);
CVdagger_2_4 = QCOpt.get_full_sized_gate("CVdagger_2_4", num_qubits);
CNot_1_3 = QCOpt.get_full_sized_gate("CNot_1_3", num_qubits);
CNot_3_2 = QCOpt.get_full_sized_gate("CNot_3_2", num_qubits);
CV_3_4 = QCOpt.get_unitary("CV_3_4", num_qubits);
CV_2_4 = QCOpt.get_unitary("CV_2_4", num_qubits);
CVdagger_2_4 = QCOpt.get_unitary("CVdagger_2_4", num_qubits);
CNot_1_3 = QCOpt.get_unitary("CNot_1_3", num_qubits);
CNot_3_2 = QCOpt.get_unitary("CNot_3_2", num_qubits);

return CV_2_4 * CNot_1_3 * CNot_3_2 * CV_3_4 * CVdagger_2_4 * CNot_3_2 * CNot_1_3
end
Expand All @@ -229,13 +229,13 @@ function quantum_fulladder()

function target_gate()

CV_1_2 = QCOpt.get_full_sized_gate("CV_1_2", num_qubits);
CV_4_2 = QCOpt.get_full_sized_gate("CV_4_2", num_qubits);
CVdagger_1_2 = QCOpt.get_full_sized_gate("CVdagger_1_2", num_qubits);
CVdagger_3_2 = QCOpt.get_full_sized_gate("CVdagger_3_2", num_qubits);
CNot_3_1 = QCOpt.get_full_sized_gate("CNot_3_1", num_qubits);
CNot_4_3 = QCOpt.get_full_sized_gate("CNot_4_3", num_qubits);
CNot_2_4 = QCOpt.get_full_sized_gate("CNot_2_4", num_qubits);
CV_1_2 = QCOpt.get_unitary("CV_1_2", num_qubits);
CV_4_2 = QCOpt.get_unitary("CV_4_2", num_qubits);
CVdagger_1_2 = QCOpt.get_unitary("CVdagger_1_2", num_qubits);
CVdagger_3_2 = QCOpt.get_unitary("CVdagger_3_2", num_qubits);
CNot_3_1 = QCOpt.get_unitary("CNot_3_1", num_qubits);
CNot_4_3 = QCOpt.get_unitary("CNot_4_3", num_qubits);
CNot_2_4 = QCOpt.get_unitary("CNot_2_4", num_qubits);

return CNot_2_4 * CV_4_2 * CVdagger_1_2 * CVdagger_3_2 * CNot_4_3 * CNot_3_1 * CV_1_2
end
Expand Down
Loading

0 comments on commit 5734d7e

Please sign in to comment.