@@ -45,7 +45,9 @@ def total_variation_distance(
4545 return 0.5 * sum (abs (dist_a .get (key , 0.0 ) - dist_b .get (key , 0.0 )) for key in keys )
4646
4747
48- def hellinger_distance (counts_a : Mapping [str , int ], counts_b : Mapping [str , int ]) -> float :
48+ def hellinger_distance (
49+ counts_a : Mapping [str , int ], counts_b : Mapping [str , int ]
50+ ) -> float :
4951 """Compute Hellinger distance between two count distributions."""
5052 dist_a , dist_b , keys = _union_probabilities (counts_a , counts_b )
5153 squared = sum (
@@ -60,7 +62,9 @@ def jensen_shannon_divergence(
6062) -> float :
6163 """Compute Jensen-Shannon divergence in bits between two distributions."""
6264 dist_a , dist_b , keys = _union_probabilities (counts_a , counts_b )
63- midpoint = {key : 0.5 * (dist_a .get (key , 0.0 ) + dist_b .get (key , 0.0 )) for key in keys }
65+ midpoint = {
66+ key : 0.5 * (dist_a .get (key , 0.0 ) + dist_b .get (key , 0.0 )) for key in keys
67+ }
6468
6569 def _kl_divergence (left : dict [str , float ], right : dict [str , float ]) -> float :
6670 divergence = 0.0
@@ -71,7 +75,9 @@ def _kl_divergence(left: dict[str, float], right: dict[str, float]) -> float:
7175 divergence += left_value * math .log2 (left_value / right_value )
7276 return divergence
7377
74- return 0.5 * _kl_divergence (dist_a , midpoint ) + 0.5 * _kl_divergence (dist_b , midpoint )
78+ return 0.5 * _kl_divergence (dist_a , midpoint ) + 0.5 * _kl_divergence (
79+ dist_b , midpoint
80+ )
7581
7682
7783def expectation_value_z (counts : Mapping [str , int ], qubit_index : int = 0 ) -> float :
@@ -126,7 +132,9 @@ def energy_error(simulated_energy: float, hardware_energy: float) -> float:
126132 return abs (simulated_energy - hardware_energy )
127133
128134
129- def hardware_match_score (counts_a : Mapping [str , int ], counts_b : Mapping [str , int ]) -> float :
135+ def hardware_match_score (
136+ counts_a : Mapping [str , int ], counts_b : Mapping [str , int ]
137+ ) -> float :
130138 """Convert TVD into a simple customer-facing match score percentage."""
131139 score = (1.0 - total_variation_distance (counts_a , counts_b )) * 100.0
132140 return max (0.0 , min (100.0 , score ))
@@ -141,4 +149,4 @@ def compute_counts_metrics(
141149 "hellinger" : hellinger_distance (counts_a , counts_b ),
142150 "js_divergence" : jensen_shannon_divergence (counts_a , counts_b ),
143151 "match_score" : hardware_match_score (counts_a , counts_b ),
144- }
152+ }
0 commit comments