From b22d9e521df78b623d7d49e9815fc5bb3e389460 Mon Sep 17 00:00:00 2001 From: Steven Whitaker Date: Mon, 28 Aug 2023 15:52:50 -0700 Subject: [PATCH 1/2] Add a couple of methods. --- src/blochmatrix.jl | 18 ++++++++++++++++++ test/blochmatrix.jl | 22 +++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/blochmatrix.jl b/src/blochmatrix.jl index 23ac48d..da54343 100644 --- a/src/blochmatrix.jl +++ b/src/blochmatrix.jl @@ -740,6 +740,24 @@ function Base.:*(A::BlochMatrix, ::IdealSpoilingMatrix) end +function Base.:*(A::FreePrecessionMatrix, B::BlochMatrix) + + (sinθ, cosθ) = sincos(A.θ) + return BlochMatrix( + A.E2 * cosθ * B.a11 + A.E2 * sinθ * B.a21, + -A.E2 * sinθ * B.a11 + A.E2 * cosθ * B.a21, + A.E1 * B.a31, + A.E2 * cosθ * B.a12 + A.E2 * sinθ * B.a22, + -A.E2 * sinθ * B.a12 + A.E2 * cosθ * B.a22, + A.E1 * B.a32, + A.E2 * cosθ * B.a13 + A.E2 * sinθ * B.a23, + -A.E2 * sinθ * B.a13 + A.E2 * cosθ * B.a23, + A.E1 * B.a33 + ) + +end + +Base.:*(A::ExcitationMatrix, B::FreePrecessionMatrix) = A.A * B Base.:*(A::ExcitationMatrix, ::IdealSpoilingMatrix) = A.A * idealspoiling function Base.:*(A::BlochMcConnellMatrix{T1,N}, B::BlochMcConnellMatrix{T2,N}) where {T1,T2,N} diff --git a/test/blochmatrix.jl b/test/blochmatrix.jl index 8b4b950..937f39e 100644 --- a/test/blochmatrix.jl +++ b/test/blochmatrix.jl @@ -164,10 +164,10 @@ end function times6() - A = BlochMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9) + A = ExcitationMatrix(BlochMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9)) B = FreePrecessionMatrix(1, 1, 1) C = A * B - correct = Matrix(A) * Matrix(B) + correct = Matrix(A.A) * Matrix(B) return Matrix(C) ≈ correct @@ -175,6 +175,17 @@ end function times7() + A = FreePrecessionMatrix(1, 1, 1) + B = BlochMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9) + C = A * B + correct = Matrix(A) * Matrix(B) + + return Matrix(C) ≈ correct + +end + +function times8() + A = ExcitationMatrix(BlochMatrix(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)) C = A * idealspoiling correct = BlochMatrix(0, 0, 0, 0, 0, 0, 0.7, 0.8, 0.9) @@ -183,7 +194,7 @@ function times7() end -function times8() +function times9() A = ExcitationMatrix(BlochMatrix(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)) B = BlochMcConnellMatrix(3) @@ -205,7 +216,7 @@ function times8() end -function times9() +function times10() A = idealspoiling B = BlochMcConnellMatrix(3) @@ -631,7 +642,7 @@ function mul16() mul!(C, A, A) correct = Matrix(A) * Matrix(A) - return Matrix(C) == correct + return Matrix(C) ≈ correct end @@ -1216,6 +1227,7 @@ end @test times7() @test times8() @test times9() + @test times10() end From 4f15971091f2b3bd484df66e18b40bb23bb9a339 Mon Sep 17 00:00:00 2001 From: Steven Whitaker Date: Mon, 28 Aug 2023 15:53:37 -0700 Subject: [PATCH 2/2] v0.7.0 --> v0.7.1 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 8830736..ff1d3c9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BlochSim" uuid = "5c0f8cbe-99a4-11e9-108b-216da9629524" authors = ["Steven Whitaker "] -version = "0.7.0" +version = "0.7.1" [deps] ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"