-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Adding support for FreeParameterExpression (#85)
* Feature: Adding support for FreeParameterExpression, resolving Issue #82 * [Feature]: Adding support for FreeParameterExpression: Improving tests and subs function * [Feature]: Adding support for FreeParameterExpression - minor cleanup * [Feature]: Adding support for FreeParameterExpression - Formatting * [Feature]: Adding support for FreeParameterExpression - Adding codereview suggestions * [Feature]: Adding support for FreeParameterExpression - completing codereview suggestions * [Feature]: Adding support for FreeParameterExpression - direct gate generation example to doctests * [Feature]: Adding support for FreeParameterExpression - formatting * [Feature]: Adding support for FreeParameterExpression - formatting * [Feature]: Adding support for FreeParameterExpression - Adding more tests * [Feature]: Adding support for FreeParameterExpression - formatting * sliming down the operator functions * codereview suggestions * Minor Formatting, Including complete Greek Letters * fix Symbolic version to 5.30.0 and SymbolicUtils to 2.0.2 * using SymbolicUtils = =2.0.2 --------- Signed-off-by: Katharine Hyatt <[email protected]> Co-authored-by: Fe-r-oz <[email protected]> Co-authored-by: Katharine Hyatt <[email protected]>
- Loading branch information
1 parent
f5ec984
commit 608532d
Showing
7 changed files
with
194 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using Braket, Test | ||
|
||
@testset "Free parameter expressions" begin | ||
α = FreeParameter(:alpha) | ||
θ = FreeParameter(:theta) | ||
gate = FreeParameterExpression("α + 2*θ") | ||
@test copy(gate) === gate | ||
gsub = subs(gate, Dict(:α => 2.0, :θ => 2.0)) | ||
circ = Circuit() | ||
circ = H(circ, 0) | ||
circ = Rx(circ, 1, gsub) | ||
circ = Ry(circ, 0, θ) | ||
circ = Probability(circ) | ||
new_circ = circ(6.0) | ||
non_para_circ = Circuit() |> (ci->H(ci, 0)) |> (ci->Rx(ci, 1, gsub)) |> (ci->Ry(ci, 0, 6.0)) |> Probability | ||
@test new_circ == non_para_circ | ||
ϕ = FreeParameter(:phi) | ||
circ = apply_gate_noise!(circ, BitFlip(ϕ)) | ||
circ = apply_gate_noise!(circ, PhaseFlip(0.1)) | ||
new_circ = circ(theta=2.0, alpha=1.0, phi=0.2) | ||
non_para_circ = Circuit() |> (ci->H(ci, 0)) |> (ci->Rx(ci, 1, gsub)) |> (ci->Ry(ci, 0, 2.0)) |> Probability |> (ci->apply_gate_noise!(ci, BitFlip(0.2))) |> (ci->apply_gate_noise!(ci, PhaseFlip(0.1))) | ||
@test new_circ == non_para_circ | ||
|
||
# creating gates directly | ||
gate = FreeParameterExpression("phi + 2*gamma") | ||
gsub₁ = subs(gate, Dict(:phi => 4.0, :gamma => 4.0)) | ||
@test gsub₁ == 12.0 | ||
circ = Circuit() | ||
circ = H(circ, 0) | ||
circ = Rx(circ, 1, gsub₁) | ||
circ = Ry(circ, 0, θ) | ||
circ = Probability(circ) | ||
new_circ = circ(6.0) | ||
non_para_circ = Circuit() |> (ci->H(ci, 0)) |> (ci->Rx(ci, 1, gsub₁)) |> (ci->Ry(ci, 0, 6.0)) |> Probability | ||
@test new_circ == non_para_circ | ||
|
||
# + operator | ||
fpe1 = FreeParameterExpression("α + θ") | ||
fpe2 = FreeParameterExpression("2 * θ") | ||
result = fpe1 + fpe2 | ||
@test result == FreeParameterExpression("2 * θ + α + θ") | ||
gsub = subs(result, Dict(:α => 1.0, :θ => 1.0)) | ||
@test gsub == 4.0 # α + 3θ == 4.0 | ||
fpe3 = FreeParameterExpression("2 * θ") | ||
# == operator | ||
@test fpe3 == fpe2 | ||
# != operator | ||
@test fpe1 != fpe2 | ||
show(fpe3) | ||
# - operator | ||
result = fpe1 - fpe2 | ||
@test result == FreeParameterExpression("α - θ") | ||
gsub = subs(result, Dict(:α => 1.0, :θ => 1.0)) | ||
@test gsub == 0.0 # α - θ == 0.0 | ||
# * operator | ||
result = fpe1 * fpe2 | ||
@test result == FreeParameterExpression("2(α + θ)*θ") | ||
gsub = subs(result, Dict(:α => 1.0, :θ => 1.0)) | ||
@test gsub == 4.0 # 2(α + θ)*θ == 4.0 | ||
# / operator | ||
result = fpe1 / fpe2 | ||
@test result == FreeParameterExpression("(α + θ) / (2θ)") | ||
gsub = subs(result, Dict(:α => 1.0, :θ => 1.0)) | ||
@test gsub == 1.0 # (α + θ) / (2θ) == 1.0 | ||
# ^ operator | ||
result = fpe1 ^ fpe2 | ||
@test result == FreeParameterExpression("(α + θ)^(2θ)") | ||
gsub = subs(result, Dict(:α => 1.0, :θ => 1.0)) | ||
@test gsub == 4.0 # (α + θ)^(2θ) == 4.0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters