From ba1aa48aa9f0a5daab3619812733e67c4babf9db Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Wed, 20 Nov 2024 21:27:21 -0500 Subject: added test cases for bloch_messiah and williamson --- bloch_messiah.m | 14 ++++++++++++++ test_data/bm_s0.csv | 8 ++++++++ test_data/bm_s15.csv | 8 ++++++++ test_data/covmat0.csv | 8 ++++++++ test_data/covmat15.csv | 8 ++++++++ test_data/w_diag15.csv | 8 ++++++++ williamson.m | 11 ++++++++++- 7 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test_data/bm_s0.csv create mode 100644 test_data/bm_s15.csv create mode 100644 test_data/covmat0.csv create mode 100644 test_data/covmat15.csv create mode 100644 test_data/w_diag15.csv diff --git a/bloch_messiah.m b/bloch_messiah.m index 4050102..19806db 100644 --- a/bloch_messiah.m +++ b/bloch_messiah.m @@ -79,3 +79,17 @@ function [ut1, st1, v1] = bloch_messiah(S, tol) v1 = real(v1); end +%!test +%! V = load('test_data/covmat0.csv'); +%! [Db, S] = williamson(V); +%! [ut1, st1, v1] = bloch_messiah(S); +%! st0 = load('test_data/bm_s0.csv'); +%! assert(st1,st0,1e-9) + +%!test +%! V = load('test_data/covmat15.csv'); +%! [Db, S] = williamson(V); +%! [ut1, st1, v1] = bloch_messiah(S); +%! st0 = load('test_data/bm_s15.csv'); +%! assert(st1,st0,1e-9) + diff --git a/test_data/bm_s0.csv b/test_data/bm_s0.csv new file mode 100644 index 0000000..84adfdf --- /dev/null +++ b/test_data/bm_s0.csv @@ -0,0 +1,8 @@ +1.414213562,0,0,0,0,0,0,0 +0,1,1.24E-16,-1.36E-16,0,0,0,0 +0,1.14E-16,1,-1.85E-16,0,0,0,0 +0,-1.26E-16,-2.46E-16,1,0,0,0,0 +0,0,0,0,0.707106781,0,0,0 +0,0,0,0,0,1,-2.06E-16,1.17E-16 +0,0,0,0,0,-1.87E-16,1,-2.68E-17 +0,0,0,0,0,1.28E-16,-2.52E-17,1 diff --git a/test_data/bm_s15.csv b/test_data/bm_s15.csv new file mode 100644 index 0000000..3cc20a5 --- /dev/null +++ b/test_data/bm_s15.csv @@ -0,0 +1,8 @@ +1.346980706,0,0,0,0,0,0,0 +0,1.091176975,0,0,0,0,0,0 +0,0,1.056569881,0,0,0,0,0 +0,0,0,1.017970399,0,0,0,0 +0,0,0,0,0.742401131,0,0,0 +0,0,0,0,0,0.916441625,0,0 +0,0,0,0,0,0,0.946458931,0 +0,0,0,0,0,0,0,0.982346835 diff --git a/test_data/covmat0.csv b/test_data/covmat0.csv new file mode 100644 index 0000000..6be1950 --- /dev/null +++ b/test_data/covmat0.csv @@ -0,0 +1,8 @@ +1.25,0.25,0.25,0.25,0,0,0,0 +0.25,1.25,0.25,0.25,0,0,0,0 +0.25,0.25,1.25,0.25,0,0,0,0 +0.25,0.25,0.25,1.25,0,0,0,0 +0,0,0,0,0.875,-0.125,-0.125,-0.125 +0,0,0,0,-0.125,0.875,-0.125,-0.125 +0,0,0,0,-0.125,-0.125,0.875,-0.125 +0,0,0,0,-0.125,-0.125,-0.125,0.875 diff --git a/test_data/covmat15.csv b/test_data/covmat15.csv new file mode 100644 index 0000000..3cb1148 --- /dev/null +++ b/test_data/covmat15.csv @@ -0,0 +1,8 @@ +1.280139796,0.320804096,0.123868166,0.184690069,-0.022298318,0.117215837,0.128740099,0.00794298 +0.320804096,1.261422034,0.126937599,0.252697232,-0.002258718,0.023102871,0.225723714,0.130202651 +0.123868166,0.126937599,1.037345873,0.002831048,-0.127303591,-0.140740218,-0.020165309,-0.160223618 +0.184690069,0.252697232,0.002831048,1.173126139,-0.208604072,0.006987702,0.092371302,0.108985019 +-0.022298318,-0.002258718,-0.127303591,-0.208604072,0.72070289,-0.039755518,-0.068058008,-0.212392278 +0.117215837,0.023102871,-0.140740218,0.006987702,-0.039755518,0.936882538,-0.051595671,-0.029025325 +0.128740099,0.225723714,-0.020165309,0.092371302,-0.068058008,-0.051595671,1.043936513,-0.006495506 +0.00794298,0.130202651,-0.160223618,0.108985019,-0.212392278,-0.029025325,-0.006495506,0.930769021 diff --git a/test_data/w_diag15.csv b/test_data/w_diag15.csv new file mode 100644 index 0000000..c1fd3ae --- /dev/null +++ b/test_data/w_diag15.csv @@ -0,0 +1,8 @@ +0.715932178,0,0,0,0,0,0,0 +0,0.871582577,0,0,0,0,0,0 +0,0,1.369166625,0,0,0,0,0 +0,0,0,1.048046923,0,0,0,0 +0,0,0,0,0.715932178,0,0,0 +0,0,0,0,0,0.871582577,0,0 +0,0,0,0,0,0,1.369166625,0 +0,0,0,0,0,0,0,1.048046923 diff --git a/williamson.m b/williamson.m index f969ab1..eaba514 100644 --- a/williamson.m +++ b/williamson.m @@ -57,7 +57,6 @@ function [Db, S] = williamson(V, tol) Kt = K * p; s1t = p * s1 * p; - s1t dd = xpxp_to_xxpp(s1t); perm_indices = xpxp_to_xxpp(1:2*n); @@ -70,4 +69,14 @@ function [Db, S] = williamson(V, tol) S = inv(S)'; end +%!test +%! V = load('test_data/covmat0.csv'); +%! [Db, S] = williamson(V); +%! assert(Db,eye(8), 1e-14) + +%!test +%! V = load('test_data/covmat15.csv'); +%! D0 = load('test_data/w_diag15.csv'); +%! [Db, S] = williamson(V); +%! assert(Db,D0, 1e-9) -- cgit v1.2.3