@@ -549,6 +549,8 @@ def scatter_plot_normalized_kak_interaction_coefficients(
549
549
* ,
550
550
include_frame : bool = True ,
551
551
ax : Optional [plt .Axes ] = None ,
552
+ rtol : float = 1e-5 ,
553
+ atol : float = 1e-6 ,
552
554
** kwargs ,
553
555
):
554
556
r"""Plots the interaction coefficients of many two-qubit operations.
@@ -590,6 +592,13 @@ def scatter_plot_normalized_kak_interaction_coefficients(
590
592
wireframe. Defaults to `True`.
591
593
ax: A matplotlib 3d axes object to plot into. If not specified, a new
592
594
figure is created, plotted, and shown.
595
+ rtol: Per-matrix-entry relative tolerance on equality used if the
596
+ kak decomposition is calculated from the `interactions`.
597
+ atol: Per-matrix-entry absolute tolerance on equality used if the
598
+ kak decomposition is calculated from the `interaction`s. T
599
+ This determines how close $k_x$ must be to π/4 to guarantee
600
+ $k_z$ ≥ 0. Must be non-negative.
601
+
593
602
**kwargs: Arguments forwarded into the call to `scatter` that plots the
594
603
points. Working arguments include color `c='blue'`, scale `s=2`,
595
604
labelling `label="theta=pi/4"`, etc. For reference see the
@@ -662,7 +671,7 @@ def coord_transform(
662
671
else :
663
672
interactions_extracted = [interactions ]
664
673
665
- points = kak_vector (interactions_extracted ) * 4 / np .pi
674
+ points = kak_vector (interactions_extracted , rtol = rtol , atol = atol ) * 4 / np .pi
666
675
667
676
ax .scatter (* coord_transform (points ), ** kwargs )
668
677
ax .set_xlim (0 , + 1 )
@@ -810,7 +819,7 @@ def kak_decomposition(
810
819
],
811
820
* ,
812
821
rtol : float = 1e-5 ,
813
- atol : float = 1e-8 ,
822
+ atol : float = 1e-6 ,
814
823
check_preconditions : bool = True ,
815
824
) -> KakDecomposition :
816
825
"""Decomposes a 2-qubit unitary into 1-qubit ops and XX/YY/ZZ interactions.
@@ -848,9 +857,7 @@ def kak_decomposition(
848
857
if check_preconditions and (
849
858
mat .shape != (4 , 4 ) or not predicates .is_unitary (mat , rtol = rtol , atol = atol )
850
859
):
851
- raise ValueError (
852
- 'Input must correspond to a 4x4 unitary matrix. Received matrix:\n ' + str (mat )
853
- )
860
+ raise ValueError (f'Input must correspond to a 4x4 unitary matrix. Received matrix:\n { mat } ' )
854
861
855
862
# Diagonalize in magic basis.
856
863
left , d , right = diagonalize .bidiagonalize_unitary_with_special_orthogonals (
@@ -948,7 +955,7 @@ def kak_vector(
948
955
949
956
if check_preconditions :
950
957
actual = np .einsum ('...ba,...bc' , unitary .conj (), unitary ) - np .eye (4 )
951
- if not np .allclose (actual , np .zeros_like (actual ), rtol , atol ):
958
+ if not np .allclose (np .zeros_like (actual ), actual , rtol = rtol , atol = atol ):
952
959
raise ValueError (
953
960
'Input must correspond to a 4x4 unitary matrix or tensor of '
954
961
f'unitary matrices. Received input:\n { unitary } '
0 commit comments