From 10bb4b6cef05341caad61162b518735ae82fe3fd Mon Sep 17 00:00:00 2001 From: Feroz Ahmad <93876775+Fe-r-oz@users.noreply.github.com> Date: Thu, 18 Jul 2024 01:00:39 +0500 Subject: [PATCH] `inv` implementation for `SingleQubitOperator` (#314) --------- Co-authored-by: Stefan Krastanov --- CHANGELOG.md | 4 ++++ Project.toml | 2 +- src/symbolic_cliffords.jl | 13 +++++++++++++ test/test_symcliff.jl | 14 +++++++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c7f5a8b..ec4e15c24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ # News +## v0.9.6 - 2024-07-12 + +- `inv` implementation for single-qubit "symbolic" Clifford operators (subtypes of `AbstractSingleQubitOperator`). + ## v0.9.5 - 2024-07-04 - Implementation of random all-to-all and brickwork Clifford circuits and corresponding ECC codes. diff --git a/Project.toml b/Project.toml index 92a6bbb5d..2f3303f4b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QuantumClifford" uuid = "0525e862-1e90-11e9-3e4d-1b39d7109de1" authors = ["Stefan Krastanov and QuantumSavory community members"] -version = "0.9.5" +version = "0.9.6" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" diff --git a/src/symbolic_cliffords.jl b/src/symbolic_cliffords.jl index b143589b3..0d2c26c40 100644 --- a/src/symbolic_cliffords.jl +++ b/src/symbolic_cliffords.jl @@ -227,6 +227,19 @@ function random_clifford1(rng::AbstractRNG, qubit) end random_clifford1(qubit) = random_clifford1(GLOBAL_RNG, qubit) +function LinearAlgebra.inv(op::SingleQubitOperator) + c = LinearAlgebra.inv(CliffordOperator(SingleQubitOperator(op), 1, compact=true)) + return SingleQubitOperator(c, op.q) +end + +LinearAlgebra.inv(h::sHadamard) = sHadamard(h.q) +LinearAlgebra.inv(p::sPhase) = sInvPhase(p.q) +LinearAlgebra.inv(p::sInvPhase) = sPhase(p.q) +LinearAlgebra.inv(p::sId1) = sId1(p.q) +LinearAlgebra.inv(p::sX) = sX(p.q) +LinearAlgebra.inv(p::sY) = sY(p.q) +LinearAlgebra.inv(p::sZ) = sZ(p.q) + ############################## # Two-qubit gates ############################## diff --git a/test/test_symcliff.jl b/test/test_symcliff.jl index 9cfddb976..2af1fd538 100644 --- a/test/test_symcliff.jl +++ b/test/test_symcliff.jl @@ -1,6 +1,5 @@ using Random using QuantumClifford - using QuantumClifford: stab_looks_good, destab_looks_good, mixed_stab_looks_good, mixed_destab_looks_good using QuantumClifford: apply_single_x!, apply_single_y!, apply_single_z! using InteractiveUtils @@ -66,3 +65,16 @@ end @test op1 == op2 end end + +@testset "SingleQubitOperator inv methods" begin + for gate_type in [sHadamard, sX, sY, sZ, sId1 , sPhase, sInvPhase] + n = rand(1:10) + @test CliffordOperator(inv(SingleQubitOperator(gate_type(n))), n) == inv(CliffordOperator(gate_type(n), n)) + @test CliffordOperator(inv(gate_type(n)), n) == inv(CliffordOperator(gate_type(n), n)) + end + for i in 1:10 + random_op = random_clifford1(i) + @test CliffordOperator(inv(random_op), i) == inv(CliffordOperator(random_op, i)) + @test CliffordOperator(inv(SingleQubitOperator(random_op)), i) == inv(CliffordOperator(random_op, i)) + end +end