Skip to content

Commit

Permalink
updates -> v0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
harshangrjn committed Jul 22, 2021
1 parent a760338 commit fe8ee59
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 79 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
QuantumCircuitOpt.jl Change Log
===============================

### v0.1.6
- Added support for obtaining idempotent matrices and adding corresponding valid constraints
- Updated `all_valid_constraints` from `Bool` to values in `[-1,0,1]`
- `qc_model.jl` clean-up
- Updated unit tests to reflect above changes

### v0.1.5
- Added support for pair-wise commuting products with Identity, (AB=BA=I)
- Bug fix to remove redundant pairs in `get_commutative_gate_pairs` when corresponding product is an Identity gate
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.1.5"
version = "0.1.6"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
10 changes: 5 additions & 5 deletions examples/2qubit_gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function test_controlled_Z()
"target_gate" => QCO.CZGate(),

"U_θ_discretization" => [-π/2, 0, π/2],
"U_ϕ_discretization" => [0, π/2],
"U_λ_discretization" => [0, π/2],
"U_ϕ_discretization" => [-π/2, 0, π/2],
"U_λ_discretization" => [-π/2, 0, π/2],

"objective" => "minimize_depth",
"decomposition_type" => "exact",
Expand Down Expand Up @@ -194,8 +194,8 @@ function test_S()
"elementary_gates" => ["U3", "cnot_12", "Identity"],
"target_gate" => QCO.kron_single_gate(2, QCO.SGate(), "q1"),

"U_θ_discretization" => [0, π/2],
"U_ϕ_discretization" => [0, π/2],
"U_θ_discretization" => [0, π/4, π/2],
"U_ϕ_discretization" => [-π/2, 0, π/2],
"U_λ_discretization" => [0, π],

"objective" => "minimize_depth",
Expand Down Expand Up @@ -348,7 +348,7 @@ function test_HCoinGate()
"decomposition_type" => "exact",

"optimizer" => "cplex",
"MIP_feasiblity_emphasis" => true
# "MIP_feasiblity_emphasis" => true

)

Expand Down
2 changes: 1 addition & 1 deletion examples/run_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_gates = ["test_hadamard",
"test_W_using_HCnot",
"test_RX_on_q3"]

# test_gates = ["test_magic_M"]
# test_gates = ["test_controlled_Z"]

#----------------------------------------------#
# Quantum Circuit Optimization model #
Expand Down
20 changes: 20 additions & 0 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,25 @@ function constraint_redundant_gate_product_pairs(qcm::QuantumCircuitModel)
end
end

return
end

function constraint_idempotent_gates(qcm::QuantumCircuitModel)

gates_dict = qcm.data["gates_dict"]
depth = qcm.data["depth"]
z_onoff_var = qcm.variables[:z_onoff_var]

idempotent_gates = QCO.get_idempotent_gates(gates_dict)

if !isempty(idempotent_gates)
(length(idempotent_gates) == 1) && (Memento.info(_LOGGER, "Detected $(length(idempotent_gates)) idempotent elementary gate"))
(length(idempotent_gates) > 1) && (Memento.info(_LOGGER, "Detected $(length(idempotent_gates)) idempotent elementary gates"))

for i = 1:length(idempotent_gates)
JuMP.@constraint(qcm.model, [d=1:(depth-1)], z_onoff_var[idempotent_gates[i], d] + z_onoff_var[idempotent_gates[i], d+1] <= 1)
end
end

return
end
22 changes: 11 additions & 11 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function get_data(params::Dict{String, Any}; eliminate_identical_gates = true)
Memento.warn(_LOGGER, "Eliminating non-unique gates in the input elementary gates")
end

gates_dict, target_real = get_quantum_gates(params, elementary_gates)
gates_dict, target_real = QCO.get_quantum_gates(params, elementary_gates)

gates_dict_unique, M_real_unique, identity_idx, cnot_idx = eliminate_nonunique_gates(gates_dict, eliminate_identical_gates = eliminate_identical_gates)

Expand Down Expand Up @@ -194,15 +194,15 @@ function eliminate_nonunique_gates(gates_dict::Dict{String, Any}; eliminate_iden
gates_dict_unique = gates_dict
end

identity_idx = _get_identity_idx(M_real_unique)
identity_idx = QCO._get_identity_idx(M_real_unique)

for i_id = 1:length(identity_idx)
if !("Identity" in gates_dict_unique["$(identity_idx[i_id])"]["type"])
push!(gates_dict_unique["$(identity_idx[i_id])"]["type"], "Identity")
end
end

cnot_idx = _get_cnot_idx(gates_dict_unique)
cnot_idx = QCO._get_cnot_idx(gates_dict_unique)

return gates_dict_unique, M_real_unique, identity_idx, cnot_idx

Expand Down Expand Up @@ -245,7 +245,7 @@ function get_quantum_gates(params::Dict{String, Any}, elementary_gates::Array{St

num_qubits = params["num_qubits"]

gates_dict = get_all_gates_dictionary(params, elementary_gates)
gates_dict = QCO.get_all_gates_dictionary(params, elementary_gates)

if !("target_gate" in keys(params)) || isempty(params["target_gate"])
Memento.error(_LOGGER, "Target gate not found in the input data")
Expand All @@ -267,12 +267,12 @@ function get_all_gates_dictionary(params::Dict{String, Any}, elementary_gates::A

R_complex_dict = Dict{}
if !isempty(R_gates_ids)
R_complex_dict = get_all_R_gates(params, elementary_gates)
R_complex_dict = QCO.get_all_R_gates(params, elementary_gates)
end

U_complex_dict = Dict{}
if !isempty(U_gates_ids)
U_complex_dict = get_all_U_gates(params, elementary_gates)
U_complex_dict = QCO.get_all_U_gates(params, elementary_gates)
end

gates_dict = Dict{String, Any}()
Expand Down Expand Up @@ -321,7 +321,7 @@ function get_all_gates_dictionary(params::Dict{String, Any}, elementary_gates::A

else

M = get_full_sized_gate(elementary_gates[i], num_qubits)
M = QCO.get_full_sized_gate(elementary_gates[i], num_qubits)
M_sqrd = M^2

gates_dict["$counter"] = Dict{String, Any}("type" => [elementary_gates[i]],
Expand Down Expand Up @@ -357,7 +357,7 @@ function get_all_R_gates(params::Dict{String, Any}, elementary_gates::Array{Stri
end

R_complex["$(gate_type)"] = Dict{String, Any}()
R_complex["$(gate_type)"] = get_discretized_R_gates(gate_type, R_complex[gate_type], collect(params[string(gate_type,"_discretization")]), params["num_qubits"])
R_complex["$(gate_type)"] = QCO.get_discretized_R_gates(gate_type, R_complex[gate_type], collect(params[string(gate_type,"_discretization")]), params["num_qubits"])

end
end
Expand All @@ -384,7 +384,7 @@ function get_discretized_R_gates(R_type::String, R::Dict{String, Any}, discretiz
)

for i_qu = 1:num_qubits
R["angle_$i"]["$(num_qubits)qubit_rep"]["qubit_$i_qu"] = get_full_sized_gate(R_type, num_qubits, matrix = R_discrete, qubit_location = "q$i_qu")
R["angle_$i"]["$(num_qubits)qubit_rep"]["qubit_$i_qu"] = QCO.get_full_sized_gate(R_type, num_qubits, matrix = R_discrete, qubit_location = "q$i_qu")
end

end
Expand All @@ -404,7 +404,7 @@ function get_all_U_gates(params::Dict{String, Any}, elementary_gates::Array{Stri

if (elementary_gates[U_gates_ids[i]] == "U3")
U_complex["U3"] = Dict{String, Any}()
U_complex["U3"] = get_discretized_U3_gates("U3", U_complex["U3"], collect(float(params["U_θ_discretization"])), collect(float(params["U_ϕ_discretization"])), collect(float(params["U_λ_discretization"])), params["num_qubits"])
U_complex["U3"] = QCO.get_discretized_U3_gates("U3", U_complex["U3"], collect(float(params["U_θ_discretization"])), collect(float(params["U_ϕ_discretization"])), collect(float(params["U_λ_discretization"])), params["num_qubits"])
end

# Add support for U1 and U2 universal gates here
Expand Down Expand Up @@ -433,7 +433,7 @@ function get_discretized_U3_gates(U_type::String, U::Dict{String, Any}, θ_discr
)

for i_qu=1:num_qubits
U["angle_$(counter)"]["$(num_qubits)qubit_rep"]["qubit_$i_qu"] = get_full_sized_gate(U_type, num_qubits, matrix = U_discrete, qubit_location = "q$i_qu")
U["angle_$(counter)"]["$(num_qubits)qubit_rep"]["qubit_$i_qu"] = QCO.get_full_sized_gate(U_type, num_qubits, matrix = U_discrete, qubit_location = "q$i_qu")
end

counter += 1
Expand Down
2 changes: 1 addition & 1 deletion src/log.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function visualize_solution(results::Dict{String, Any}, data::Dict{String, Any};

return
else
gates_sol, gates_sol_compressed = get_postprocessed_solutions(results, data)
gates_sol, gates_sol_compressed = QCO.get_postprocessed_solutions(results, data)
end

R_gates_ids = findall(x -> startswith(x, "R"), data["elementary_gates"])
Expand Down
Loading

0 comments on commit fe8ee59

Please sign in to comment.