From 602d18d01897695de875639d790e3d1da18b60a1 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Nov 2024 01:08:11 +0500 Subject: [PATCH] normalize the projected states to have consistent comparison and use random_clifford --- test/test_nonclifford_quantumoptics.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_nonclifford_quantumoptics.jl b/test/test_nonclifford_quantumoptics.jl index 9c1c1384a..88a1d2ef6 100644 --- a/test/test_nonclifford_quantumoptics.jl +++ b/test/test_nonclifford_quantumoptics.jl @@ -93,7 +93,7 @@ end s = random_stabilizer(n) p = random_pauli(n) md = MixedDestabilizer(s) - apply!(md, p) # or apply!(s, p) + apply!(md, random_clifford(n)) # or apply!(s, random_clifford(n)) qo_state = Operator(md) # or Operator(s) projectrand!(md, p)[1] # or projectrand!(s, p)[1] qo_state_after_proj = Operator(md) # or Operator(s) @@ -102,7 +102,11 @@ end qo_proj2 = (identityoperator(qo_pauli) + qo_pauli)/2 result1 = qo_proj1*qo_state*qo_proj1' result2 = qo_proj2*qo_state*qo_proj2' - @test qo_state_after_proj ≈ result2 || qo_state_after_proj ≈ result1 || qo_state_after_proj ≈ 2*result2 || qo_state_after_proj ≈ 2*result1 + # Normalize to ensure consistent comparison of the projected state, independent of scaling factors + norm_qo_state_after_proj = qo_state_after_proj / tr(qo_state_after_proj) + norm_result1 = result1 / tr(result1) + norm_result2 = result2 / tr(result2) + @test norm_qo_state_after_proj ≈ norm_result2 || norm_qo_state_after_proj ≈ norm_result1 end end end