From 7235f2f89ba48fd245ddf1efca6d3a9db878660c Mon Sep 17 00:00:00 2001 From: Kunal Marwaha Date: Sun, 13 Sep 2020 01:48:56 -0700 Subject: [PATCH 1/2] Implement fromBlochVector --- Q/Q-Qubit.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Q/Q-Qubit.js b/Q/Q-Qubit.js index 2b33355..35a186c 100644 --- a/Q/Q-Qubit.js +++ b/Q/Q-Qubit.js @@ -286,8 +286,20 @@ Object.assign( Q.Qubit, { }, fromBlochVector: function( x, y, z ){ + // converting back to a Qubit (a, b) only maintains the relative phase between a and b + // for convenience, I will assume a is real. - //basically from a Pauli Rotation + // this neat trick comes from considering the density matrix if a = r and b = s + ti: + // ( r*r rs-rti ) + // ( rs+rti s*s+t*t ) + + // compare that with the density matrix in https://en.wikipedia.org/wiki/Bloch_sphere + + aReal = ( 0.5 + 0.5 * z ) ** 0.5 + a = new Q.ComplexNumber( aReal, 0 ) + b = new Q.ComplexNumber( x / 2 / aReal, y / 2 / aReal ) + + return new Q.Qubit( a, b ) } }) From c398f47ce728851ef20c340b287e708509c29039 Mon Sep 17 00:00:00 2001 From: Kunal Marwaha Date: Thu, 17 Sep 2020 12:46:41 -0700 Subject: [PATCH 2/2] Add variable declarations --- Q/Q-Qubit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Q/Q-Qubit.js b/Q/Q-Qubit.js index 35a186c..b420b27 100644 --- a/Q/Q-Qubit.js +++ b/Q/Q-Qubit.js @@ -295,8 +295,9 @@ Object.assign( Q.Qubit, { // compare that with the density matrix in https://en.wikipedia.org/wiki/Bloch_sphere - aReal = ( 0.5 + 0.5 * z ) ** 0.5 - a = new Q.ComplexNumber( aReal, 0 ) + const + aReal = ( 0.5 + 0.5 * z ) ** 0.5, + a = new Q.ComplexNumber( aReal, 0 ), b = new Q.ComplexNumber( x / 2 / aReal, y / 2 / aReal ) return new Q.Qubit( a, b )